Please help "This Is Insane"

 

This Tiny Piece Of Code Is Meant To Get The Highest Low  And The Lowest high on The Chart

(I Know The iHighest,iLowest , But The Get The Low And High Of The Candle With Highest High And Lowest Low , What I want Is To get

   The Highest Low Even If Its Not In The Highest Candle And vice versa)

So I Aimed To move From left To Right If The Low is Highest i save it If Not I Continue And So On..

The Insane Thing Happening To me Is When It Comes To The Highest Low It Works Excellent

But It Don't Work With The Lowest high And I Don't Know Why.....





double HighestLow;

double LowestHigh;

double CurLow;

double CurHigh;

double PrevHigh;

//---

for(int i=MathMax(Bars-2-IndicatorCounted(),1);i>0;i--) {


while(i>0){

CurLow=Low[i];

if(CurLow>=HighestLow)   HighestLow=CurLow;

else

HighestLow=HighestLow;

i--;

//-----


CurHigh=High[i];

if(CurHigh<=LowestHigh)   LowestHigh=CurHigh;

else

LowestHigh=LowestHigh;

i--;

Print("HighestLow= ",+HighestLow,"\nLowestHigh= ",+LowestHigh);

}

}

//+------------------------------------------------------------------+

Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • 2022.02.04
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
Get the highest low ... iHighest( _Symbol, _Period, MODE_LOW )
Get the lowest high ... iLowest( _Symbol, _Period, MODE_HIGH )
 
Fernando Carreiro #:
Get the highest low ... iHighest( _Symbol, _Period, MODE_LOW )
Get the lowest high ... iLowest( _Symbol, _Period, MODE_HIGH )

thank you for replaying

 but as i mentioned  iHighest gets me the low of the candle with the highest high if the next candle or the next two candles have higher low but Lowerhigh they dont appear

however the problem is the code works well but with getting the highest low but Dont work at all to get the lowesthigh although it have the same code(with inverted (>) Of course)

 
Ahmed Mokhtar # but as i mentioned  iHighest gets me the low of the candle with the highest high if the next candle or the next two candles have higher low but Lowerhigh they dont appear

however the problem is the code works well but with getting the highest low but Dont work at all to get the lowesthigh although it have the same code(with inverted (>) Of course)

The following code is untested and not compiled. Just serves as an example:

HighestLow = 0;
LowestHigh = DBL_MAX;

for( int i = MathMax( Bars - 2 - IndicatorCounted(), 1 ); i>0; i-- )
{
   if( Low[i]  > HighestLow ) HighestLow = Low[i];
   if( High[i] < LowestHigh ) LowestHigh = High[i];
}

Print( "HighestLow = ", HighestLow, "; LowestHigh = ", LowestHigh );

Also you are using the old style almost decrepit code (eg. IndicatorCounted). Use the more modern MQL4+ style which is compatiable with MQL5.

PS! Your loop will also fail if their is only the current bar available and not a previous bar.

 
Fernando Carreiro #:

Code is untested or compiled. Just serves as an example:

Also you are using the old style almost decrepit code (eg. IndicatorCounted). Use the more modern MQL4+ style which is compatiable with MQL5.

Thank You Very Much

That Was Perfect

"Also you are using the old style almost decrepit code (eg. IndicatorCounted). Use the more modern MQL4+ style which is compatiable with MQL5."


Sure I Started Only One Week Ago And Still Learning Thank You Very Much For Your Advise :D

 
Ahmed Mokhtar #: Thank You Very Much. That Was Perfect. Sure I Started Only One Week Ago And Still Learning Thank You Very Much For Your Advise :D
You are welcome!
Reason: