3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Reversing positions without market orders?
[Re: MegaTanker]
#486127
06/09/22 16:52
06/09/22 16:52
|
Joined: Feb 2017
Posts: 1,731 Chicago
AndrewAMD
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,731
Chicago
|
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]
#486140
06/11/22 06:51
06/11/22 06:51
|
Joined: Aug 2021
Posts: 101
MegaTanker
OP
Member
|
OP
Member
Joined: Aug 2021
Posts: 101
|
This is the code that reverses a position:
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]
#486157
06/14/22 09:45
06/14/22 09:45
|
Joined: Aug 2021
Posts: 101
MegaTanker
OP
Member
|
OP
Member
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.
|
|
|
|