how to find high/low for 2 min timeframe

 

hi

 

i dont understand how to find the high and the low of the last 2 minute candle

i use this code:

 

void OnTimer() 
   {
   
   datetime thisTime = TimeLocal();
   MqlDateTime tm;
   TimeToStruct(thisTime,tm);
   currentHour = tm.hour;
   currentMinutes = tm.min;
   int currentSecond = tm.sec;
   long div = currentMinutes % 2;

   if (div == 0)
      {
      if (currentSecond == 0)
         {
        
         double highPriceArray[],lowPriceArray[];
         
         CopyHigh(
            Symbol(),     
            PERIOD_M2,       
            thisTime,      
            1,           
            highPriceArray     
         );
         CopyLow(
            Symbol(),     
            PERIOD_M2,       
            thisTime,      
            1,           
            lowPriceArray     
         );

         Print("high: ",highPriceArray[0],"low: ",lowPriceArray[0]);


   }
   

}

 my code, print price different from the price of my mt5 chart, where is my error?

 
Your chart is at broker server time, use TimeCurrent() not TimeLocal().
 
angevoyageur:
Your chart is at broker server time, use TimeCurrent() not TimeLocal().

The ange!

 

it's work with this change,  to get the info of previous 2 min candle i need to take last 2 candle:

 datetime thisTime = TimeCurrent();


         CopyHigh(
            Symbol(),     
            PERIOD_M2,       
            thisTime,      
            2,           <-- i have to request the last two candle if i want the previous candle
            highPriceArray     
         );


 then info about prev candle: 

Print("high: ",highPriceArray[1],"low: ",lowPriceArray[1]);

instead if i want the info about current candle: 

Print("high: ",highPriceArray[0],"low: ",lowPriceArray[0]);

 right?

 
andream1977:

The ange!

 

it's work with this change,  to get the info of previous 2 min candle i need to take last 2 candle:


 then info about prev candle: 

instead if i want the info about current candle: 

 right?

Only if your arrays are indexed as series :

ArraySetAsSeries(highPriceArray,true);
ArraySetAsSeries(lowPriceArray,true);