why not use mql4 instructions :
int x =20;//the last x candles ResetLastError(); int low_indice = iLowest(_Symbol,_Period,MODE_LOW,x,1); if (low_indice !=-1) { double low_value = iLow(_Symbol,_Period,low_indice); if (low_value==0) Print("Error While searching low_value"); else PrintFormat("Lowest value of past x candles = %s",low_value); } else Print("Error While searching low_indice"); int high_indice = iHighest(_Symbol,_Period,MODE_HIGH,x,1); if (high_indice !=-1) { double high_value = iHigh(_Symbol,_Period,high_indice); if (high_value==0) Print("Error While searching high_value"); else PrintFormat("Highest value of past x candles = %s",high_value); } else Print("Error While searching high_indice");
paul selvan :
perché non usare le istruzioni di mql4:
Thanks Paul, but I was trying to get the lowest closure and the highest closing of the last x candles. The returned value is incorrect. Why? I would draw levels on the highest/lowest close of x candle. Thankyou :)
graphic image
https://imgur.com/KtXGV7R
Source code
https://imgur.com/oQ8sggf
RealRik: I wrote this program to find the values of the highest and lowest closures of the last n candles.
The values that are returned to me do not correspond to the real value. Why? :
int ChiusuraMax = ArrayMaximum(prezzo, WHOLE_ARRAY, 0); int ChiusuraMin = ArrayMinimum(prezzo, WHOLE_ARRAY, 0); void OnStart() { prezzo [0] = iClose(Symbol(),PERIOD_CURRENT,1); prezzo [1] = iClose(Symbol(),PERIOD_CURRENT,2);
- Please edit
your (original) post and use the CODE button
(Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - Don't copy and past code - use a loop to initialize your array.
- Global and static variables 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 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.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi guys, I wrote this program to find the values of the highest and lowest closures of the last n candles. The values that are returned to me do not correspond to the real value. Why? :( int ChiusuraMax = ArrayMaximum(prezzo, WHOLE_ARRAY, 0); int ChiusuraMin = ArrayMinimum(prezzo, WHOLE_ARRAY, 0); void OnStart() { prezzo [0] = iClose(Symbol(),PERIOD_CURRENT,1); prezzo [1] = iClose(Symbol(),PERIOD_CURRENT,2); prezzo [2] = iClose(Symbol(),PERIOD_CURRENT,3); prezzo [3] = iClose(Symbol(),PERIOD_CURRENT,4); prezzo [4] = iClose(Symbol(),PERIOD_CURRENT,5); prezzo [5] = iClose(Symbol(),PERIOD_CURRENT,6); prezzo [6] = iClose(Symbol(),PERIOD_CURRENT,7); prezzo [7] = iClose(Symbol(),PERIOD_CURRENT,8); prezzo [8] = iClose(Symbol(),PERIOD_CURRENT,9); prezzo [9] = iClose(Symbol(),PERIOD_CURRENT,10); prezzo [10] = iClose(Symbol(),PERIOD_CURRENT,11); prezzo [11] = iClose(Symbol(),PERIOD_CURRENT,12); prezzo [12] = iClose(Symbol(),PERIOD_CURRENT,13); prezzo [13] = iClose(Symbol(),PERIOD_CURRENT,14); prezzo [14] = iClose(Symbol(),PERIOD_CURRENT,15); prezzo [15] = iClose(Symbol(),PERIOD_CURRENT,16); prezzo [16] = iClose(Symbol(),PERIOD_CURRENT,17); prezzo [17] = iClose(Symbol(),PERIOD_CURRENT,18); prezzo [18] = iClose(Symbol(),PERIOD_CURRENT,19); prezzo [19] = iClose(Symbol(),PERIOD_CURRENT,20); // ObjectCreate(Symbol(),"LINEA EA RIKI",OBJ_HLINE,0,0,ChiusuraMax); Comment("CHIUSURA PIÙ ALTA " + ChiusuraMax + "CHIUSURA PIÙ BASSA " + ChiusuraMin); } //+------------------------------------------------------------------+
Thankyou :)