BackTesting of PDI-MDI strategy - Error

I am trying to backtest a simple buy-and-sell strategy. Whenever I run a backtest on the following strategy(given below), the system does not generate any output.

StartTime = ParamTime("Start Time", "09:20");
EndTime = ParamTime("End Time", "15:00");
sqOffTime = ParamTime("Square Off Time", "15:10");

Pd = Optimize("Period", 4, 1, 20, 1);


Buy=  PDI(Pd) - MDI(Pd) >= 20      AND TimeNum() > StartTime AND TimeNum() < EndTime; 
Sell= PDI(Pd) - MDI(Pd) < 10           OR TimeNum() >= sqOffTime;                                                                                                   
Short=  MDI(Pd) - PDI(Pd) >= 20    AND TimeNum() > StartTime AND TimeNum() < EndTime; 
Cover=MDI(Pd) - PDI(Pd) <10          OR TimeNum() >= sqOffTime;																		                                




Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

However, when I simply comment out the line after 'AND' in BUY or SHORT statements as given below, the backtest runs perfectly.

StartTime = ParamTime("Start Time", "09:20");
EndTime = ParamTime("End Time", "15:00");
sqOffTime = ParamTime("Square Off Time", "15:10");

Pd = Optimize("Period", 4, 1, 20, 1);


Buy=  PDI(Pd) - MDI(Pd) >= 20;      //AND TimeNum() > StartTime AND TimeNum() < EndTime;     //AND ADX(Pd) >= 35
Sell= PDI(Pd) - MDI(Pd) < 10           OR TimeNum() >= sqOffTime;                                                                                                   
Short=  MDI(Pd) - PDI(Pd) >= 20    AND TimeNum() > StartTime AND TimeNum() < EndTime;       //AND ADX(Pd) >= 35
Cover=MDI(Pd) - PDI(Pd) <10          OR TimeNum() >= sqOffTime;																		                                




Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

I am unable to understand why the backtester does not accept the 'start time' and 'End Time' together with the Buy or Sell Signal.

Appreciate any help in figuring out the logic behind the backtest not producing any result with the above-mentioned conditions.

It's quite simple... your set time range does not exist.
Best bet is... you have run the code on EOD data where there is no intraday time.

Use debugger then you'll see the light at end of the tunnel.

Also remove Exrem in Backtester.
Backtester removes excessive signals in default mode already.

3 Likes

Thank you so much for pointing me in the right direction.

You are right about the 'time range does not exist' statement.

I have changed the periodicity to 1 minute and the backtest produces the result like a charm.