Category Other  Published on 25/10/2020

SmaCloseBandWidthOverlay2

Description

This is the same indicator as the previous one but with an added average of the highs and lows to smooth them out.

If you allow me an opinion, it is an opportunity to contribute to keep prices within acceptable levels of volatility instead of taking them to extremes that are not justifiable by economic fundamentals (whose evolution only the authorities know until the date of publication), forcing intervention. Feel free logically.

Thank you all


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SmaCloseBandWidthOverlay2 : Indicator
    {
        [Parameter(DefaultValue = 15)]
        public int Periods { get; set; }

        [Parameter("Volatility Periods", DefaultValue = 15)]
        public int vPeriods { get; set; }

        [Output("Result1", LineColor = "Red")]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("Result2", LineColor = "Green")]
        public IndicatorDataSeries Result2 { get; set; }

        [Output("Result3", LineColor = "Aqua")]
        public IndicatorDataSeries Result3 { get; set; }

        [Output("Result4", LineColor = "LightCoral")]
        public IndicatorDataSeries Result4 { get; set; }

        [Output("Result5", LineColor = "LightGreen")]
        public IndicatorDataSeries Result5 { get; set; }

        private SimpleMovingAverage sma;
        private double hband, lband;
        private IndicatorDataSeries hbMean, lbMean;

        protected override void Initialize()
        {
            sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, Periods);
            hbMean = CreateDataSeries();
            lbMean = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            if (Bars.ClosePrices[index] == Bars.ClosePrices.Maximum(Periods))
                hband = Bars.ClosePrices.Maximum(Periods) - sma.Result[index];

            if (Bars.ClosePrices[index] == Bars.ClosePrices.Minimum(Periods))
                lband = Bars.ClosePrices.Minimum(Periods) - sma.Result[index];

            Result1[index] = sma.Result[index] + hband;
            Result2[index] = sma.Result[index] + lband;
            Result3[index] = sma.Result[index];

            hbMean[index] = Result1[index] - Result3[index];
            lbMean[index] = Result3[index] - Result2[index];

            Result4[index] = sma.Result[index] + hbMean.Sum(vPeriods) / vPeriods;
            Result5[index] = sma.Result[index] - lbMean.Sum(vPeriods) / vPeriods;
        }
    }
}


srm_bcn's avatar
srm_bcn

Joined on 01.09.2019

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