Difference between terminal start and indicator start

 

Hell everybody,

here is my question: Is there a difference between terminal start (with a chart template which contains my indicator) and an indicator start (drag n drop from indicator list into the chart) ?

The background is I made an indicator which should convert the price of a horizontal line in chart coordinates right from the start. When I start the terminal this calculation fails. When I drag n drop from the indicator list into the chart, it works perfectly. Is there any variable that I can query whether the chart is ready for further calculations?

Thank you

 
  1. Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  2. Frika: (with a chart template which contains my indicator)
    No such thing. Applying a template removes everything and then adds and sets what ever is in the template. Then the template is irrevalent.
 

Thank you William,

everytime the best adress to ask!

Best Regards

 

I understand, thank you,

and how can I determined when the chart is ready to calculate further things like ChartTimePriceToXY() ?

Best Regards

 
When you get a tick (not in OnInit.)
 
William Roeder:
When you get a tick (not in OnInit.)

I did it now on this way:

bool rebuildOneTime=true;

int OnCalculate(const int rates_total,
                const int prev_calculated,
                ...
  {
if(rebuildOneTime && prev_calculated > 0){RebuildSmartlines_struct(); rebuildOneTime = false;} 

}  

this seems to be to work correct. Thanks again for pushing me in the right direction.

 

So far so good,

but is there a way to differentiate between ChartChange (symbol, TF) and terminal restart or load indicator?

Thank you

 
Frika: but is there a way to differentiate between ChartChange (symbol, TF) and terminal restart or load indicator?

Why do you need to know? You just need to reset the global on chart change.

 
William Roeder:

Why do you need to know? You just need to reset the global on chart change.

The rebuild function does the following: it creates a couple of buttons and labels that stick to a horizontal line. With the help of the ChartTimePriceToXY() function, it works very well. When the indicator is initial loaded I use the construct as described above. But it takes a moment for everything to happen. If only the TF is changed, I can also use this rebuild in the oninit function. This is faster and makes the user experience a little more fluid. Therefore it would be nice if I could differentiate between changing TF and initial loading.

And, if it is okey a further question. Is it possible to determine which chart is at the top in MT4?


Best Regards

 
Frika: Therefore it would be nice if I could differentiate between changing TF and initial loading.

Again, you don't need to know. You should have deleted all objects in deinit and must create all in onInit/first tick. What are you going to do different?

You already know how for EAs. #6 and UninitializeReason

Reason: