High or Low == Close

 
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DimGray
#property indicator_color2 Lime
#property indicator_color3 Red
double price[0],G[0],R[0];
int N;
int init(){
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,DimGray);SetIndexBuffer(0,price);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Lime);SetIndexBuffer(1,G);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,Red);SetIndexBuffer(2,R);
   return(0);
   }
int deinit(){return(0);}
int start(){
   for(N=Bars;N>=0;N--){price[N]=Close[N];}
   for(N=Bars;N>=0;N--){
      if((Close[N]*1000)==(Low[N]*1000)){R[N]=price[N];G[N]=EMPTY_VALUE;}
      if((Close[N]*1000)==(High[N]*1000)){G[N]=price[N];R[N]=EMPTY_VALUE;}
      }
   return(0);
   }

I have this problem with indicators that I make <,>,==,!= don't always work. Does anyone know why? This indicator is on a range-bar chart, A range-bar chart must exceed its range in order to complete a bar so Close must be always equal to ether high or Low. I have also multiplied prices (High,Low,Close) by 1000 to make double numbers whole, comparable, without fraction. I don't see how metatrader does not see 81457 is equal to 81457???

 

Maybe try the following substitutions in your code just in case the range bars are using figures past the displayed decimals

Close[N]*1000  >>  MathRound(Close[N]*1000)
Low[N]*1000    >>  MathRound(Low[N]*1000)
High[N]*1000   >>  MathRound(High[N]*1000)
 

same result !

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DimGray
#property indicator_color2 Lime
#property indicator_color3 Red
double price[0],G[0],R[0];
int N;
int init(){
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,DimGray);SetIndexBuffer(0,price);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Lime);SetIndexBuffer(1,G);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,Red);SetIndexBuffer(2,R);
   return(0);
   }
int deinit(){return(0);}
int start(){
   for(N=Bars;N>=0;N--){price[N]=Close[N];}
   for(N=Bars;N>=0;N--){
      if((MathRound(Close[N]*1000))==(MathRound(Low[N]*1000))){R[N]=price[N];G[N]=EMPTY_VALUE;}
      if((MathRound(Close[N]*1000))==(MathRound(High[N]*1000))){G[N]=price[N];R[N]=EMPTY_VALUE;}
      }
   return(0);
   }
 
maybe it's because of EMPTY_VALUE being such an extreme?
 

I'm Still learning about indicators here shouldn't the SetIndexBuffer statement come before SetIndexStyle or is that not supposed to matter?

*edit* nevermind found that seems to be the style of doing it.

 
benzmuircroft: I have this problem with indicators that I make <,>,==,!= don't always work. Does anyone know why?

Doubles rarely compare equal. Multiplying by a 1000 does not change that.

Can price != price ? - MQL4 forum
Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum



 

This is simple stuff MQL4 cant seem to handle (so many indicators, ea's would work better if this was fixed)... sorry i am just quite annoyed (its like finding out that your calculator is broken when all this time you thought it was YOU doing bad sums).

Anyway... StrToInteger(DoubleToStr(Close[0]*1000,3)) gives me something like eg: 82431. So its now working by comparing ints!

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DimGray
#property indicator_color2 Lime
#property indicator_color3 Red
double price[0],G[0],R[0];
int N;
int init(){
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,DimGray);SetIndexBuffer(0,price);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Lime);SetIndexBuffer(1,G);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,Red);SetIndexBuffer(2,R);
   return(0);
   }
int deinit(){return(0);}
int start(){
   for(N=Bars;N>=0;N--){price[N]=Close[N];}
   for(N=Bars;N>=0;N--){
      if( (DoubleToStr(Close[N]*1000,0))==(DoubleToStr(Low[N]*1000,0)) ){R[N]=price[N];G[N]=EMPTY_VALUE;}
      if( (DoubleToStr(Close[N]*1000,0))==(DoubleToStr(High[N]*1000,0)) ){G[N]=price[N];R[N]=EMPTY_VALUE;}
      Comment("\n",StrToInteger(DoubleToStr(Close[N]*1000,3)),
              "\n",StrToInteger(DoubleToStr(High[N]*1000,3)),
              "\n",StrToInteger(DoubleToStr(Low[N]*1000,3)),
              "\n",DoubleToStr(Close[N]*1000,0),
              "\n",DoubleToStr(High[N]*1000,0),
              "\n",DoubleToStr(Low[N]*1000,0)
              );
      }
      
   return(0);
   }

Same result !


Just a thought... If MQL4 cant compare doubles,ints why isn't this indicator always grey? why on earth does it sometimes succeed? surely it should never be green/red (numbers are ether comparable or they are not, this is the RULE or is it not?)

 

in fact StrToInteger(DoubleToStr(Close[N]*1000,3)) has redundant code compared to DoubleToStr(Close[N]*1000,0) my mistake, yet it does not matter because MQL4 still doesn't compare correctly and I still get the same result !

PS: I edited my last post

 

https://www.mql5.com/en/forum/138355 From RaptorUK... Same result !

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DimGray
#property indicator_color2 Lime
#property indicator_color3 Red
double price[0],G[0],R[0];
int N;
int init(){
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,DimGray);SetIndexBuffer(0,price);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Lime);SetIndexBuffer(1,G);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,Red);SetIndexBuffer(2,R);
   return(0);
   }
int deinit(){return(0);}
int start(){
   for(N=Bars;N>=0;N--){price[N]=Close[N];}
   for(N=Bars;N>=0;N--){
      if( (MathRound(MathPow(10,Digits)*(Close[N]+(4.9/(MathPow(10,Digits)*10)))))==(MathRound(MathPow(10,Digits)*(Low[N]+(4.9/(MathPow(10,Digits)*10))))) ){R[N]=price[N];G[N]=EMPTY_VALUE;}
      if( (MathRound(MathPow(10,Digits)*(Close[N]+(4.9/(MathPow(10,Digits)*10)))))==(MathRound(MathPow(10,Digits)*(High[N]+(4.9/(MathPow(10,Digits)*10))))) ){G[N]=price[N];R[N]=EMPTY_VALUE;}
      }
   return(0);
   }
 

Arrrghh!!

 

Storing them as actual ints then comparing ints also gives same result !

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DimGray
#property indicator_color2 Lime
#property indicator_color3 Red
double price[0],G[0],R[0];
int N;
int init(){
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,DimGray);SetIndexBuffer(0,price);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Lime);SetIndexBuffer(1,G);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,Red);SetIndexBuffer(2,R);
   return(0);
   }
int deinit(){return(0);}
int start(){
   for(N=Bars;N>=0;N--){price[N]=Close[N];}
   for(N=Bars;N>=0;N--){
      int C=StrToInteger(DoubleToStr(Close[N]*1000,3));
      int H=StrToInteger(DoubleToStr(High[N]*1000,3));
      int L=StrToInteger(DoubleToStr(Low[N]*1000,3));
      if( C==L ){R[N]=price[N];G[N]=EMPTY_VALUE;}
      if( C==H ){G[N]=price[N];R[N]=EMPTY_VALUE;}
      }
   return(0);
   }

this is dumb, I'm going to sleep(nightTime);

Reason: