Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 911 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 4 1 2 3 4
Re: Reversing positions without market orders? [Re: jcl] #486159
06/14/22 15:07
06/14/22 15:07
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
The problem is I am trying to act as a market maker only to benefit from zero commission. The strategy is built on that. I'm sending post-only orders through the broker plugin to the exchange that either get rejected because they would act as taker orders or the plugin waits for the order to get filled. It will repost rejected orders or wait until a maximum timeout has passed and then return 0 if the order wasn't filled in time.

So the plugin has to "work" to get fills, which can take some time. E.g. on 1 min bars, I can't wait longer than that for an order to get filled. If I send two separate orders the process must happen twice within the bar duration, increasing the chance that orders are missed, or at least making the order process more complicated.


Originally Posted by jcl
Yes, it iterates over all open trades and calculates the open profit from scratch. The closed profit only changes when a trade is closed.


Thank you, that is good to know. But the same probably does not apply to the array of balances Zorro uses to draw the equity curve. Can you tell me how this is handled? Based on my experience it looks like this value is adjusted with spread/commission/slippage immediately upon the enterLong() call, before I can modify any values of the trade struct.

Re: Reversing positions without market orders? [Re: MegaTanker] #486168
06/15/22 09:46
06/15/22 09:46
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Yes, the equity curve is adjusted at opening trades and at any tick. It is the sum of open and closed profit.

If needed, you can adjust the equity by adding or subtracting from Balance.

Re: Reversing positions without market orders? [Re: MegaTanker] #486170
06/15/22 12:27
06/15/22 12:27
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
Thank you, I will try again soon, maybe I'll have more luck this time

Re: Reversing positions without market orders? [Re: jcl] #486171
06/15/22 12:42
06/15/22 12:42
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Originally Posted by jcl
If needed, you can adjust the equity by adding or subtracting from Balance.
But if the broker plugin outputs balance and equity, this would be unnecessary I believe.

Re: Reversing positions without market orders? [Re: MegaTanker] #486172
06/15/22 13:57
06/15/22 13:57
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
That might be true. I don't know if Zorro uses that return value from the plugin to generate the equtiy curve in the chart or if it uses something internal like ProfitTotal or similar.

Last edited by MegaTanker; 06/15/22 14:01.
Re: Reversing positions without market orders? [Re: MegaTanker] #486173
06/15/22 14:08
06/15/22 14:08
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
That depends on which plugin and which SET_PATCH configuration you use.

Re: Reversing positions without market orders? [Re: MegaTanker] #486174
06/15/22 21:46
06/15/22 21:46
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
The plugin does return the Account balance and if Zorro indeed uses the change of that value to draw the equity curve then that could explain why mine looked bogus. There were some other positions open in the account that were much larger in size than the 1 Lot test trades I did

Re: Reversing positions without market orders? [Re: MegaTanker] #486175
06/16/22 07:03
06/16/22 07:03
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
Returned live parameters from the broker plugin, for account, trades, assets, override anything. Unless you disable them with SET_PATCH.

Re: Reversing positions without market orders? [Re: MegaTanker] #486179
06/16/22 14:52
06/16/22 14:52
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Originally Posted by MegaTanker
The plugin does return the Account balance and if Zorro indeed uses the change of that value to draw the equity curve then that could explain why mine looked bogus. There were some other positions open in the account that were much larger in size than the 1 Lot test trades I did
Hmm...
https://github.com/vitakot/ftx_zorro_plugin/blob/main/src/ftx.cpp#L231
Code
DLLFUNC_C int BrokerAccount(char *Account, double *pdBalance, double *pdTradeVal, double *pdMarginVal) {
	//...
	if (pdBalance) {
		*pdBalance = std::round(account.m_totalAccountValue);
	}
	return 1;
	//...
}
If account.m_totalAccountValue is actually the account equity, then the plugin was written incorrectly.

Emphasis added:
Quote
pTradeVal: Optional output, current value of all open trades; the difference between account equity and returned balance value. If not available, Zorro estimates the equity from balance and value of all open trades. If no balance was returned, the account equity can be returned in pTradeVal.
https://zorro-project.com/manual/en/brokerplugin.htm

Re: Reversing positions without market orders? [Re: MegaTanker] #486180
06/16/22 20:02
06/16/22 20:02
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
Yes, I think you are right, but it doesn't matter for my case because I still don't think Zorro really uses those values beyond printing it to the Zorro window and making it available in the Balance variable.

I found the variables that I was mostly looking for:
g->w.vWin and g->w.vLoss keep a tally of closed profits/losses and the difference between them is drawn as the equity in the chart and to the Zorro status section during the session. I have to modify those based on the result of the trade I'm cancelling/entering
g->w.numWin and g->w.numLoss are the number of won/lost trades, also a running tally. For some reason all trades are added to the losers upon cancelTrade, so I had to correct that manually.

Those are at least the important metrics but there are many more to take care off.

I think this is something Zorro should support natively. Is this really such a crazy use case? I don't see why trades should be split up into multiples if it's not necessary. Especially because many brokers (like IB) charge minimum order fees or flat fees, thereby increasing the overall commission if the order is split up. It's probably not too hard to implement in Zorro as an alternative order type that is activated by some flag. The normal trade logic can be left untouched, just adding it as an alternative.

Last edited by MegaTanker; 06/16/22 20:03.
Page 3 of 4 1 2 3 4

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1