Get time from last 52 week's highest price

 

Hi, I'm trying to get time from specific candle like highest price from last 52 candles but it gives me incorrect time, can anyone help me?

Here's my code:


   
   double Highest  = High[0];
   double Highest1 = High[0];
   double Lowest   = Low[0];
   
   for(int i = 0; i <= 52; i++){
      if(High[i] > Highest)  Highest  = Time[i];
      if(High[i] > Highest1) Highest1 = High[i];
      if(Low[i]  < Lowest)   Lowest   = Low[i];
   }
   Print(TimeToStr(Highest) + " " + Highest1);


Thanks in advance

 
mr-roma:

Hi, I'm trying to get time from specific candle like highest price from last 52 candles but it gives me incorrect time, can anyone help me?

Here's my code:



Thanks in advance

You will not get time from a double value....

Use the built in functions

iHighest will return the index of the highest bar in the range specified

iTime will return the time of the bar with the specified index 

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
Paul Anscombe:

You will not get time from a double value....

Use the built in functions

iHighest will return the index of the highest bar in the range specified

iTime will return the time of the bar with the specified index 

I know iHighest and iTime but I don't know how to find which candle is the highest in range to specify in iTime. I mean if 31th is the highest in last 52 candles than I will use that number in iTime

 

The high of the weekly candle is already the highest of that week.

iHighest will return the bar index number which you can use in iTime also.

 
mr-roma:

I know iHighest and iTime but I don't know how to find which candle is the highest in range to specify in iTime. I mean if 31th is the highest in last 52 candles than I will use that number in iTime

   int iHi = iHighest(_Symbol,_Period,MODE_HIGH,52,0);
   
   datetime dtTime = iTime(_Symbol,_Period,iHi);
   
   Print("Bar Index: " + iHi + "   Time: " + dtTime);
 

If someone would need it, here's the code:

   int r52wHn   = iHighest( NULL, PERIOD_W1, MODE_HIGH, 52);                                //52 Week's Highest Candle
   int r52wLn   = iLowest( NULL, PERIOD_W1, MODE_LOW, 52);                                  //52 Week's Lowest Candle
   double r52wH = iHigh(_Symbol, PERIOD_W1, iHighest( _Symbol, PERIOD_W1, MODE_HIGH, 52));  //52 Week's Highest Price
   double r52wL = iLow(_Symbol, PERIOD_W1, iLowest( _Symbol, PERIOD_W1, MODE_LOW, 52));     //52 Week's Lowest Price
   
   string r52wHt = StringSubstr(TimeToStr(iTime(Symbol(),PERIOD_W1,r52wHn)), 0, 10);        //Show Date only
   string r52wLt = StringSubstr(TimeToStr(iTime(Symbol(),PERIOD_W1,r52wLn)), 0, 10);        //Without Time
    
   SetLabel2 ("trtdg2", r52wHt + " " + r52wH, "Arial", WColor, 195, 60, CsymTp, 10, 3, ANCHOR_LEFT_LOWER);
   SetLabel2 ("trtdg3", r52wLt + " " + r52wL, "Arial", WColor, 195, 40, CsymTp, 10, 3, ANCHOR_LEFT_LOWER);


Marco and Paul Thanks for your suggestions 

Reason: