I ran following code with setting as show in attachment and was surprised to find that instead of 1 trade per bar more were observed on regular intervals. Strange this problem was not observed under Async mode.
Thanks to Martin Miller, who showed me a trick to control trades through a code rather then using the standard limit setting which places artficial constraints on code.
Code: Select all
[intrabarordergeneration=true]
Input: Length(5),VarA(2),VarB(2),EndOfDayExit(true);
Var: LowBar(0),HighBar(0),BuyPrice(0),ShortPrice(0);
Var: MP(0), IntrabarPersist MP_prev(0),
CC(0), IntrabarPersist CC_prev(0),
IntrabarPersist TradesThisBar(0),
IntrabarPersist FirstTickOfBar(False);
MP = MarketPosition;
CC = CurrentContracts;
If MP <> MP_prev or CC <> CC_prev then TradesThisBar = TradesThisBar + 1;
If FirstTickOfBar then TradesThisBar = 0;
LowBar= Lowest(Low,Length)[1];
HIghBar= Highest(High,Length)[1];
BuyPrice= LowBar + Range[1] * VarA;
ShortPrice=HighBar - Range[1] * VarB;
If TradesThisBar = 0 and MP<> 1 then buy next bar at BuyPrice stop;
If TradesThisBar = 0 and MP<>-1 then sellshort next bar at ShortPrice stop;
if EndOfDayExit then setexitonclose;
FirstTickOfBar = BarStatus(1) = 2;
MP_prev = MP;
CC_prev = CC;