I am coding a simple strategy that does the following:
1. Sets and adjusts a stoploss in the OnBarUpdate() section:
SetStopLoss(CalculationMode.Percent, 1)
2. Evaluates a certain condition in the OnBarUpdate() section and enters short if met:
EnterShort(1000,"GoingDown");
3. Evaluates another condition in the OnBarUpdate() section and exits the short if met:
ExitShort("GoingDown close", "GoingDown");
The conditions are such that they cannot be met simultaneously within the same bar. The idea is that in CurrentBar=n I could enter the short position and in CurrentBar>n I check if I should exit.
The strategy sets CalculateOnBarClose=true;
It all works fine when I backtest this with a single instrument. The sequence of events seems to be for each new bar: OnBarUpdate -> OnOrderUpdate -> OnExecution
However, when I adapt the strategy to multiple instruments then the sequence of events for the non-primary series seem different: OnOrderUpdate->OnExecution->OnBarUpdate
As a consequence the strategy executes the stoploss order before I can evaluate my second condition that would otherwise close the position at a different exit price.
Is there a hardcoded sequence of events for each instrument when backtesting multi-instrument strategies? What would that sequence be?
If not, how can I force the evaluation of my exit-condition before the stoploss is filled? Note this is not a problem with my single-instrument strategy because events seem to always follow the same sequence.
thanks
Comment