How to record the time at which High & Low occurs?

 

Kindly help me creating two buffers TimeH[] and TimeH[] for each Period() as following:

Taking into consideration that,

DeltaT=Time[i+1] - Time[i]=Time[i+1] + Period()*60;

where x the main parameter (in seconds) within the period starting from x=0 to x=Period()*60

so that, How can we use such index based on x values i.e. xTime=Time[i+1] + x ; 0<= x >= Period()*60

and What is the variable to be compared with the High/Low values to satisfy the following conditions:

  • if(Price[x] == High[i]) TimeH[i]=H_time;
  • if(Price [x] == Low[i]) TimeL[i]=L_time;
Please advice
 

https://docs.mql4.com/series/iHighest

Play with it and see what it does

 

1. How to records the time at which High & Low occurs ?, That's your title,

  if (High [pos + 1] < High [pos] && High [pos] > High [pos - 1] ) Time_High = Time  [pos];
  if (Low  [pos + 1] > Low  [pos] && Low  [pos] < Low  [pos - 1] ) Time_Low  = Time  [pos];

2. The variable to be compared is Close [n].

 
onewithzachy:

1. How to records the time at which High & Low occurs ?, That's your title,

2. The variable to be compared is Close [n].


Thank you deVries & onewithzachy for your support

Now you give me two different ways to obtain my target.

The first one to get the location by using iHighest

The second one to test the pos and then obtaining the time

Now assume that for M1 timeframe:

i=10 (for example)

i is now fixed, so can i go through its 60 seconds to detect the High (@32) and Low (@55) ?

[pos] index can not be used from 0 to 60 cause it will point to another Bars.

iHighest can not be applied on seconds.

 
OmegaFX:

Kindly help me creating two buffers TimeH[] and TimeH[] for each Period() as following:

Taking into consideration that,

DeltaT=Time[i+1] - Time[i]=Time[i+1] + Period()*60;

where x the main parameter (in seconds) within the period starting from x=0 to x=Period()*60

so that, How can we use such index based on x values i.e. xTime=Time[i+1] + x ; 0<= x >= Period()*60

and What is the variable to be compared with the High/Low values to satisfy the following conditions:

  • if(Price[x] == High[i]) TimeH[i]=H_time;
  • if(Price [x] == Low[i]) TimeL[i]=L_time;
Please advice

You cannot index a price series by seconds because no such data exists. MT4 has history data down to 1 minute bars only. During that 1 minute bar there is a High, Low, Open and Close. That is all that is known for sure. MT4 then invents the intermediate ticks based on some sort of algorithm, and I am not sure if that is explicitly published. Therefore the best you can reasonably do is to use M1 data and use the iHighest function as suggested by deVries above.
 

Please check out and correct my code:

int start()
  {
   int    i, n=Bars, counted_bars=IndicatorCounted();
//----
   
   for(i=0;  i<=n-1; i++)
   {
   int shift=i*Period();
   int limit=Period()-1;
      
   datetime StartTime=iTime(Symbol(),PERIOD_M1,shift+limit);
   datetime FinishTime=iTime(Symbol(),PERIOD_M1,shift);
   
   int timeHigh = iHighest(Symbol(),PERIOD_M1,MODE_HIGH,limit,shift);
   datetime timeH=iTime(Symbol(),PERIOD_M1,timeHigh);
   ExtMapBufferH[i]=(timeH-StartTime)/(FinishTime-StartTime);
      
   int timeLow = iLowest(Symbol(),PERIOD_M1,MODE_LOW,limit,shift);
   datetime timeL=iTime(Symbol(),PERIOD_M1,timeLow);
   ExtMapBufferL[i]=(timeL-StartTime)/(FinishTime-StartTime);
   
   }
//----
   return(0);
  }

It should calculate the High/Low times in dimensionless value within range of 0 and 1

ExtMapBufferH[i] = 0 if High[i]=Open[i] and,

ExtMapBufferH[i] = 1 if High[i]=Close[i], the same for ExtMapBufferL[i]

Reason: