Custom indicator drawing vertical lines, help anyone?

 

Hello,

 not sure if I'm posting on right place...

 I have a problem with one of my favorite custom indicators.

 

This multiple MA indicator is drawing a vertical line at the current bar!  All this started to happen after the infamous ver 600 MT4 update that messed up a lot of thing for many people 

 

 

 

 

Code:"

 


...
 
 string  MAMode       = "";
 
double MA[];
double Up[];
double Dn[];
//----
double tmp[][6];
double haClose[], haOpen[], haHigh[], haLow[];
int    draw_begin, mBars, pBars, mcnt_bars; 
string short_name;
int    sUp = 0, sDn =0;   

//-----
double Price=0,AveragePrice=0,Price2=0,AveragePrice2=0;
int LastCount = 0; 
extern double Factor=10000;
extern bool UseConstantFactor=false;
extern bool ShowComment=false;
 double MA_Angle[],MA_Angle2[],ATR_[],ExtMapBuffer[],dg,pt;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- 
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
   SetIndexStyle(0,DRAW_LINE);
   if(TimeFrame == 0 || TimeFrame < Period()) TimeFrame = Period();
   SetIndexShift(0,MA_Shift*TimeFrame/Period());
   
   draw_begin=MA_Period*TimeFrame/Period();
//---- 
   switch(MA_Method)
   {
   case 1 : short_name="EMA(";  break;
   case 2 : short_name="Wilder("; break;
   case 3 : short_name="LWMA("; break;
   case 4 : short_name="SineWMA("; break;
   case 5 : short_name="TriMA("; break;
   case 6 : short_name="LSMA("; break;
   case 7 : short_name="SMMA("; break;
   case 8 : short_name="HMA("; break;
   case 9 : short_name="ZeroLagEMA("; break;
   case 10: short_name="DEMA(";  break;
   case 11: short_name="T3(";  break;
   case 12: short_name="InstTrend(";  break;
   case 13: short_name="Median(";  break;
   case 14: short_name="GeometricMean("; break;
   case 15: short_name="REMA(";  break;
   case 16: short_name="ILRS(";  break;
   case 17: short_name="IE/2(";  break;
   case 18: short_name="TriMA_gen("; break;
   case 19: short_name="VWMA("; break;
   case 20: short_name="JSmooth("; break;
   default: MA_Method=0; short_name="SMA(";
   }
   
   switch(TimeFrame)
   {
   case 1     : string TF = "M1"; break;
   case 5     : TF = "M5"; break;
   case 15    : TF = "M15"; break;
   case 30    : TF = "M30"; break;
   case 60    : TF = "H1"; break;
   case 240   : TF = "H4"; break;
   case 1440  : TF = "D1"; break;
   case 10080 : TF = "W1"; break;
   case 43200 : TF = "MN1"; break;
   default    : TF = "Current";
   } 
   
   IndicatorShortName(short_name+MA_Period+")"+" "+TF);
   SetIndexDrawBegin(0,draw_begin);
   SetIndexLabel(0,short_name+MA_Period+")"+" "+TF);
//---- 
   SetIndexBuffer(0,MA);
//---- 
   if(Color_Mode == 1)
   {
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexShift(1,MA_Shift*TimeFrame/Period());
   SetIndexShift(2,MA_Shift*TimeFrame/Period());
   SetIndexDrawBegin(1,draw_begin);
   SetIndexDrawBegin(2,draw_begin);
   SetIndexLabel(1,short_name+MA_Period+")"+" "+TF+" UpTrend");
   SetIndexLabel(2,short_name+MA_Period+")"+" "+TF+" DnTrend");
   SetIndexBuffer(1,Up);
   SetIndexBuffer(2,Dn);
   }
//----   
//-------------------------- Adjust Factor according to currency pair --------
if(!UseConstantFactor){

 if(Bars>200 && Factor==0 && (Period()==1 || Period()==5 || Period()==15 ||Period()==30 || Period()==60 || Period()==240 || Period()==1440 || Period()==10080)){
  
 for(int yy = 0; yy <Bars-5  ; yy++)
   { Price=Price+(iHigh(NULL,0,yy)-iLow(NULL,0,yy));
     Price2=Price2+(iHigh("EURUSD",0,yy)-iLow("EURUSD",0,yy));
   }
  AveragePrice=(Price/(Bars-5));
  AveragePrice2=(Price2/(Bars-5));
 //temp=ArrayRange(Price, 0);
 if (Digits==3 || Digits==2 || Digits==5 || Digits==4)
   {
   
  if (Digits==3 || Digits==2)  Factor= AveragePrice2/AveragePrice*10000;  // was 1000
   if (Digits==5 || Digits==4)  Factor= AveragePrice2/AveragePrice*10000;
 
   }
 else  Alert (Symbol()," Adjust Factor manually!! Number of digits: ",Digits, " does not match preset");

 } else { if(Factor==0) {Factor=10000; Alert ("Factor set to:"+Factor+" due to custom Period");}}
}
if (UseConstantFactor)Factor=10000;

//----   
   return(0);
}

//--------------------------
int deinit()
  {
Comment("");

//---- 
   return(0);
  }

//+------------------------------------------------------------------+
//| AllAverages_v2.5                                                 |
//+------------------------------------------------------------------+
int start()
{


   int limit, y, i, shift, cnt_bars=IndicatorCounted(); 
   double aPrice[], mMA[], mUp[], mDn[];
  
   if(TimeFrame!=Period()) mBars = iBars(NULL,TimeFrame); else mBars = Bars;   
   
   if(mBars != pBars)
   {
   ArrayResize(aPrice,mBars);
   ArrayResize(aPrice,mBars);   
   
   ArrayResize(mMA,mBars);
   

   if(MA_Method==10 || MA_Method==11 || MA_Method==20) ArrayResize(tmp,mBars);
      if(Color_Mode ==1)
      {
      ArrayResize(mUp,mBars);
      ArrayResize(mDn,mBars);
      ArrayResize(MA_Angle, mBars);
      ArrayResize(MA_Angle2, mBars);
      
      }
      if(MAPrice > 6 && MAPrice <= 10)
      {
      ArrayResize(haClose,mBars);
      ArrayResize(haOpen,mBars);
      ArrayResize(haHigh,mBars);
      ArrayResize(haLow,mBars);
      }
   pBars = mBars;
   }  
   
   if(cnt_bars<1)
   {
      for(i=1;i<=draw_begin;i++)
      { 
      MA[Bars-i]=iMA(NULL,TimeFrame,1,0,0,MAPrice,Bars-i); 
      Up[Bars-i]=EMPTY_VALUE;
      Dn[Bars-i]=EMPTY_VALUE;
      }
   mcnt_bars = 0;
   
   }
//---- 
   if(mcnt_bars > 0) mcnt_bars--;
   
   for(y=mcnt_bars;y<mBars;y++)
   {
      if(MAPrice <= 6) aPrice[y] = iMA(NULL,TimeFrame,1,0,0,MAPrice,mBars-y-1);   
      else
      if(MAPrice > 6 && MAPrice <= 10) aPrice[y] = HeikenAshi(TimeFrame,MAPrice-7,mBars-y-1);
      
      switch(MA_Method)
      {
      case 1 : mMA[y] = EMA(aPrice[y],mMA,MA_Period,y); break;
      case 2 : mMA[y] = Wilder(aPrice,mMA,MA_Period,y); break;  
      case 3 : mMA[y] = LWMA(aPrice,MA_Period,y); break;
      case 4 : mMA[y] = SineWMA(aPrice,MA_Period,y); break;
      case 5 : mMA[y] = TriMA(aPrice,MA_Period,y); break;
      case 6 : mMA[y] = LSMA(aPrice,MA_Period,y); break;
      case 7 : mMA[y] = SMMA(aPrice,mMA,MA_Period,y); break;
      case 8 : mMA[y] = HMA(aPrice,MA_Period,y); break;
      case 9 : mMA[y] = ZeroLagEMA(aPrice,mMA,MA_Period,y); break;
      case 10: mMA[y] = DEMA(0,aPrice[y],MA_Period,1,y); break;
      case 11: mMA[y] = T3(aPrice[y],MA_Period,T3Amp,y); break;
      case 12: mMA[y] = ITrend(aPrice,mMA,MA_Period,y); break;
      case 13: mMA[y] = Median(aPrice,MA_Period,y); break;
      case 14: mMA[y] = GeoMean(aPrice,MA_Period,y); break;
      case 15: mMA[y] = REMA(aPrice[y],mMA,MA_Period,0.5,y); break;
      case 16: mMA[y] = ILRS(aPrice,MA_Period,y); break;
      case 17: mMA[y] = IE2(aPrice,MA_Period,y); break;
      case 18: mMA[y] = TriMA_gen(aPrice,MA_Period,y); break;
      case 19: mMA[y] = VWMA(aPrice,MA_Period,y); break;
      case 20: mMA[y] = JSmooth(aPrice[y],MA_Period,1,y); break;
      default: mMA[y] = SMA(aPrice,MA_Period,y); break;
      }
   
      if(Color_Mode == 1)
      {
//========== MA Angle Cycle ===========================================

 
 MA_Angle[y]=MA_Angle_Angletest( TimeFrame,MA_Period,MAMode,MAPrice,y, MACount1_start, MACount1_stop,  Factor,mMA);  
// MA_Angle[i]=MA_Angle_Angletest( 0,50,0,0,y, 1, 3,  10000);  
//  MA_Angle[y]=mMA[y]-mMA[y+1];
  MA_Angle2[y]=MA_Angle_Angletest( TimeFrame,MA_Period,MAMode,MAPrice,y, MACount2_start, MACount2_stop,  Factor,mMA); 
//==========
 //Comment( "MA_Angle[y]  "+MA_Angle[y]+"  Factor  "+Factor+"  Y: "+y);  
    
      // if(mMA[y] > mMA[y-1]) 
       if (MA_Angle[y]>Min_MA_Angle && (Min_MA_Angle2==-1 || MA_Angle2[y]>Min_MA_Angle2)) 
         
         {mUp[y] = mMA[y]; mDn[y] = EMPTY_VALUE;}  // Draw Blue
         
         
         else
         
        // if(mMA[y] < mMA[y-1]) 
         if (MA_Angle[y]<=-Min_MA_Angle && (Min_MA_Angle2==-1 || MA_Angle2[y]<=-Min_MA_Angle2)) 
         
         {mUp[y] = EMPTY_VALUE; mDn[y] = mMA[y];}  // Draw Red
         
         else
         {mUp[y] = EMPTY_VALUE; mDn[y] = EMPTY_VALUE;}
      
         if(Sound_Mode == 1 && y == mBars-1)
         {
            if(((Sound_Shift > 0 && sUp == 0) || Sound_Shift == 0) && mMA[y-Sound_Shift] > mMA[y-1-Sound_Shift] && mMA[y-1-Sound_Shift] <= mMA[y-2-Sound_Shift]) 
            {
            if(Sound_Shift > 0) {sUp = 1; sDn = 0;}
            PlaySound(Buy_Sound);
            }
            else
            if(((Sound_Shift > 0 && sDn == 0) || Sound_Shift == 0) && mMA[y-Sound_Shift] < mMA[y-1-Sound_Shift] && mMA[y-1-Sound_Shift] >= mMA[y-2-Sound_Shift]) 
            {
            if(Sound_Shift > 0) {sUp = 0; sDn = 1;}
            PlaySound(Sell_Sound);
            }
         }
      }
   
      if(TimeFrame == Period()) 
      {
      MA[mBars-y-1] = mMA[y];
         if(Color_Mode == 1)
         {  
         Up[mBars-y-1] = mUp[y];
         Dn[mBars-y-1] = mDn[y];
         }
      }
      
   }
   mcnt_bars = mBars-1;

   if(TimeFrame > Period())
   { 
      if(cnt_bars>0) cnt_bars--;
      limit = Bars-cnt_bars+TimeFrame/Period()-1;
      
      for(shift=0,y=0;shift<limit;shift++)
      {
      if (Time[shift] < iTime(NULL,TimeFrame,y)) y++; 
      MA[shift] = mMA[mBars-y-1];
         if(Color_Mode == 1)
         {
         Up[shift] = mUp[mBars-y-1];
         Dn[shift] = mDn[mBars-y-1];
         }
      }
   }

//---- 
   return(0);
}
 
// MA_Method=0: SMA - Simple Moving Average
double SMA(double array[],int per,int bar)
{
   double Sum = 0;
   for(int i = 0;i < per;i++) Sum += array[bar-i];
   
   return(Sum/per);
}                
// MA_Method=1: EMA - Exponential Moving Average
double EMA(double price,double array[],int per,int bar)
{
   if(bar == 2) double ema = price;
   else 
   if(bar > 2) ema = array[bar-1] + 2.0/(1+per)*(price - array[bar-1]); 
   
   return(ema);
}
// MA_Method=2: Wilder - Wilder Exponential Moving Average
double Wilder(double array1[],double array2[],int per,int bar)
{
   if(bar == per) double wilder = SMA(array1,per,bar);
   else 
   if(bar > per) wilder = array2[bar-1] + (array1[bar] - array2[bar-1])/per; 
   
   return(wilder);
}
// MA_Method=3: LWMA - Linear Weighted Moving Average 
double LWMA(double array[],int per,int bar)
{
   double Sum = 0;
   double Weight = 0;
   
      for(int i = 0;i < per;i++)
      { 
      Weight+= (per - i);
      Sum += array[bar-i]*(per - i);
      }
   if(Weight>0) double lwma = Sum/Weight;
   else lwma = 0; 
   return(lwma);
} 
// MA_Method=4: SineWMA - Sine Weighted Moving Average
double SineWMA(double array[],int per,int bar)
{
   double pi = 3.1415926535;
   double Sum = 0;
   double Weight = 0;
  
      for(int i = 0;i < per-1;i++)
      { 
      Weight+= MathSin(pi*(i+1)/(per+1));
      Sum += array[bar-i]*MathSin(pi*(i+1)/(per+1)); 
      }
   if(Weight>0) double swma = Sum/Weight;
   else swma = 0; 
   return(swma);
}
// MA_Method=5: TriMA - Triangular Moving Average
double TriMA(double array[],int per,int bar)
{
   double sma;
   int len = MathCeil((per+1)*0.5);
   
   double sum=0;
   for(int i = 0;i < len;i++) 
   {
   sma = SMA(array,len,bar-i);
   sum += sma;
   } 
   double trima = sum/len;
   
   return(trima);
}
// MA_Method=6: LSMA - Least Square Moving Average (or EPMA, Linear Regression Line)
double LSMA(double array[],int per,int bar)
{   
   double Sum=0;
   for(int i=per; i>=1; i--) Sum += (i-(per+1)/3.0)*array[bar-per+i];
   double lsma = Sum*6/(per*(per+1));
   return(lsma);
}
// MA_Method=7: SMMA - Smoothed Moving Average
double SMMA(double array1[],double array2[],int per,int bar)
{
   if(bar == per) double smma = SMA(array1,per,bar);
   else 
   if(bar > per)
   {
   double Sum = 0;
   for(int i = 0;i < per;i++) Sum += array1[bar-i-1];
   smma = (Sum - array2[bar-1] + array1[bar])/per;
   }
   return(smma);
}                
// MA_Method=8: HMA - Hull Moving Average by Alan Hull
double HMA(double array[],int per,int bar)
{
   double tmp[];
   int len =  MathSqrt(per);
   ArrayResize(tmp,len);
   
   if(bar == per) double hma = array[bar]; 
   else
   if(bar > per)
   {
   for(int i = 0; i < len;i++) tmp[len-i-1] = 2*LWMA(array,per/2,bar-i) - LWMA(array,per,bar-i);  
   hma = LWMA(tmp,len,len-1); 
   }  
 
   return(hma);
}
// MA_Method=9: ZeroLagEMA - Zero-Lag Exponential Moving Average
double ZeroLagEMA(double array1[],double array2[],int per,int bar)
{
   double alfa = 2.0/(1+per); 
   int lag = 0.5*(per - 1); 
   
   if(bar == lag) double zema = array1[bar];
   else 
   if(bar > lag) zema = alfa*(2*array1[bar] - array1[bar-lag]) + (1-alfa)*array2[bar-1];
   
   return(zema);
}
// MA_Method=10: DEMA - Double Exponential Moving Average by Patrick Mulloy
double DEMA(int num,double price,int per,double v,int bar)
{
   if(bar == 2) {double dema = price; tmp[bar][num] = dema; tmp[bar][num+1] = dema;}
   else 
   if(bar > 2) 
   {
   tmp[bar][num] = tmp[bar-1][num] + 2.0/(1+per)*(price - tmp[bar-1][num]); 
   tmp[bar][num+1] = tmp[bar-1][num+1] + 2.0/(1+per)*(tmp[bar][num] - tmp[bar-1][num+1]); 
   dema = (1+v)*tmp[bar][num] - v*tmp[bar][num+1];
   }
   return(dema);
}
// MA_Method=11: T3 by T.Tillson
double T3(double price,int per,double v,int bar)
{
   if(bar == 2) 
   {
   double T3 = price; 
   for(int k=0;k<=5;k++) tmp[bar][k] = T3;
   }
   else 
   if(bar > 2) 
   {
   double dema1 = DEMA(0,price,per,v,bar); 
   double dema2 = DEMA(2,dema1,per,v,bar); 
   T3 = DEMA(4,dema2,per,v,bar);
   }
   return(T3);
}
// MA_Method=12: ITrend - Instantaneous Trendline by J.Ehlers
double ITrend(double price[],double array[],int per,int bar)
{
   double alfa = 2.0/(per+1);
   if(bar > 7)
   double it = (alfa - 0.25*alfa*alfa)*price[bar]+ 0.5*alfa*alfa*price[bar-1]-(alfa - 0.75*alfa*alfa)*price[bar-2]+
   2*(1-alfa)*array[bar-1] - (1-alfa)*(1-alfa)*array[bar-2];
   else
   it = (price[bar] + 2*price[bar-1]+ price[bar-2])/4;
   
   return(it);
}
// MA_Method=13: Median - Moving Median
double Median(double price[],int per,int bar)
{
   double array[];
   ArrayResize(array,per);
   
   for(int i = 0; i < per;i++) array[i] = price[bar-i];
   ArraySort(array);
   
   int num = MathRound((per-1)/2); 
   if(MathMod(per,2)>0) double median = array[num]; else median = 0.5*(array[num]+array[num+1]);
   
   return(median); 
}
// MA_Method=14: GeoMean - Geometric Mean
double GeoMean(double price[],int per,int bar)
{
   double gmean = MathPow(price[bar],1.0/per); 
   for(int i = 1; i < per;i++) gmean *= MathPow(price[bar-i],1.0/per); 
   
   return(gmean);
}
// MA_Method=15: REMA - Regularized EMA by Chris Satchwell 
double REMA(double price,double array[],int per,double lambda,int bar)
{
   double alpha =  2.0/(per + 1);
   if(bar <= 3) double rema = price;
   else 
   if(bar > 3) 
   rema = (array[bar-1]*(1+2*lambda) + alpha*(price - array[bar-1]) - lambda*array[bar-2])/(1+lambda); 
   
   return(rema);
}
// MA_Method=16: ILRS - Integral of Linear Regression Slope 
double ILRS(double price[],int per,int bar)
{
   double sum = per*(per-1)*0.5;
   double sum2 = (per-1)*per*(2*per-1)/6.0;
     
   double sum1 = 0;
   double sumy = 0;
      for(int i=0;i<per;i++)
      { 
      sum1 += i*price[bar-i];
      sumy += price[bar-i];
      }
   double num1 = per*sum1 - sum*sumy;
   double num2 = sum*sum - per*sum2;
   
   if(num2 != 0) double slope = num1/num2; else slope = 0; 
   double ilrs = slope + SMA(price,per,bar);
   
   return(ilrs);
}
// MA_Method=17: IE/2 - Combination of LSMA and ILRS 
double IE2(double price[],int per,int bar)
{
   double ie = 0.5*(ILRS(price,per,bar) + LSMA(price,per,bar));
      
   return(ie); 
}
 
// MA_Method=18: TriMAgen - Triangular Moving Average Generalized by J.Ehlers
double TriMA_gen(double array[],int per,int bar)
{
   int len1 = MathFloor((per+1)*0.5);
   int len2 = MathCeil((per+1)*0.5);
   double sum=0;
   for(int i = 0;i < len2;i++) sum += SMA(array,len1,bar-i);
   double trimagen = sum/len2;
   
   return(trimagen);
}
 
// MA_Method=19: VWMA - Volume Weighted Moving Average 
double VWMA(double array[],int per,int bar)
{
   double Sum = 0;
   double Weight = 0;
   
      for(int i = 0;i < per;i++)
      { 
      Weight+= Volume[mBars-bar-1+i];
      Sum += array[bar-i]*Volume[mBars-bar-1+i];
      }
   if(Weight>0) double vwma = Sum/Weight;
   else vwma = 0; 
   return(vwma);
} 
 
// MA_Method=20: JSmooth - Smoothing by Mark Jurik
double JSmooth(double price,int per,double pow,int bar)
{
   double beta = 0.45*(per-1)/(0.45*(per-1)+2);
    double alpha = MathPow(beta,pow);
    if(bar == 2) {tmp[bar][4] = price; tmp[bar][0] = price; tmp[bar][2] = price;}
    else 
   if(bar > 2) 
   {
    tmp[bar][0] = (1-alpha)*price + alpha*tmp[bar-1][0];
    tmp[bar][1] = (price - tmp[bar][0])*(1-beta) + beta*tmp[bar-1][1];
    tmp[bar][2] = tmp[bar][0] + tmp[bar][1];
    tmp[bar][3] = (tmp[bar][2] - tmp[bar-1][4])*MathPow((1-alpha),2) + MathPow(alpha,2)*tmp[bar-1][3];
    tmp[bar][4] = tmp[bar-1][4] + tmp[bar][3]; 
   }
   return(tmp[bar][4]);
}
 
// HeikenAshi MAPrice:  7 - Close,8 - Open,9 - High,10 - Low 
double HeikenAshi(int tf,int price,int bar)
{ 
   if(bar == iBars(NULL,TimeFrame)- 1) 
   {
   haClose[bar] = iClose(NULL,tf,bar);
   haOpen[bar]  = iOpen(NULL,tf,bar);
   haHigh[bar]  = iHigh(NULL,tf,bar);
   haLow[bar]   = iLow(NULL,tf,bar);
   }
   else
   {
   haClose[bar] = (iOpen(NULL,tf,bar)+iHigh(NULL,tf,bar)+iLow(NULL,tf,bar)+iClose(NULL,tf,bar))/4;
   haOpen[bar]  = (haOpen[bar+1]+haClose[bar+1])/2;
   haHigh[bar]  = MathMax(iHigh(NULL,tf,bar),MathMax(haOpen[bar], haClose[bar]));
   haLow[bar]   = MathMin(iLow(NULL,tf,bar),MathMin(haOpen[bar], haClose[bar]));
   }
   
   switch(price)
   {
   case 0: return(haClose[bar]);break;
   case 1: return(haOpen[bar]);break;
   case 2: return(haHigh[bar]);break;
   case 3: return(haLow[bar]);break;
   }
}

//=========================== Angle Function ================================   
double MA_Angle_Angletest( int timeFrame,int maPeriod,int maMode,int maAppliedPrice, int I , int MACount_start, int MACount_stop, int factor,double array[])   
    { 
    double  MA_angle=0, ma_dif=0, atr=0;

   //  for(y=mcnt_bars;y<mBars;y++)
 //   for ( int xx=I+MACount_start; xx<I+MACount_stop; xx ++)     
 for ( int xx=I-MACount_start; xx>I-MACount_stop; xx --)                                                 //  Loop counting x-bars for the sum of macd differences
      { 
     //   ma_dif      = ma_dif + iMA(NULL,timeFrame,maPeriod,0,maMode, maAppliedPrice,xx)-iMA(NULL,timeFrame,maPeriod,0,maMode, maAppliedPrice,xx+1); 
    
       ma_dif      = ma_dif + (array[xx+1]-array[xx]);
      // ma_dif      = array[xx-1];
       }  
  //  if (atr!=0)     atr=1/(atr/(MACount_stop-MACount_start));
 MA_angle =((ma_dif  /(MACount_stop-MACount_start))*factor);///atr; //*atr  ; //
 
         
          if(ShowComment)Comment( " ALL_MA_COLOR --/  Factor  "+factor+ " / MA_angle  "+MA_angle);

 
   return(MA_angle); 
   }
 

I haven't read your code totally I was just looking for the use of  'future' bars ..[bar-??] for calculation that aren't defined:

..
      for(i=1;i<=draw_begin;i++)
      { 
      MA[Bars-i]=iMA(NULL,TimeFrame,1,0,0,MAPrice,Bars-i); 
      Up[Bars-i]=EMPTY_VALUE;
      Dn[Bars-i]=EMPTY_VALUE;
..

Try to search from there.

Be aware that this (calculation of a value with a 'future-bar') can produce the typical 're-painting' indicators!

Gooly

 
To avoid re-painting, should we have some sort comparison or something like that?
 

your code cannot be compiled

 

how do you think that someone is gonna spend his time to fix so many error before trying to get to the bottom of your problem  

 
deysmacro:
To avoid re-painting, should we have some sort comparison or something like that?

Make sure that prev. calculated bars aren't recalculated with new Bars:

1) Start checking whether (s.a.) Value1[Bar] = func( Value2[Bar-x] ).

2) Check whether the loop is going from now to the beginning of the chart (dangerous) or the opposite way (saver).

3) Place an arrow at the indicator-price of a time(!) defined bar (if Time[x] == D'...') whenever the indicator-value of this bar is calculated: is it always at the same place or is it 'moving' and you see many arrows stacked at the same bar?

Sometimes it is hidden pretty well in the code either by purpose or by unthoughtfulness.

Gooly
 

..@qjol   sorry I could not fit all the code in here, so if you compile this it wont work. The code itself gives no errors.

 

If anyone is interested in he indicator I have attached a copy.

 

I think this is very handy multi-MA indicator for automated systems. For emable T3 (code:11) gives very smooth signals that are easy to incorporate into an EA strategy! 

Files:
 

@gooly  thank you very much for your advice!

 

Unfortunately my programming skills and understanding of the syntax is very rudimentary, and I don't think I can understand the code enough to solve the problem. 

 
luckyluke72:

@gooly  thank you very much for your advice!

 

Unfortunately my programming skills and understanding of the syntax is very rudimentary, and I don't think I can understand the code enough to solve the problem. 


Just look at ITrend(..):

double ITrend(double price[],double array[],int per,int bar)
{
   double alfa = 2.0/(per+1);
   if(bar > 7)
   double it = (alfa - 0.25*alfa*alfa)*price[bar]+ 0.5*alfa*alfa*price[bar-1]-(alfa - 0.75*alfa*alfa)*price[bar-2]+
   2*(1-alfa)*array[bar-1] - (1-alfa)*(1-alfa)*array[bar-2];
   else
   it = (price[bar] + 2*price[bar-1]+ price[bar-2])/4;
   
   return(it);
}


For the e.g.  1-min Bar at 12:30 you the values of the bars 12:31 and 12:32,

But this at least seams to be easy to repair: replace [bar] => [bar+2], [bar-1] => [bar+1] and [bar-2] => [bar] :

// MA_Method=12: ITrend - Instantaneous Trendline by J.Ehlers
double ITrend(double price[],double array[],int per,int bar)
{
   double alfa = 2.0/(per+1);
   /* original
      if(bar > 7)
         double it = (alfa - 0.25*alfa*alfa)*price[bar]+ 0.5*alfa*alfa*price[bar-1]-(alfa - 0.75*alfa*alfa)*price[bar-2]+
                     2*(1-alfa)*array[bar-1] - (1-alfa)*(1-alfa)*array[bar-2];
      else
         it = (price[bar] + 2*price[bar-1]+ price[bar-2])/4;
   */
   if(bar > 7)
      double it = (alfa - 0.25*alfa*alfa)*price[bar+2]+ 0.5*alfa*alfa*price[bar+1]-(alfa - 0.75*alfa*alfa)*price[bar]+
                  2*(1-alfa)*array[bar+1] - (1-alfa)*(1-alfa)*array[bar];
   else
      it = (price[bar+2] + 2*price[bar+1]+ price[bar])/4;
   
   return(it);
}

Without testing (!) I think it should be the same but now you'll get the vertical lines at the first bars of the chart (way back in the past) or you start calc at Bars - 3.

Gooly

 

Thank you gooly,

 

seems like your fix did away with repainting! :) 

 

I attached the fixed version in case some finds this indicator useful.

 

I like trading it with 25-50 tick volume bars (using custom script to convert time chart to volume) as well as using it with EAs, it gives very clean and clear signals due to the exponential smoothing

Files:
 

..actually the repainting on the recent bar is still there... :(  

 

I changed:

 

 /*  if(bar > 7)  // This will repaint!  replaced by code below
   double it = (alfa - 0.25*alfa*alfa)*price[bar]+ 0.5*alfa*alfa*price[bar-1]-(alfa - 0.75*alfa*alfa)*price[bar-2]+
   2*(1-alfa)*array[bar-1] - (1-alfa)*(1-alfa)*array[bar-2];
   else
   it = (price[bar] + 2*price[bar-1]+ price[bar-2])/4;
   
   return(it);
   */
 //-------------  
   if(bar > 7)
      double it = (alfa - 0.25*alfa*alfa)*price[bar+2]+ 0.5*alfa*alfa*price[bar+1]-(alfa - 0.75*alfa*alfa)*price[bar]+
                  2*(1-alfa)*array[bar+1] - (1-alfa)*(1-alfa)*array[bar];
   else
      it = (price[bar+2] + 2*price[bar+1]+ price[bar])/4;
   
   return(it);
 

To be clear if the value of the last, most recent bar changes which hasn't closed yet - that is not re-painting!

That's why one either trades on the open of a new bar or you wait until the bar is 'close to close'  e.g. 5min-bar and 90% = 30sec left to finish.

Gooly
Reason: