Category Trend  Published on 08/01/2024

Price Weighted Sums Gap

Description

This custom indicator's key difference lies in the weights assigned to each element in the price array. In the narrow formula, the last weights of price members are multiplied by 1, 2, 2, and 1, respectively; in the wide formula, the last weights of price members are multiplied by 4, 3, 2, and 1, respectively.

Mathematically, these formulas represent weighted sums of the last four elements of prices as a result of a smoothed price array. The choice of weights affects the emphasis given to each element in the sum. Larger weights assign more importance to the corresponding element, making it contribute more significantly to the overall sum.

The difference in results from the two different weighted sums will evaluate both formulas to see how the choice of weights sum impacts the calculated sum. In other words, the difference between the two weighted sums of price arrays will identify the price smooth gap, called the gap.

Using this indicator for trading zones is easy; for positive output values (output result > 0), trade only long, and for negative output values (output result < 0), trade only short.

This custom indicator is developed by Iba.


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mPriceWeightedSumsGap : Indicator
    {
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }

        [Output("Price Weighted Sums Gap", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outGAP { get; set; }

        private IndicatorDataSeries _price, _pwsnarrow, _pwswide, _gap;


        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _pwsnarrow = CreateDataSeries();
            _pwswide = CreateDataSeries();
            _gap = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            switch (inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            _pwsnarrow[i] = i>3 ? (_price[i] + 2.0 * _price[i-1] + 2.0 * _price[i-2] + _price[i-3]) / 6.0 : _price[i];
            _pwswide[i] = i>10 ? (4 * _price[i] + 3 * _price[i-1] + 2 * _price[i-2] + _price[i-3]) / 10 : _price[i];
            _gap[i] = (_pwswide[i] - _pwsnarrow[i]) / Symbol.PipSize;
            
            outGAP[i] = _gap[i]; 
        }
    }

    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}


mfejza's avatar
mfejza

Joined on 25.01.2022

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