You should share all the code. Difficult to judge like this.
Sure
//+------------------------------------------------------------------+ //| daniel1.mq4 | //| Milvetti | //| https://www.milvetti.com | //+------------------------------------------------------------------+ #property copyright "Milvetti" #property link "https://www.milvetti.com" #property version "1.00" #property strict #include <stdlib.mqh> //--- input parameters input datetime startTime=D'2024.07.10'; //Start Time input datetime endTime=D'2025.07.15'; //End Time input datetime candleTime = D'23:45'; //Candle Time input bool showLines = true; // Show Lines input int timeZone = 0; // UTC+- input color upColor = clrRed; //Up Color input color dnColor = clrBlue; //Down Color string scriptName = "Daniel Levels[EA]"; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ string cTime =TimeToStr(candleTime,TIME_MINUTES); double levelPrices[]; double blueLines[]; double redLines[]; int checkStart = 0; int OnInit() { Comment("Loading..."); checkStart=0; int nu = ObjectsDeleteAll(); Print(nu); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { //--- int nu = ObjectsDeleteAll(); Print(nu); } int prev_calculated =0; void OnTick() { int rates_total = iBars(NULL,0); //5000 bar var int limit = rates_total - prev_calculated; if (prev_calculated>0) limit++; for(int i=0;i<limit;i++) { if(GetTime(Time[i],timeZone)<startTime) { prev_calculated=rates_total; break; } prev_calculated+=1; string currentCandleTime = TimeToStr(GetTime(Time[i],timeZone),TIME_MINUTES); if(currentCandleTime == cTime && GetTime(Time[i],timeZone)>startTime ) { if(showLines) { if (ObjectCreate(0, "UpArrow"+Time[i], OBJ_ARROW_UP, 0, Time[i], Low[i])) { ObjectSetInteger(0, "UpArrow"+Time[i], OBJPROP_COLOR, clrDodgerBlue); ObjectSetInteger(0, "UpArrow"+Time[i], OBJPROP_ARROWCODE, 233); // Arrow code for upward arrow } else Print(GetLastError()); if (ObjectCreate(0, "LowLine"+Time[i], OBJ_HLINE, 0, Time[i], Low[i])) ObjectSetInteger(0, "LowLine"+Time[i], OBJPROP_COLOR, dnColor); else Print(GetLastError()); ObjectCreate(0, "HighLine"+Time[i], OBJ_HLINE, 0, Time[i], High[i]); ObjectSetInteger(0, "HighLine"+Time[i], OBJPROP_COLOR, upColor); } }//End If }//End For if(checkStart==0) { checkStart+=1; Comment(scriptName); } } //+------------------------------------------------------------------+ datetime GetTime (datetime gmtTime,int offset) { datetime localTime = gmtTime + (offset * 3600); return localTime; }
//| Expert initialization function | //+------------------------------------------------------------------+ string cTime =TimeToStr(candleTime,TIME_MINUTES); ⋮ if(currentCandleTime == cTime && GetTime(Time[i],timeZone)>startTime )
That is not an assignment; it's initialization of a common (globally declared), or static variable(s) with a constant. They work exactly the same way in MT4/MT5/C/C++.
-
They are initialized once on program load.
-
They don't update unless you assign to them.
-
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), 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.
- A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
- 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, I am working on an Ea. This Ea checks historical data and draws support and resistance levels.
My problem is this: the objects are displayed on the screen without any issues when the Ea starts, but I noticed that the objects are not drawn after making any changes in the properties.
What could be the reason for this?
Thanks
I delete all objects within the Deinit method.