- Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
- 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.)
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.
bool rebuildOneTime=true;
Ok for indicators, not EAs on some deinit/init cycles:
So far so good,
but is there a way to differentiate between ChartChange (symbol, TF) and terminal restart or load indicator?
Thank you
Why do you need to know? You just need to reset the global on chart change.
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
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
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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