Why Does This Code Work? - page 2

 
koranged:


So if I am following correctly, this means that 'Experts' is local to just the one program rather than all programs as a Global Variable of the Client Terminal would be, whereas 'Quantity' is a Global Variable of the Client Terminal, and its value can therefore be updated by other programs, i.e. when the EA is attached to the second window, the value of 'Quantity' (and therefore 'New_Experts') will be 2, but as 'Experts' is a variable local to just this program, it is not aware that the EA has been attached to the second window and therefore its value remains as 1, until the 'if' statement changes that?

Is this correct or at least along the right lines?

Yep, that is correct. Each time you attach a program to a chart, it is like having a new program running, independent from the others (even if we attach the same program). Then, GVs of the terminal are one (not the only) of the means to exchange values between various programs/charts. For example, another way to accomplish that is to create a file, with FileOpen() and use that file for the same purpose.

A last remark I would like to do, while I understand that you are new to it, but hey :) So, I was writing that OnInit() and Start() are independent and you may not assume order of execution. What's more, so does OnDeinit(). So, for example, when you change timeframe, OnDeinit() is called for the current TF and OnInit() is called on the new one. If, e.g OnDeinit() is big enough, OnInit() may execute before OnDeinit() returns.

Greets

 
Demos Stogios:

Yep, that is correct. Each time you attach a program to a chart, it is like having a new program running, independent from the others (even if we attach the same program). Then, GVs of the terminal are one (not the only) of the means to exchange values between various programs/charts. For example, another way to accomplish that is to create a file, with FileOpen() and use that file for the same purpose.

A last remark I would like to do, while I understand that you are new to it, but hey :) So, I was writing that OnInit() and Start() are independent and you may not assume order of execution. What's more, so does OnDeinit(). So, for example, when you change timeframe, OnDeinit() is called for the current TF and OnInit() is called on the new one. If, e.g OnDeinit() is big enough, OnInit() may execute before OnDeinit() returns.

Greets

I am trying to get my head around the fact that the order of operations/execution is not necessarily linear, as you mention. 

Thanks a lot for all your help.

Reason: