Category Trend  Published on 16/03/2023

Power Weighted Moving Average indicator

Description

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


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);
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mPowerWeightedMovingAverage.algo
  • Rating: 5
  • Installs: 574
Comments
Log in to add a comment.
No comments found.