October 26, 2006
If we are backtesting the intraday strategy and we do not want to keep open positions overnight – then it’s necessary to force closing all the open positions before the session end. In order to code it in AFL – the easiest is to use TimeNum() function for that purpose.
The below example shows how to close all open positions after 15:50, just before the end of the trading session (when testing on intraday quotes).
Buy = ...your regular conditions....For example – in case of MACD crossover – the code will look like:
Sell = ....your regular conditions.... OR TimeNum() > 155000
Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() ) OR TimeNum() > 155000