Problem de with my code

Back to topics list To post a new topic, please log in or register
avatar
8
Recon004 2015.02.23 11:01
 

Indicator with the holesHello,

I changed a code for a best display : continuous thick line and color change when changing direction. But when rendering , you can see the holes in the plot lines as seen from the attached chart.

I can't find the solution.

 The code :

//+------------------------------------------------------------------+
//|                                               Custom BB_Line.mq4 |
//|                                                 Copyright © 2005 |
//|------------------------------------------------------------------+

#property  copyright ""
//#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1  Red    //bbMacd down
#property  indicator_color2  White //bbMacd up
#property  indicator_color3  DimGray    //Upperband
#property  indicator_color4  DimGray     //Lowerband
#property  indicator_color5  Red    //avg down
#property  indicator_color6  White //avg up
//---- indicator parameters
extern int FastLen = 12;
extern int SlowLen = 26;
extern int Length = 10;
extern double StDv = 1;
//----
int loopbegin;
int shift;
double zeroline;
//---- indicator buffers
double ExtMapBuffer1[];  // bbMacd
double ExtMapBuffer2[];  // bbMacd
double ExtMapBuffer3[];  // Upperband Line
double ExtMapBuffer4[];  // Lowerband Line
double ExtMapBuffer5[];  // avg
double ExtMapBuffer6[];  // avg
//---- buffers
double bbMacd[];
double Upperband[];
double Lowerband[];
double avg[];
double bbMacdline;
double sDev;
double mean;
double sumSqr;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 8 additional buffers are used for counting.
   IndicatorBuffers(10);   
//---- drawing settings     
   SetIndexBuffer(0, ExtMapBuffer1); // bbMacd line
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
   IndicatorDigits(Digits + 1);
//----
   SetIndexBuffer(1, ExtMapBuffer2); // bbMacd line
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
   IndicatorDigits(Digits + 1);
//----   
   SetIndexBuffer(2, ExtMapBuffer3); // Upperband line
   SetIndexStyle(2, DRAW_LINE, STYLE_DOT, 1);
   IndicatorDigits(Digits + 1);
//----   
   SetIndexBuffer(3, ExtMapBuffer4); // Lowerband line
   SetIndexStyle(3, DRAW_LINE, STYLE_DOT, 1);
   IndicatorDigits(Digits + 1);
//----
   SetIndexBuffer(4, ExtMapBuffer5); // avg
   SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 2);
   IndicatorDigits(Digits + 1);
//----
   SetIndexBuffer(5, ExtMapBuffer6); // avg
   SetIndexStyle(5, DRAW_LINE, STYLE_SOLID, 2);
   IndicatorDigits(Digits + 1);
//----   
   SetIndexBuffer(6, bbMacd);
   SetIndexBuffer(7, Upperband);        
   SetIndexBuffer(8, Lowerband);
   SetIndexBuffer(9, avg);    
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("XX");
   SetIndexLabel(0, "bbMacd");
   SetIndexLabel(1, "Upperband");
   SetIndexLabel(2, "Lowerband");
   SetIndexLabel(3, "avg");  
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom BB_MACD                                                   |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars = IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0) 
       return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;
//----
   for(int i = 0; i < limit; i++)
       bbMacd[i] = iMA(NULL, 0, FastLen, 0, MODE_EMA, PRICE_CLOSE, i) - 
                   iMA(NULL, 0, SlowLen, 0, MODE_EMA, PRICE_CLOSE, i);
//----
   for(i = 0; i < limit; i++)
     {
       avg[i] = iMAOnArray(bbMacd, 0, Length, 0, MODE_EMA, i);
       sDev = iStdDevOnArray(bbMacd, 0, Length, MODE_EMA, 0, i);  
       Upperband[i] = avg[i] + (StDv * sDev);
       Lowerband[i] = avg[i] - (StDv * sDev);
       ExtMapBuffer1[i]=bbMacd[i];     // Uptrend bbMacd
       ExtMapBuffer2[i]=bbMacd[i];     // downtrend bbMacd
       ExtMapBuffer3[i]=Upperband[i];  // Upperband
       ExtMapBuffer4[i]=Lowerband[i];  // Lowerband
       ExtMapBuffer5[i]=avg[i];     // Uptrend avg
       ExtMapBuffer6[i]=avg[i];     // downtrend avg
       //----
       if(bbMacd[i] >= bbMacd[i+1])
         ExtMapBuffer1[i] = EMPTY_VALUE;
       //----
       if(bbMacd[i] <= bbMacd[i+1])
           ExtMapBuffer2[i] = EMPTY_VALUE;
       //----
       if(avg[i] >= avg[i+1])
           ExtMapBuffer5[i] = EMPTY_VALUE;
       //----
       if(avg[i] <= avg[i+1])
           ExtMapBuffer6[i] = EMPTY_VALUE;    
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

 

thank you

avatar
13004
WHRoeder 2015.02.23 14:14 #
 
Recon004: see the holes in the plot lines
When color changes, both buffers must have the same value so the lines connect.
       if(bbMacd[i] >= bbMacd[i+1])
         ExtMapBuffer1[i] = EMPTY_VALUE;


       //----
       if(bbMacd[i] <= bbMacd[i+1])
           ExtMapBuffer2[i] = EMPTY_VALUE;


       //----
       if(avg[i] >= avg[i+1])
           ExtMapBuffer5[i] = EMPTY_VALUE;


       //----
       if(avg[i] <= avg[i+1])
           ExtMapBuffer6[i] = EMPTY_VALUE;


       if(bbMacd[i] >= bbMacd[i+1])
         ExtMapBuffer1[i] = ExtMapBuffer2[i+1] == EMPTY_VALUE // Change
                          ? ExtMapBuffer2[i]                  // Join
                          : EMPTY_VALUE;
       //----
       else                                                   // Not one must be other.
         ExtMapBuffer2[i] = ExtMapBuffer1[i+1] == EMPTY_VALUE
                          ? ExtMapBuffer1[i]
                          : EMPTY_VALUE;
       //----
       if(avg[i] >= avg[i+1])
         ExtMapBuffer5[i] = ExtMapBuffer6[i+1] == EMPTY_VALUE
                          ? ExtMapBuffer6[i]
                          : EMPTY_VALUE;
       //----
       else
         ExtMapBuffer6[i] = ExtMapBuffer5[i+1] == EMPTY_VALUE
                          ? ExtMapBuffer5[i]
                          : EMPTY_VALUE;
avatar
8
Recon004 2015.02.23 14:32 #
 
WHRoeder:
Recon004: see the holes in the plot lines
When color changes, both buffers must have the same value so the lines connect.

I don't understand ??
avatar
8
Recon004 2015.02.23 16:44 #
 
Wonderfull , not only it works perfectly but the more I understood the logic of the new code now .
A huge thank you
avatar
250
ffoorr 2015.02.23 23:08 #
 

Improved :

Attached files:
  custom_bb_line.mq4  (6.41 KB)
avatar
8
Recon004 2015.02.23 23:39 #
 
ffoorr:

Improved :

Very perfect

Thanks 

avatar
250
ffoorr 2015.02.24 18:28 #
 

Try this one recoon004, there is problems with the trigger, corrected in this one ...  sorry about that  :


Attached files:
  custom_bb_line_b.mq4  (5.97 KB)
Back to topics list  

To add comments, please log in or register