# HIghest High and Lowest Low Question

12

Has anyone had any experience with finding the highest high and lowest low, between two points in time.  I'm trying to draw a line at the highest high and lowest low from 3:00 p.m. to 5:00 p.m. est.  ( 19:00 - 0:00 )  I can draw a line between these two points of time, but only at the high and low of the day.  I can find the high and low between a certain number of candles, but becomes a problem as time moves forward the candle numbers keep changing.  If I start with the candle at 19:00 ( 228 ) and count backwards towards the current ( 168 = 0:00 ) 60 candles ( 5 minute chart )  I can get the high and low of each candle, but I need the highest of the high and lowest of the low.

Below is the code I've been working on.  Maybe someone can tell me what I'm missing or doing wrong.

Thanks!

Yellowbeard

//+--------------------------------------------------------------------------+
//|                                                   Daily High and Low.mq4 |
//|                                                                       me |
//|                                                                          |
//+--------------------------------------------------------------------------+

#property indicator_chart_window

extern int Hour_Num = 19;
extern int Hour_Num_A = 0;

extern int Minute_Num = 0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{

datetime BeginTime, EndTime;
int ph;
int Counted_bars=IndicatorCounted();
int p=Bars-Counted_bars-1;

while(p>=0)
{
if(TimeHour(Time[p]) == Hour_Num && TimeMinute(Time[p]) == Minute_Num)

{ ph=ph+1;

double pvH =  iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 60, 168));

if(p > 0)
{
BeginTime = iTime( NULL, PERIOD_D1, pvH );
EndTime   = BeginTime - 18000;
}

//double pvH=iHigh(NULL, PERIOD_D1,ph);

//  double pvH=iHighest(NULL,0,MODE_HIGH,60,-168);

/*  ObjectDelete("DnSymbolBz");
ObjectCreate("DnSymbolBz", OBJ_ARROW, 0, Time[p],pvH);
ObjectSet("DnSymbolBz", OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
ObjectSet("DnSymbolBz", OBJPROP_WIDTH,2);
ObjectSet("DnSymbolBz", OBJPROP_COLOR,Red);
ObjectSet("DnSymbolBz", OBJPROP_ANCHOR, ANCHOR_BOTTOM);*/

ObjectDelete("OpenTtA");
ObjectCreate("OpenTtA",OBJ_HLINE,0,Time[p],pvH);
ObjectSet("OpenTtA", OBJPROP_COLOR, LightGreen);

ObjectDelete("pHg_Line"+ph);
ObjectCreate("pHg_Line"+ph, OBJ_TREND, 0, BeginTime, pvH, EndTime, pvH );
ObjectSet("pHg_Line"+ph, OBJPROP_COLOR, MediumSeaGreen);
ObjectSet("pHg_Line"+ph, OBJPROP_STYLE, STYLE_DASH);
ObjectSet("pHg_Line"+ph, OBJPROP_WIDTH, 1);
ObjectSet("pHg_Line"+ph, OBJPROP_RAY, False);

}
p--;
ObjectSet("pHg_Line"+ph,OBJ_TREND,EndTime);

ChartRedraw(ChartID());

}

//----
return(0);
}
//+------------------------------------------------------------------+

1615

If you convert your starting and ending time to bar number ... then this will work for you ...

HH =  iHigh(Symbol(), TimeFrame, iHighest(NULL,0,MODE_HIGH,NoOfBars,StartingBar));
LL =  iLow(Symbol(), TimeFrame, iLowest(NULL,0, MODE_LOW,NoOfBars,StartingBar));

12

Osama Shaban:

If you convert your starting and ending time to bar number ... then this will work for you ...

HH =  iHigh(Symbol(), TimeFrame, iHighest(NULL,0,MODE_HIGH,NoOfBars,StartingBar));
LL =  iLow(Symbol(), TimeFrame, iLowest(NULL,0, MODE_LOW,NoOfBars,StartingBar));

This code seems to work by it's self.  But I need to know which candle, during the two points in time, was the high and which one was the low.

int start()
{

//  HH =  iHigh(Symbol(), TimeFrame, iHighest(NULL,0,MODE_HIGH,NoOfBars,StartingBar));
//   LL =  iLow(Symbol(), TimeFrame, iLowest(NULL,0, MODE_LOW,NoOfBars,StartingBar));

int CntBarsz = 60;

int lowshiftl=iLowest(NULL,0,MODE_LOW,CntBarsz,168);

double Minimuml=Close[lowshiftl];
datetime lowtimel=Time[lowshiftl];

int maxshifth=iHighest(NULL,0,MODE_HIGH,CntBarsz,168);

double Maximumh=Open[maxshifth];
datetime maxtimeh=Time[maxshifth];

for(int i=0;i<CntBarsz-1;i++)
{
if (Low[i]< Minimuml)
{

Minimuml=Low[i]; int nl = i;

ObjectDelete("UpSymbolBz");
ObjectCreate("UpSymbolBz", OBJ_ARROW, 0, lowtimel,Minimuml);
ObjectSet("UpSymbolBz", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet("UpSymbolBz", OBJPROP_WIDTH,2);
ObjectSet("UpSymbolBz", OBJPROP_COLOR,Lime);
ObjectSet("UpSymbolBz", OBJPROP_ANCHOR, ANCHOR_TOP);

ObjectDelete("OpenTtA");
ObjectCreate("OpenTtA",OBJ_HLINE,0,lowtimel,Minimuml);
ObjectSet("OpenTtA", OBJPROP_COLOR, LightGreen);

}

if (High[i]> Maximumh)
{

Maximumh=High[i]; int mh = i;

ObjectDelete("DnSymbolBz");
ObjectCreate("DnSymbolBz", OBJ_ARROW, 0, maxtimeh,Maximumh);
ObjectSet("DnSymbolBz", OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
ObjectSet("DnSymbolBz", OBJPROP_COLOR,Red);
ObjectSet("DnSymbolBz", OBJPROP_ANCHOR, ANCHOR_BOTTOM);

ObjectDelete("OpenDnA");
ObjectCreate("OpenDnA",OBJ_HLINE,0,maxtimeh,Maximumh);
ObjectSet("OpenDnA", OBJPROP_COLOR, Pink);

ChartRedraw();

}

}

//----
return(0);
}

Already had:       double pvH =  iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 60, 168));

The above code only gives me one side.  High or Low.

Thanks!

Yellowbeard

1615

As long as you can now find HH/LL, then you may add a function to scan bars in range and find the bar # of the HH or LL.

Just an idea.

Moderator
2322

Yellowbeard1881:

This code seems to work by it's self.  But I need to know which candle, during the two points in time, was the high and which one was the low.

Osama Shaban:

As long as you can now find HH/LL, then you may add a function to scan bars in range and find the bar # of the HH or LL.

Just an idea.

iHighest and iLowest are already returning the bar index.

You only need iHigh or iLow if you want the actual price.