I have developed a trading algo for intraday trading which runs on hourly data. It uses the high and low of the current day till the current candle to generate buy/sell signals. While trading in live market this works as intended.
But when I backtest this algo on hourly data instead of taking today's high/low till current candle (current hour) it takes high/low of the whole day which in turn pollutes the result of the backtest, since this uses the future data which will not be available while I am trading live.
Let's say that the market function between 9am to 3pm and I am trading on hourly chart at 1pm, so at 1 pm my algo will use the day's high/low till 1pm to generate buy/sell signal.
Whereas in backtest since I have the whole day's data for any day the same algo at 1pm will use the whole day's high/low which might be made after 1pm.
So is there a way in which I can limit my data till the current hourly candle while backtesting??
In addition to @portfoliobuilder's comments, you should confirm that you have set your Periodicity to 1 hour in the Analysis Settings window. It sounds to me like perhaps you have 1-hour data in your database, but you're back testing using daily bars. That won't allow you to achieve what you want.
Thanks for you replies. Below is a part of the code that I am using.
dmin1C=TimeFrameGetPrice( "C", inDaily, shift = -1, mode = expandFirst ); // to get yesterday's close
dmin1L=TimeFrameGetPrice( "L", inDaily, shift = -1, mode = expandFirst ); // to get yesterday's low
dmin1H=TimeFrameGetPrice( "H", inDaily, shift = -1, mode = expandFirst ); // // to get yesterday's high
dH=TimeFrameGetPrice( "H", inDaily, shift = 0, mode = expandFirst ); // to get today's high till the present candle
dop=TimeFrameGetPrice( "O", inDaily, shift = 0, mode = expandFirst ); // to get today's open till the present candle
dC=TimeFrameGetPrice( "C", inDaily, shift = 0, mode = expandFirst ); // to get today's close till the present candle
Buy= (dmin1L< dop) and (dH>dmin1H);
//The above line is used to get the price at the time when the Buy condition is true. It works for live market but I face the same issue while backtesting
While back testing in the settings window I have set the Periodicity to Hourly. I am using the above code to access the daily high and low for past days and present days.
expandLast - the compressed value is expanded starting from last bar within given period (so for example weekly close/high/low is available on Friday's bar) expandFirst - the compressed value is expanded starting from first bar within given period (so for example weekly open is available from Monday's bar) expandPoint - the resulting array gets not empty values only for the last bar within given period (all remaining bars are Null (empty)).
Caveat: expandFirst used on price different than open may look into the future. For example if you create weekly HIGH series, expanding it to daily interval using expandFirst will enable you to know on MONDAY what was the high for entire week.