Find lower closing value than the last x candles

To add comments, please log in or register
RealRik
11
RealRik  

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 :)

paul selvan
629
paul selvan  

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");
RealRik
11
RealRik  
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

Imgur
  • 2019.06.10
  • imgur.com
Post with 0 votes and 2 views.
William Roeder
18943
William Roeder  
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);  

  1. 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

  2. Don't copy and past code - use a loop to initialize your array.

  3. Global and static variables work exactly the same way in MT4/MT5/C/C++.
    1. They are initialized once on program load.
    2. They don't update unless you assign to them.
    3. In C/C++ you can only initialize them with constants, and they default to zero.
    4. 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:

      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.
You are trying to get the min/max of your arrays, before you populate them.
To add comments, please log in or register