Indicator arrows messy

Back to topics list To post a new topic, please log in or register
avatar
43
asuralm 2015.06.29 14:46
 

Hi 

 

I met a problem when writing indicators. The indicator works fine in normal conditions but if there are some new data loading, the indicator markers and zigzags becomes messy like show in the following image. 

https://charts.mql5.com/8/221/usdchf-m15-forex-capital-markets.png

 

Any help please?

 

The code of the lower indicator shows in the image is here

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

//| Custom indicator initialization function                         |

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

int OnInit()

{

//--- indicator buffers mapping

   IndicatorBuffers(6);

   SetIndexBuffer(0, BufSto1);

   SetIndexBuffer(1, BufSto2);

   

   SetIndexLabel(0, "FastTermSto");   

   SetIndexLabel(1, "SlowTermSto");

   

   SetIndexBuffer(2, BufStoMark1);

   SetIndexBuffer(3, BufStoMark2);   

   

   SetIndexLabel(2, "FastStoMark");   

   SetIndexLabel(3, "SlowStoMark");

   

   SetIndexStyle(2, DRAW_ARROW,SYMBOL_CHECKSIGN);   

   SetIndexStyle(3, DRAW_ARROW,SYMBOL_CHECKSIGN);   

   

   SetIndexBuffer(4, BufWPRUp);

   SetIndexLabel(4, "WPRUp");

   SetIndexStyle(4, DRAW_LINE, STYLE_DASH);

   

   SetIndexBuffer(5, BufWPRDn);

   SetIndexLabel(5, "WPRDn");

   SetIndexStyle(5, DRAW_LINE, STYLE_DASH);

   

   Print("Bars=", Bars);

   SetIndexDrawBegin(0, ex_nK2+ex_nK1+1);

   SetIndexDrawBegin(1, ex_nK2+ex_nK1+1);

   SetIndexDrawBegin(2, ex_nK2+ex_nK1+1);

   SetIndexDrawBegin(3, ex_nK2+ex_nK1+1);

   SetIndexDrawBegin(4, ex_nK2+ex_nK1+1);

   SetIndexDrawBegin(5, ex_nK2+ex_nK1+1);

//---

   return(INIT_SUCCEEDED);

}

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

{

//---

   

   int nBeginInx = Bars-1-ex_nK2-ex_nK1;

   if (prev_calculated > 0 )

   {

      //nBeginInx = 50;

   }

   for (int i=nBeginInx; i>=0; i--)

   {

      int nIx1 = iBarShift(NULL, ex_nTimeFrame1, Time[i]);

      int nIx2 = iBarShift(NULL, ex_nTimeFrame2, Time[i]);

      BufSto1[i] = iStochastic(NULL, ex_nTimeFrame1, ex_nK1, ex_nDPeriod, ex_nSlow, MODE_SMA, 0, 0, nIx1);

      BufSto2[i] = iStochastic(NULL, ex_nTimeFrame2, ex_nK2, ex_nDPeriod, ex_nSlow, MODE_SMA, 0, 0, nIx2);      

      

      if (BufSto1[i] > ex_nOverbought || BufSto1[i] < ex_nOversold)

      {

         BufStoMark1[i] = BufSto1[i];

      }      

      

      if (BufSto2[i] > ex_nOverbought || BufSto2[i] < ex_nOversold)

      {

         BufStoMark2[i] = BufSto2[i];

      }

      

      int nWPRIx = iBarShift(NULL, ex_nWPRTimeFrame, Time[i]);

      double dWPR = iWPR(NULL, ex_nWPRTimeFrame, ex_nWPR, nWPRIx)+100;

      if (dWPR >= 50)

      {

         BufWPRUp[i] = dWPR;

      } else {

         BufWPRDn[i] = dWPR;

      }
                            
   }

//--- return value of prev_calculated for next call

   return(rates_total);

}

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

 

avatar
12984
WHRoeder 2015.06.29 16:51 #
 
      if (BufSto1[i] > ex_nOverbought || BufSto1[i] < ex_nOversold)
      {
         BufStoMark1[i] = BufSto1[i];
      }
else BufStoMark1[i] = EMPTY_VALUE;
Likewise all others
avatar
43
asuralm 2015.06.30 03:42 #
 
WHRoeder:
Likewise all others
Thanks, problem solved.
Back to topics list  

To add comments, please log in or register