MQL5 Finding values of a candle in an array

RedTaurus  

Hello To the group

I just started studying MQL5 and I found myself having to solve a simple question for those who are more advanced.

I have a period during the day definable by inputs.

I check if I'm on period or if period has passed but I'm still on the day.

I add the data of the candles in an array with CopyRates and look for the highest value.

The strange thing is that when I open the graph from Debug it shows me in the Print first the values of H1 and moving to M1 they vary even if

the Candles that I am going to memorize are all at M1.

I add the code


 input int    OraInizio    =   4 ;
input int    MinutiInizio =   0 ;
input int    OraFine      =   7 ;
input int    MinutiFine   =   0 ;
int          OraCheck;      
datetime     OraAttuale;
long         DaInizioGiorno;

int OnInit ()
  {
     ChartSetSymbolPeriod ( 0 , NULL , PERIOD_M1 );
    
   Elabora();
 
   return ( INIT_SUCCEEDED );
  }


void Elabora() {


    OraAttuale = TimeLocal ();
    DaInizioGiorno = (OraAttuale% 86400 )/ 60 ;
     
     int OraStart= 60 *OraInizio+MinutiInizio;
     int OraStop = 60 *OraFine  +MinutiFine  ;
  
       if ( DaInizioGiorno >= OraStop ) { 
         OraCheck = OraStop ;
         Comment ( " Periodo attivo giá passato " ); 
      }
       if ( DaInizioGiorno > OraStart && DaInizioGiorno < OraStop ) {
         OraCheck = OraAttuale;
         Comment ( " Periodo attivo " );
      }
       if ( DaInizioGiorno < OraStart) {
         Comment ( " Periodo non ancora attivo " );
      }
     
   MqlRates rates[]; 
   int copied = CopyRates ( NULL , PERIOD_M1 ,OraStart,( OraCheck - OraStart ) ,rates);   // Calcola le candele nel periodo se ancora non completato
                                                                                     // calcola sino all-ultima disponibile  
   if (copied<= 0 ) {
       Print ( "Errore nella copia dei dati dei prezzi " , GetLastError ()); 
   } else { 
       Print ( "Copiate " , ArraySize (rates), " barre" );          
   }    
   
   int       hBar = iHighest ( NULL , 0 , MODE_HIGH , ArraySize (rates));   // Candela con valore Highest del periodo
   double    HhBar = rates[hBar].high;                             // Valore Candela hBar
   int       HBarDaInizio = OraStart + hBar;                       // Candela hBar conteggiata da inizio giorno
   
   Print ( "InizioGiorno: "     + DaInizioGiorno ); 
   Print ( "OraCheck    : "     + OraCheck );
   Print ( "HBarDaInizio: "     + HBarDaInizio );
   Print ( "HhBar       : "     + HhBar );          
   Print ( "hBar        : "     + hBar );  
 
}   

What I would like to get is to know the maximum value of the period and which candle has generated it.


Thanks to anyone who can give me a suggestion

Custom Graphical Controls. Part 1: Creating a Simple Control
Custom Graphical Controls. Part 1: Creating a Simple Control
  • www.mql5.com
This article covers general principles of development of graphical controls. We are going to prepare tools for a quick and convenient work with graphical objects, analyze an example of creation of a simple control for entering text or numeric data as well as the ways of using it.
Reason: