Your function name is func1 and your AFL file is named func1.afl too.
So which func1 do you actually mean??
Another case of imprecise question.
If you mean func1() (the function) in func1.afl, then in "func1.afl" file the function func1() does not calculate/return anything if it is not called there but then it is just defined as function in that file.
If that function func1() is called in that file ("func1.afl") e.g.
f1 = func1();
then it calculates on selected interval's data (if f1 is not called within timeframe functions there).
If you mean the call of func1() (the function) in func2.afl of your upper example then calculations are switched to different interval derived from selected interval's data (switched if inXminute > selected interval). If inXminute <= selected interval then calculations remain in selected interval (e.g. your 1-minute interval being selected chart or analysis interval).
If func1() contains iterations through array then read here for example
Now, if you mean func1.afl (the file) when you say "the program in func1" then again, if that program in file func1.afl is not executed within timeframe functions then it is executed on selected interval's data. If that program of func1.afl is executed within timeframe functions in func1.afl then calculations are switched to different interval derived from selected interval (switched if inXminute > selected interval).
As for documentation on multi timeframe support read here.
Evaluate the flow of control yourself, It is not about TimeFrame in respective AFL files but what is the timeframe when a function is called.
Calling a Function does not execute the entire AFL, however, an include command will when its called.
That is why headers files are always declared at the start, not at the end. Is this logical to you ?
If you have TimeFrame calls within the called ( or Callee ) function, then it will change it accordingly otherwise the called function will execute in the scope of the caller function (Logically answered to best of my knowledge).
What don't you write a complete proper code of AFL 1 and 2, demonstrate the control flow instead ?
-> Calling a Function does not execute the entire AFL, however, an include command will when its called.
-> That is why headers files are always declared at the start, not at the end. Is this logical to you ?
This statement is a bit interesting to me.
My include afl file contains the associated initial value settings, plus the TimeFrame setting.
Then create a variable for the next afl file
Time-frame functions do not change the BarCount - they just squeeze the arrays so you have first N-bars filled with NULL values and then - last part of the array contains the actual time-compressed values.
This is why it is essential to expand the data back to the original frame with TimeFrameExpand.
The original setting in Chart TF or Periodicity will govern the AFL variable BarCount
Obviously, you cannot go to Lower TF than this, only higher an in proper multiples.
so with 5m TF, don't expect to extrapolate 12m TF.
Array values will be populated according to the respective TF in which that bit of code is run.
periodicity set to daily and you will see how "weekly close compressed" column contains empty values at the beginning and weekly compressed data at the end of array.
so you need to deal with these NULL values either using AFL functions or your own logic (if you're capable of handling it).
Nothing has been misunderstood. You don't understand what has been already explained in detail here in this thread.
You do not need to add function definition within Time Frame functions.
So:
_SECTION_BEGIN( "CrossOverNm" ) ;
// Function DEFINITION before
// (Alternativally move that custom function to include file)
function CrossOverNm()
{
LongAvg = MA(C, 20);
ShortAvg = MA(C, 3);
BuySell = IIf( ShortAvg > LongAvg , 1, -1 );
return BuySell;
}
in2Minute = 2 * in1Minute;
TimeFrameSet( in2Minute ); // switch to 2 minute frame
Co2m = CrossOverNm();
TimeFrameRestore();
Co2 = TimeFrameExpand( Co2m, in2Minute);
Plot( Co2, "Co2", colorRed );
_SECTION_END( ) ;
EDIT: Now I have seen that you have edited your upper post to this one all of the sudden:
And what is supposed to be wrong there? And where is loop you have problems with?
Excuse me but the OP clearly has not bothered reading the second post (carefully) at all! (I even doubt that he continued reading after first paragraph.)
In first post he asked:
Excuse me, the program in func1 uses what time frame to calculate data.
Then he got detailed response (having taken time to create) for almost every case of func1... Besides I have already suspected in 2nd post that looping code in his func1() function could the probable main issue and being the possible reason for asking "which time frame is used". That's why I have added example there dealing with looping code used within Time Frame functions.
And then in 3rd post he ask exactly the same question again:
Excuse me, the program in func1 uses what time frame to calculate data.
I consider that incredibly ignorant and big waste of time.
Fact remains your further posts are just repetition and that you post same links and quotes that have been posted already just tells me that you did not bother reading/acknowledging 2nd post yourself. Otherwise you would have mentioned that almost everything has been posted in this thread already including link(s) to manual and actual loop example.
If he would have read 2nd post carefully then where is his looping code within timeframe functions to ask further specific questions about?
Again, he has not bothered reading first response at all. Period.
Instead same questions and different functions and then one post or more posts even without any use of time frame functions in his code examples all of the sudden. A big imprecise mess.
As for your (rather hypocritical) last post (which encourages others to similarly not bother reading carefully too)... from now on I will use that one as a quote when you will complain yourself again in posts similar to these ones:
I wouldn't argue with you, that's not what I meant if perceived that way, ppl don't absorb what is posted by others.
This doesnt mean that the post was missing anything or incorrect.
This is why I wrote "You know all about it for a long time"
_SECTION_BEGIN( "CrossOverNm" ) ;
function CrossOverNm(inNmin, Lavg, Savg)
{
inMinute = inNmin * in1Minute;
TimeFrameSet( inMinute ); // switch to N minute frame
iti = TimeNum() / 100;
LongAvg = MA(C, Lavg);
ShortAvg = MA(C, Savg);
for ( i = 0; i < BarCount ; i++ ) {
if ((iti[i] < (846 + (Lavg * inNmin))) || (iti[i] > 1400)) {
BuySell[i] = 0 ; // I want the BuySell if the time befort bar count set to 0
} else {
if ( ShortAvg[i] > LongAvg[i] ) {
BuySell[i] = 1;
} else {
BuySell[i] = -1;
}
}
}
TimeFrameRestore();
Co = TimeFrameExpand(BuySell, inMinute);
return Co;
}
Co2m = CrossOverNm(2, 20, 3);
_SECTION_END( ) ;
This is not the final version I want. The program I want is that we need to reset all variables when we open the mark every day, but I can't think of how to write it. For example, when we open 0845 with 2min K,