How to properly use TimeframeExpand function

Hello all members and admin, I am new user and don’t have much knowledge of programming, this is very first post in this forum. With the help of available posts in the forum i have been able to write a simple afl code.

SetBarsRequired( sbrAll, 0 );

count = 0;

i = 0;

for( i =1; i <=50; i++ ) 

{ 

TimeFrameSet(i*indaily);

b1 = C>ref(c,-1);

s1 = C<ref(c,-1);

 TimeFrameRestore();
 
 b1 = TimeFrameExpand(b1, i*inDaily);
 s1 = TimeFrameExpand(s1, i*inDaily);
 
 Filter= 1;

AddColumn((i), "t.frame" , 1.1,colorDefault, IIf((s1), colorred, IIf((b1), colorGreen, coloryellow )));



count++;

}

I am bit confused about TimeframeExpand() function, whether it is properly implemented or not. please help by guiding me about the proper use of TimeframeExpand function in AddTocolumn() function.
THANKS & REGARDS

@vijaykumar if you could explain what you are trying to achieve as well as how your current output differs from what you wanted, that would help the group understand how to help you.

Thanks @mradtke for reply .In fact I am trying to build an exploration which can give me exact defined condition for defined time frame by its color. I am getting wrong out put of the Afl. That’s why i am looking for my mistake.
THANKS & REGARDS.

@mradtke On the other hand if i use the following code it gives the correct results i.e it gives green color for [c>ref(c,-1)] and red color for [c<ref(c,-1)] as defined in afl, in exploration result. whereas i didn’t use TimeFrameExpand() function in this afl code. i took all the precautions given here in the following link
http://www.amibroker.com/kb/2015/01/28/why-analysis-results-and-chart-output-may-differ/
using Local Database with Eod Data

count = 0;

i = 0;

for( i =1; i <=50; i++ ) 

{ 

TimeFrameSet(i*indaily);

b1 = C>ref(c,-1);

s1 = C<ref(c,-1);

 TimeFrameRestore();
 
 
 Filter= 1;

AddColumn((i), "t.frame" , 1.1,colorDefault, IIf((s1), colorred, IIf((b1), colorGreen, coloryellow )));



count++;

}

THANKS & REGARDS

Actually I doubt very much that the second example gives “correct” results. However, it will be very difficult to tell because your only output is the value of i (the number of days in your compressed data bars) and a color.

My first suggestion is to read this if you have not already: https://www.amibroker.com/guide/h_timeframe.html. That should help you understand how time frame manipulation works in AB.

Second, enhance your Exploration so that it outputs the “current” close (i.e. close of the current i-Day compressed bar), “previous” close (i.e. close of the previous i-Day compressed bar), b1, and s1. Validate those closing values against a chart, and make sure you’re paying attention to the dates in the exploration as well.

Incidentally, if you did something like this:

AddColumn(b1, "t.frame "+i, ...);

Then the time frame index would be in the header, making all your headers unique and also easy to identify.

@mradtke thanks once again for reply. Well, i followed your suggestions and add “current close” and “previous close” for i-day compressed bars in Exploration, and the results were according your doubts, I mean exploration output did not match with the chart output. So what next? How to make it working right? please guide me.
One more thing i want to know, whether the first example i posted before is properly written or not ?
THANKS & REGARDS.

Two things will make it much easier for members of this forum to help you:

  1. Take the time to explain in English (not code) what you are trying to accomplish. For example “Generate a Buy signal whenever today’s close is greater than the close N days ago.”

  2. Post your code, and your specific observations about how the output of that code differs from your desired output.

1 Like

From now on, key sentences are in orange boxes to get the message across: http://www.amibroker.com/guide/h_timeframe.html

4 Likes