How is loop executed

For (i=0;i<5;i++)
{
statement 1
statement 2
statement 3
}

if iteration i=1 is being executed on bar number 10 at time t will the same iteration be executed on bar number 11, 35, 100001 at time t?

Recommended reading:
https://www.amibroker.com/guide/h_understandafl.html

I have read that article. It is the cornerstone of afl processing. Thankyou.

But my question is not answered in that article.
Since entire afl code is executed for every bar simultaneously my question has relevance.

Lets say at clock time 14:00:00 hrs in bar number 10 the loop is being executed. Lets say iteration i=2 is being run. Because of the way things are at bar number 25 the same code is being simultaneously executed. My question is IS THERE A WAY TO KNOW AT BAR 25 WHICH ITERATION IS BEING EXECUTED? is it i=2 or i=0 or i=4 ?

tomas can you please give me back express posting privileges. Earlier I was able to post threads immediately now they go in moderation queue. My work is disrupted because of this.

Entire loop is executed always, from the beginning to end, all iterations.

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

Specifically use _TRACE then you will know how and when it executes.

As to moderation - it is AUTOMATIC, not manual, thing - Discourse has dozens of factors that decide on whenever post is marked as it needs moderation based on heuristic that is built into Discourse. Nothing to enable or disable manually.

Yes.

But lets assume at time = t
At bar number 1 we are at iteration i=0 of the loop. That means that the statements are being exected with value of i=0.

Now my question is at bar number 25 which iteration (i=?) is being executed?

That is why I pointed out you to the ARTICLE from tutorial. You have to read slowly and carefully and understand it. The question you ask clearly shows that article did not sink in yet. It explains that ALL bars are processed at once (array processing).
Entire formula is executed from beginning and as many times as you loop says. So it will be executed 5 times with i = 0, 1, 2, 3, 4 as your for loop tells it to do. AFL is NOT processed one bar at a time. It is processes ALL BARS at once. It is VECTOR processing. If you write X = (H+L)/2; then X is an ARRAY representing ALL BARS, not one. There i s no "bar number 1" to be done individually. ALL bars are done at once.

Again USE _TRACE as advised, you will see it in action.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.