Category Oscilators  Published on 16/03/2023

Power Weighted / Weighted delta

Description

This custom indicator, is a difference between Power Weighted Moving Average and Weighted Moving Average.

Use for Bullish sentiment when indicator result is above the zero and Bearish when indicator result is below the zero



using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
 
namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mPWWdelta : 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 / Weighted delta", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outPWWdelta { get; set; }
         
        double pw, summ, sumpw;
        private MovingAverage _wma;
 
        protected override void Initialize()
        {
            _wma = Indicators.MovingAverage(Bars.ClosePrices, inpPeriod, MovingAverageType.Weighted);
        }
 
        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;
            }
             
            outPWWdelta[i]= (sumpw!=0 ? summ/sumpw : double.NaN) - _wma.Result[i];
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

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