Category Trend  Published on 04/01/2021

Moving Averages with Levels

Description

Your favourite moving averages with additional divergence (higher/lower line) based of deviation pips.


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 MovingAverageswithLevels : Indicator
    {
        [Parameter("Source")]
        public DataSeries source { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType movingAverageType { get; set; }

        [Parameter("MA Period", DefaultValue = 14)]
        public int maPeriod { get; set; }

        [Parameter("MA Dev (Pips)", DefaultValue = 1)]
        public double maDev { get; set; }

        public MovingAverage ma { get; set; }

        [Output("Main", LineColor = "Turquoise")]
        public IndicatorDataSeries main { get; set; }
        [Output("Upper", LineColor = "Turquoise", LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries upper { get; set; }
        [Output("Lower", LineColor = "Turquoise", LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries lower { get; set; }

        private double maDevPips;
        protected override void Initialize()
        {
            ma = Indicators.MovingAverage(source, maPeriod, movingAverageType);
        }

        public override void Calculate(int index)
        {
            maDevPips = Symbol.PipSize * maDev;
            main[index] = ma.Result[index];
            upper[index] = ma.Result[index] + maDevPips;
            lower[index] = ma.Result[index] - maDevPips;
        }
    }
}


KA
kamilsz

Joined on 23.12.2020

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