In a 15-day linearly-weighted moving average,
todays closing price is multiplied by 15, yesterdays by 14, and so on until day 1 in the periods range is reached. These results are then added together and divided by the sum of the multipliers (15 + 14 + 13 + + 3 + 2 + 1 = 120).
The linearly weighted moving average was one of the first responses to placing a greater importance on recent data. The popularity of this moving average has been diminished by the exponential moving average, but none the less it still proves to be very useful.
From : investopedia.
Ive done the coding only.
see if it could help u in improving ur systems.
previously i have uploaded this on other websites.
now here to benifit all of us
/************/
function LWMA( P, per )
{
s=0;
pa=0;
for( i = 0; i < per; i++ )
{
s=s+(Ref(P,-i)*(per-i));
pa=pa+(per-i);
}
return (s/pa);
}
P = ParamField("Price field");
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot(LWMA( P, Periods ), "LWMA("+Periods +")", ParamColor( "LWMA Color", colorCycle ), ParamStyle("LWMA Style") );
/*************/
todays closing price is multiplied by 15, yesterdays by 14, and so on until day 1 in the periods range is reached. These results are then added together and divided by the sum of the multipliers (15 + 14 + 13 + + 3 + 2 + 1 = 120).
The linearly weighted moving average was one of the first responses to placing a greater importance on recent data. The popularity of this moving average has been diminished by the exponential moving average, but none the less it still proves to be very useful.
From : investopedia.
Ive done the coding only.
see if it could help u in improving ur systems.
previously i have uploaded this on other websites.
now here to benifit all of us
/************/
function LWMA( P, per )
{
s=0;
pa=0;
for( i = 0; i < per; i++ )
{
s=s+(Ref(P,-i)*(per-i));
pa=pa+(per-i);
}
return (s/pa);
}
P = ParamField("Price field");
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot(LWMA( P, Periods ), "LWMA("+Periods +")", ParamColor( "LWMA Color", colorCycle ), ParamStyle("LWMA Style") );
/*************/