I have just started reading Bandy´s Quantitative Trading Systems.
On page 104 there is code for exiting a trade after predefined number of bars.
SetTradeDelays(0,0,0,0);
BuyPrice = C;
SellPrice = C;
// Trading system entry logic goes here, for example MA Crossover
MAperiod1 = Optimize("MAperiod1",30,1,50,1);
MAperiod2 = Optimize("MAperiod1",16,1,50,1);
MA1 = MA(C,MAperiod1);
MA2 = MA(C,MAperiod2);
Buy = Cross(MA1,MA2);
HoldDays = Param("HoldDays",5,1,60,1);
Sell = BarsSince(Buy) >= HoldDays;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
This works fine, but when I enter a different entry criteria the system exits at everything between 5 and 21 bars.
SetTradeDelays(0,0,0,0);
BuyPrice = C;
SellPrice = C;
Range = High - Low;
// Trading system entry logic goes here
Buy = C <= Low + 0.1*Range;
HoldDays = Param("HoldDays",5,1,60,1);
Sell = BarsSince(Buy)>= HoldDays;
// Remove extra buy-sell-signals
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
Where have I gone wrong?