I'm trying to trade simple strategy [Its just for sample coding purpose, don't trade - it will fail ], I want to do Intraday trades only that too with time restiction from 9:30am to 15;00pm. All positions should be closed @ 3:15pm and the same should be reflected in backtest report also. I have tried the code here : https://www.amibroker.com/kb/2014/11/28/how-to-restrict-trading-to-certain-hours-of-the-day/ but its not working as expected.
_SECTION_BEGIN("Tradetime"); tn = TimeNum(); startTime = 93000; // start in HHMMSS format endTime = 151500; // end in HHMMSS format timeOK = tn >= startTime AND tn <= endTime; /* To restrict trade time and End the trade @ particular time */ Buy = ( Cross( MACD(), Signal() ) AND timeOK ) OR Cross( tn, endTime ); Sell = (Cross( Signal(), MACD() ) AND timeOK) OR Cross( tn, endTime ); Short=Sell OR Cross(tn,endTime); Cover=Buy OR Cross (tn,endTime); Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); _SECTION_END();
Can someone help with a sample code ? when you run backtest report will be generated but if you check on some Long trades trades ,it will be triggered @ 15:19:00 and exits next day 9:19:00AM which shows that Time restriction isn't effective. Any help is much appreciated.Thanks in Advance :)