holes in the indicator

 

I try to create a two-tone Bollinger following phases.

It is no doubt very simple but I can not find why when changing colors there are holes ...

 

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

//| Bollinger Phases Bi-Color.mq4 |

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

#property copyright "JLF"
#property link "http://www.rototo.fr"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Tomato
#property indicator_color2 Lime
#property indicator_color3 Tomato
#property indicator_color4 Lime

extern int Periode = 20;
extern double Deviation = 2;
input ENUM_APPLIED_PRICE Price = PRICE_CLOSE;

double haut,hautnew,bas,basnew;

double HautVert[] ; // boll sup croissante
double HautRouge[] ; // boll sup décroissante
double BasVert[] ; // boll inf croissante
double BasRouge[] ; // boll inf décroissante

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

//| initialisation |

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

int init()
   {
   IndicatorBuffers(4);
   
   SetIndexStyle(0,DRAW_LINE,0,1);
   SetIndexBuffer(0,HautRouge);
   
   SetIndexStyle(1,DRAW_LINE,0,1);
   SetIndexBuffer(1,HautVert);
   
   SetIndexStyle(2,DRAW_LINE,0,1);
   SetIndexBuffer(2,BasRouge);
   
   SetIndexStyle(3,DRAW_LINE,0,1);
   SetIndexBuffer(3,BasVert);
   //----
   return(0);
}

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

//| Bollinger Phase

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

int start()
   {
   int index ;
   int limit=Bars-Periode;
   RefreshRates();
   for(index=limit-2 ; index>=0 ; index--)
      {
      haut = iBands(NULL,0,Periode,Deviation,0,Price,MODE_UPPER,index+1);
      hautnew =iBands(NULL,0,Periode,Deviation,0,Price,MODE_UPPER,index);
      bas = iBands(NULL,0,Periode,Deviation,0,Price,MODE_LOWER,index+1);
      basnew =  iBands(NULL,0,Periode,Deviation,0,Price,MODE_LOWER,index);
      
      if (hautnew >= haut && basnew <= bas)
         {
         HautVert[index] = hautnew;
         BasVert[index] = basnew;
         }
      else
         {
         HautRouge[index] = hautnew;
         BasRouge[index] = basnew;
         }
             
      }
   return(0);
   }

 

 

Files:
phaseboll.mq4  3 kb
 
stanislass:

I try to create a two-tone Bollinger following phases.

It is no doubt very simple but I can not find why when changing colors there are holes ...

 

 

 

 

im uncertain if this is the answer but it appears to work. you;ve got to play around with the order of arrays and the condition of its price in order to get it to work correctly.

anyway u can see from the data window the prices appear funky.

give us an update if you got it figured out


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

//| Bollinger Phases Bi-Color.mq4 |

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

#property copyright "JLF"
#property link "http://www.rototo.fr"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Tomato
#property indicator_color2 Lime
#property indicator_color3 Tomato
#property indicator_color4 Lime
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
extern int Periode = 20;
extern double Deviation = 2;
extern double Price = 0;


double BandsUpperOut[] ; // boll sup croissante
double BandsUpperIn[] ; // boll sup décroissante
double BandsLowerOut[] ; // boll inf croissante
double BandsLowerIn[] ; // boll inf décroissante
int ExtCountedBars=0;


int init()
   {
   IndicatorBuffers(4);
   
   SetIndexBuffer(0,BandsUpperIn);
   SetIndexLabel(0,"BandsUpperIn");
   SetIndexStyle(0,DRAW_LINE,0);
   
   SetIndexBuffer(1,BandsUpperOut);
   SetIndexLabel(1,"BandsUpperOut");
   SetIndexStyle(1,DRAW_LINE,0);
   
   SetIndexBuffer(2,BandsLowerIn);
   SetIndexLabel(2,"BandsLowerIn");
   SetIndexStyle(2,DRAW_LINE,0);
   
   SetIndexBuffer(3,BandsLowerOut);
   SetIndexLabel(3,"BandsLowerOut");
   SetIndexStyle(3,DRAW_LINE,0);
   
   //----
   IndicatorShortName("Bollinger Phase");
   return(0);
}


int start()
 {
 ExtCountedBars=IndicatorCounted();
 if(ExtCountedBars<0){return(-1);}
 if(ExtCountedBars>0){ExtCountedBars--;}
 int pos=Bars-ExtCountedBars-1;
 while(pos>=0)
  {
  BandsUpperIn[pos] = iBands(NULL,0,Periode,Deviation,0,Price,MODE_UPPER,pos);
  BandsLowerIn[pos] = iBands(NULL,0,Periode,Deviation,0,Price,MODE_LOWER,pos);
  
  if(iBands(NULL,0,Periode,Deviation,0,Price,MODE_UPPER,pos) >= 
     iBands(NULL,0,Periode,Deviation,0,Price,MODE_UPPER,pos+1) && 
     iBands(NULL,0,Periode,Deviation,0,Price,MODE_LOWER,pos) <=
     iBands(NULL,0,Periode,Deviation,0,Price,MODE_LOWER,pos+1)
    )
   {
   BandsUpperOut[pos] = iBands(NULL,0,Periode,Deviation,0,Price,MODE_UPPER,pos);
   BandsLowerOut[pos] = iBands(NULL,0,Periode,Deviation,0,Price,MODE_LOWER,pos);
   
   }

   
  pos--;
  }
 return(0);
 }
Files:
 

 

 

Yes, your suggestion works by changing the order of arrays.
No longer persists that the delay the opening of the final table.

Thank you
 
  1. stanislass: why when changing colors there are holes ...
    stanislass: Yes, your suggestion works by changing the order of arrays. No longer persists that the delay the opening of the final table.
    Changing the order fixes nothing, you just hid the problem in one direction.
    You must connect the lines. You have red[5]=value, green[5]=empty, and then green[4]=value. Therefor red ends one bar before green begins, resulting in a gap. If green[5] is empty set it to the same value as red[5] and thus connecting the lines.
  2. if(ExtCountedBars>0){ExtCountedBars--;}
    No need for the decrement. Contradictory information on IndicatorCounted() - MQL4 forum
  3. You lookback is Periode (iBands) Do your lookbacks correctly.
 

Ahhhh okkkk ! 

I debuted in indicator.

I forgot that the route stops in the middle of the candle!

Thanks you two 

Reason: