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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (vicknick, 7th_zorro), 888 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 2 of 4 1 2 3 4
Re: Reversing positions without market orders? [Re: MegaTanker] #486127
06/09/22 16:52
06/09/22 16:52
Joined: Feb 2017
Posts: 1,726
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,726
Chicago
Originally Posted by MegaTanker
Also, using cancelTrade to remove the old position will completely drop this trade from Zorro's trade history, no? So most of Zorro's metrics will report nothing useful for monitoring the strategy.
Yes, but you can use enterTrade() to report what happened, one enterTrade call for each time the position was positive or negative.

Re: Reversing positions without market orders? [Re: MegaTanker] #486128
06/09/22 18:56
06/09/22 18:56
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
That's a good point. I think I got it sort of working now with enterTrade(). Also had to set the exit price of outgoing orders and more importantly toggle the TR_OPEN flag off, otherwise the trade was added as an open trade again upon enterTrade. With the flag off, Zorro didn't print an "Enter Long..." message but the trade shows up in the report at the end. It's pretty hacky but it works

Re: Reversing positions without market orders? [Re: MegaTanker] #486133
06/10/22 14:15
06/10/22 14:15
Joined: Feb 2017
Posts: 1,726
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,726
Chicago
Originally Posted by MegaTanker
It's pretty hacky but it works
grin

Re: Reversing positions without market orders? [Re: MegaTanker] #486136
06/10/22 19:38
06/10/22 19:38
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
Unfortunately this seems to throw off Zorro's performance measures still. The attached picture correctly shows the trades as they really happened but the equity curve is clearly bogus. I've verified that every TRADE's commission/spread etc is set to zero with the trade loops. The final report also shows zero trade costs.

The final report correctly shows the number of trades but it shows 0% winning trades when almost all of them are in fact winning. I set the fResult field appropriately to reflect the result of each trade. I can't check if the Gross win/loss are correct because my trading volume is so low, Zorro doesn't show the necessary precision.

Could mean that Zorro keeps a tally for these measures and assigns them before I can get a handle on the TRADE struct to modify it, and doesn't recalculate them by looping the trades for the report... Not sure how to fix this. Is the PERFORMANCE struct accessible per script?

Attached Files Untitled.png
Last edited by MegaTanker; 06/10/22 19:39.
Re: Reversing positions without market orders? [Re: MegaTanker] #486137
06/10/22 20:21
06/10/22 20:21
Joined: Feb 2017
Posts: 1,726
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,726
Chicago
I really don't know what you did. enterTrade is a beast to tame since you have to manipulate TRADE structs.

Check out the Simulate script, which gives a great example on how to use enterTrade for this kind of purpose.

Re: Reversing positions without market orders? [Re: MegaTanker] #486140
06/11/22 06:51
06/11/22 06:51
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
This is the code that reverses a position:

Code

Lots = 2; //1 lot to close previous, 1 to open new in opposite direction
OrderLimit = Close[0] - Spread/2; //order between bid/ask
Spread = 0;  //spread to zero because limit orders
TRADE* t = enterLong();
if(t){
	t->nLotsTarget = 1;
	t->nLots = 1;       //semantically, trade is only 1 lot
	t->fSpread = 0; 
	t->fSlippage = 0;
	TRADE tmp;
	memcpy(&tmp, lasttrade, sizeof(tmp));    //lasttrade is pointer to previous trade that gets cancelled and re-entered
	cancelTrade(lasttrade);
	tmp.fExitPrice = t->fEntryPrice;
	tmp.fResult = tmp.nLots * (tmp.fEntryPrice-tmp.fExitPrice);        //lasttrade was a short trade
	tmp.fSpread = 0;   
	tmp.fSlippage = 0;
	tmp.flags ^= TR_OPEN; //toggle closed
	tmp.flags ^= TR_SIMULATED; //Zorro doesn't set this automatically upon enterTrade(), not sure what it does exactly
	tmp.nBarClose = Bar;
	tmp.tExitDate = t->tEntryDate;
	enterTrade(&tmp);
	lasttrade = t;
}



Commission is also set to zero earlier. I don't think it's that I forgot something, I suspect Zorro adjusts the internal performance metrics at the enterLong() call before I can change any properties of the trade.

Last edited by MegaTanker; 06/11/22 06:53.
Re: Reversing positions without market orders? [Re: MegaTanker] #486154
06/13/22 22:05
06/13/22 22:05
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
Any chance I could get a dev's insight?

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

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Hmm, I admit that even I am lost about the purpose and working of that code. I can only say that it looks very dangerous.

The normal way to reverse a short position with 2 orders:

exitShort();
enterLong();

The unconventional way with 1 order, open position is ThisTrade:

enterLong(Lots+TradeLots);
cancelTrade(ThisTrade);

Re: Reversing positions without market orders? [Re: MegaTanker] #486157
06/14/22 09:45
06/14/22 09:45
Joined: Aug 2021
Posts: 101
M
MegaTanker Offline OP
Member
MegaTanker  Offline OP
Member
M

Joined: Aug 2021
Posts: 101
Yes, but problem with that is that the cancelled trade completely disappears from Zorro's grasp, thus it is lost from any performance report. The above code is messy because I tried to re-enter the cancelled trades in order to leave the performance measures intact.

Can you tell me how Zorro internally handles its performance variables? Does it iterate over all trades to calculate the performance report from scratch or does it keep a variable for the overall profit for example that is added up whenever a trade closes and then printed to the performance report?


Last edited by MegaTanker; 06/14/22 09:45.
Re: Reversing positions without market orders? [Re: MegaTanker] #486158
06/14/22 11:40
06/14/22 11:40
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Yes, it iterates over all open trades and calculates the open profit from scratch. The closed profit only changes when a trade is closed.

What exactly is the problem with the normal exit/enter method? It does normally not matter for transaction cost if you use 1 or 2 orders. You can exit at limit and then enter at the same or another limit.

Page 2 of 4 1 2 3 4

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1