Power Weighted Moving Average indicator free

by mfejza in category Trend at 25/02/2023
Description

Power Weighted Moving Average. This indicator is a hybrid of moving average series.

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
 
namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class mPowerWeightedMovingAverage : Indicator
    {
        [Parameter("Period (14)", DefaultValue = 14)]
        public int inpPeriod { get; set; }
        [Parameter("Power (2.0)", DefaultValue = 2.0)]
        public double inpPower { get; set; }
 
        [Output("Power Weighted Moving Average", LineColor = "Orange", PlotType = PlotType.Line, Thickness = 2)]
        public IndicatorDataSeries outPWMA { get; set; }
         
        double pw, summ, sumpw;
 
        protected override void Initialize()
        {
            //
        }
 
        public override void Calculate(int i)
        {
            summ = 0;
            sumpw = 0;
            for(int j=0; j<inpPeriod; j++)
            {
                pw = Math.Pow(inpPeriod-j,inpPower);
                summ += pw * (i>inpPeriod+1 ? Bars.ClosePrices[i-j] : Bars.ClosePrices[i]);
                sumpw += pw;
            }
             
            outPWMA[i]=(sumpw!=0 ? summ/sumpw : double.NaN);
        }
    }
}
Comments
0