If you need to calculate the linear weighted moving average of a simple moving average :

Before start :

Code:
double ma[999];

int kl;

int weightsum=0;
int k=0;
double firstValue;
double ExtMapBuffer[999];
Inside start :

Code:
for(kl=0;kl<=998;kl++){
      ma[kl]=iMA(NULL,0,MAPeriod,0,MODE_SMA,PRICE_CLOSE,kl);
   }
   
   double sum=0.0,lsum=0.0;
   double price2;
   int    i5,weight=0,pos=999;

   if(pos<LWMAPeriod) pos=LWMAPeriod;
   for(i5=1;i5<=LWMAPeriod;i5++,pos--)
     {
      price2=ma[pos];
      sum+=price2*i5;
      lsum+=price2;
      weight+=i5;
     }

   pos++;
   i5=pos+LWMAPeriod;
   while(pos>=0)
     {
      ExtMapBuffer[pos]=sum/weight;
      if(pos==0) break;
      pos--;
      i5--;
      price2=ma[pos];
      sum=sum-lsum+price2*LWMAPeriod;
      lsum-=ma[i5];
      lsum+=price2;
     }
Last lwma value : ExtMapBuffer[0]

It's away to get rid of imaonarray into an EA.