Moving Averages with Levels free

by kamilsz in category Trend at 04/01/2021
Description

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

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
´╗┐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;
        }
    }
}
Comments
0