- If you change TF or symbol you get a deinit/init cycle.
- You should not be doing anything in OnInit other than what is necessary to initialize the EA before the first tick. You shouldn't even try to use any price or server related functions in
OnInit as there may be no connection/chart yet:
- Terminal starts.
- indicators/EAs are loaded.
- 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 and prices are now valid.
- What do you mean by "an operation?"
Hi,
one question, i noticed that when I ask to do an operation OnInit()...it does the operation when the EA starts, but also when I just change the Timeframe, from 1 minute, to 5 and so on.
Is it possible to ask him to don't do the operation in case I want to change the timeframe?
https://www.mql5.com/en/docs/globals
// This is not complete and untested if ( GlobalVariableGet(WindowExpertName()) == 1.0 ) { Print(StringFormat("EA %s has already run this block of code once.", WindowExpertName())); } else { GlobalVariableSet(WindowExpertName(), 1.0); { // block of code you run once } }
- What do you mean by "an operation?"
(sorry if my english is not perfect)
I have inserted these functions on Init(),
ObjectsDeleteAll(0, OBJ_VLINE); ObjectsDeleteAll(0, OBJ_ARROW_CHECK); ObjectsDeleteAll(0, OBJ_TREND); ObjectsDeleteAll(0, OBJ_CHANNEL); ObjectsDeleteAll(0, OBJ_ARROW);
because my EA draws lines, arrows etc. And I want every time all clear when it starts. But not if I change the timeframes...I was wondering if it was possible...
florenceale:
And I want every time all clear when it starts. But not if I change the timeframes...I was wondering if it was possible...
If you switched the location to Deinit() you can check for how the EA was closed.
If it was because you changed the time frame, don't erase.
void OnDeinit(const int reason) { if ( reason != REASON_CHARTCHANGE ) { // Clean all drawn objects ObjectsDeleteAll(0, OBJ_VLINE); ObjectsDeleteAll(0, OBJ_ARROW_CHECK); ObjectsDeleteAll(0, OBJ_TREND); ObjectsDeleteAll(0, OBJ_CHANNEL); ObjectsDeleteAll(0, OBJ_ARROW); } }
If you switched the location to Deinit() you can check for how the EA was closed.
If it was because you changed the time frame, don't erase.
i will try like this, it looks simple. Thanks a lot

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
one question, i noticed that when I ask to do an operation OnInit()...it does the operation when the EA starts, but also when I just change the Timeframe, from 1 minute, to 5 and so on.
Is it possible to ask him to don't do the operation in case I want to change the timeframe?