TimeFrameSet and TimeFrameExpand

I am using 3 time frames in my formula - 15 min, hourly and daily and then combining the results generated by each to form a buy or sell signal.

For hourly data, this is the code I am using:

TimeFrameSet( inHourly );

//Hourly code

HourlyBuyCondition = HourlyBuyCondition1 OR HourlyBuyCondition2 OR HourlyBuyCondition3;
HourlySellCondition = HourlySellCondition1 OR HourlySellCondition2 OR HourlySellCondition3;


HourlyBuyCondition = TimeFrameExpand(HourlyBuyCondition, inHourly);
HourlySellCondition = TimeFrameExpand(HourlySellCondition, inHourly);

As you can see I am using 3 variables HourlyBuyCondition1, HourlyBuyCondition2, HourlyBuyCondition3 and combining them using OR and doing the same for 15 min and daily time frames.

So in the end, I am combining all 3 time frames to get buy or sell signal:

Buy = DailyBuyCondition AND HourlyBuyCondition AND fifteenMinBuyCondition;
Sell = DailySellCondition AND HourlySellCondition AND fifteenMinSellCondition;

This is not generating signals as per my expectation and that's probably due to my lack of understanding about timeframe functions. I read that timeframe functions are not a replacement for periodicity settings and TimeFrameExpand should be used which I'm using but still not getting desired results.

Can someone please shed some light on it?

I would suggest adding an Exploration to your AFL so that you can see the values for each of your intermediate values like DailyBuyCondition, HourlyBuyCondition and fifteenMinBuyCondition. If you still don't understand what's going wrong, then drill down to the next level: HourlyBuyCondition1, HourlyBuyCondition2, HourlyBuyCondition3, etc.


After adding exploration, it is returning 1 if the condition is true and 0 of the condition doesn't match. I tried it on all - DailyBuyCondition, HourlyBuyCondition3 etc..

I believe the results I'm getting are due to timeframe set in periodicity settings. For example, I am using 15 minute, hourly and daily timeframe in AFL and I've set the periodicity time frame as 15 min. Now if I change the periodicity, for example, from 15 min to daily or hourly, the results are returned using that setting. So regardless of what the AFL timeframe says, the results are getting affected by periodicity settings, I believe this is where I am getting it all wrong.

Your only solution is to use advice given here: How do I debug my formula?

1 Like

@sarupria, you also need to read this page again and pay particular attention to the orange boxes: https://www.amibroker.com/guide/h_timeframe.html. The TimeFrame* functions are not a replacement for the Periodicity setting. Also, you cannot expand to a shorter timeframe than your Periodicity setting.

Yes, I've read that orange box. That actually triggered this question as I want to know what is the alternative or solution. First I will follow the steps given by @Tomasz to see what values my code is producing and to correct it if necessary.

But can you tell me what I should do after the code is producing correct values, how to display the final combined value as the orange box says TimeFrame* functions are not a replacement for Periodicity setting.

Ex - A is true, B is true, C is true. If all 3 are true at the same time, how to get that signal without it getting affected by Periodicity setting. If I use Scan or Explore, results will get affected by time frame I set in periodicity setting.

Your question is too vague for me to understand what you're attempting to do. Please post your revised code and let us know what's not working, which will allow us to offer appropriate suggestions.