Weighted Moving Average

In the ESPL Help documentation, select the section User Defined Study, for more information.  The example shell contained in that section of the documentation is an Exponential Average, and I have edited it to show a weighted average.

procedure WeightAverage;
var
  i,k,ave1,denom: integer;
  sum: real;
begin
  SetUser(ePosition,eChart); {plot on the chart}
  SetUser(ePlot1,True);      {plot 1st array value}
  SetUser(eShow1,True);      {Show 1st array value}
  Ave1:=GetUser(eParm1);     {read parameter from form}
  denom:=0;
  for k:=1 to ave1 do denom:=denom+k;    {divisor}
  for i:= BarBeginLeft to BarEnd do
  begin
    sum:=0;
    for k:=i downto i-Ave1 do sum:=sum+Last(k)*(k-i+Ave1);
    SetUser(1,sum/denom,i);              {value to plot}
  end;
end;

{Main program}
begin
  if ESPL=51 then WeightAverage;
end;

To use, display your chart, click on the Studies button, and click small button 1 at the bottom of study list.