I am trying to generate buy and sell signals based on different timeframes. What I want to do is check if a condition A is true in hourly timeframe, if yes then check whether condition B is true in 5 min timeframe. If this is also true, then generate buy signal.
Let's say the current time is 11:10 AM and the latest hourly candle satisfied the condition A, now I want to check the 5 min data of that stock and see whether or not condition B at that point in time is also true or not. If true then that's a buy signal.
To switch time frames,
TimeFrameSet is used. But how to use it in my case? As I want to first check on hourly and then move on to 5 minute but the docs say you can only move on from smaller timeframe to bigger timeframe and not the other way round.
Please note that you can only compress data from shorter interval to longer interval. So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, ....N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames.
So what I did was set the periodicity setting to 5 minute and in code, set the timeframe to hourly data and check for condition A.
For example if the conditionA is moving average of x bars greater than moving average of y bars.
TimeFrameSet( inHourly ); conditionA = MA(C, 8) > MA(C, 13); TimeFrameRestore();
Now only if conditionA is true, I want to check for conditionB in 5 min timeframe. As the base periodicity setting is set to 5 minutes, after
TimeFrameRestore, I should be back to 5 minutes timeframe automatically.
This is where I am having doubts whether this will work or not. At 11:15 AM, the time compressed hourly data will be different for the one generated at the time of 11:10 AM but I only want to check the data for the last formed hourly bar, i.e the one generated at 11:00 AM as the next one will only be generated at 12:00 PM. Since the past few days, I am trying to think how to code it but unable to find a way. Any help would be greatly appreciated.