Please fix this indicator

 

Anyone please help me to fix this indicator.

When MASmooth is more than 1, the indicator will show in the left picture.

It has  a false signal at the nearly NosBar value.

If MASmooth =1 it's normal as in the right picture.

I have a limit programing.


Anyone help me to fix it.




extern int period = 14;
extern int price  = PRICE_CLOSE;
extern int ReCal = 1;
extern int MASmooth = 3;
extern int NosBar    =200;

  
double prices[], ZlagLWMA[],temp1[],temp2[],temp3[];
double lwma1[];


int init()
{

   IndicatorBuffers(5);

       SetIndexBuffer(0,lwma1);
      SetIndexBuffer(1,prices);
      SetIndexBuffer(2,temp1);
      SetIndexBuffer(3,temp2);
     SetIndexBuffer(4,temp3);

   return(0);
}



int start()
{
   double sum,sumw,weight, atr;
   int i,k,mk, limit;
  
     
   SetIndexDrawBegin(0,Bars-NosBar);

   limit=NosBar;
  
   for(i=limit; i>=0; i--) prices[i] = iMA(NULL,0,1,0,MODE_SMA,price,i);
  
   ArrayCopy(temp1,prices);
  
  for (mk=1;  mk <=ReCal ; mk++)
  {
    if (mk>1 ) ArrayCopy(temp1,temp3);
  
   for(i=limit; i>=0; i--)
   {
      for(k=0, sum=0, sumw=0; k<period && (i+k)<NosBar; k++) { weight = period-k; sumw += weight; sum += weight*temp1[i+k]; }
      if (sumw!=0)
            temp2[i] = sum/sumw;
      else  temp2[i] = 0;
   }     
  
   for(i=0; i<=limit; i++)
   {
      for(k=0, sum=0, sumw=0; k<period && (i-k)>=0; k++) { weight = period-k; sumw += weight; sum += weight*temp2[i-k]; }            
      if (sumw!=0)
            temp3[i] = sum/sumw;
      else  temp3[i] = 0;
   }
   
 }
  
 
 for(i=0; i<limit; i++) lwma1[i]=iMAOnArray(temp3,0,MASmooth,0,MODE_EMA,i);

     

   return(0);
}
 
Attached.
Files:
 

Thank you Ubzen. But if you set 5,0,2,3,200 it's still happen.

And I saw nothing change in my code.



 
Sorry just edited.
 
prothemeus:
Sorry just edited.
Thank you.
 

I changed the [extern int MASmooth = 3;] from 3 to 1 and that seemed to fix the problem. I taught maybe you had a problem compiling the default values.

You might want to contact someone at the job-site, they can spend more time than I can working on this for you.

Reason: