Category Other  Published on 19/09/2020

Standard Deviation (Super Trend)

Description


// -------------------------------------------------------------------------------------------------
//
//    This code is a cTrader Automate API example.
//    
//    All changes to this file might be lost on the next application update.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo
{
    [Indicator(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class StdTest : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 14, MinValue = 2)]
        public int Periods { get; set; }

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

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

        private MovingAverage movingAverage;

        protected override void Initialize()
        {
            movingAverage = Indicators.MovingAverage(Source, Periods, MAType);
        }

        public override void Calculate(int index)
        {
            var average = movingAverage.Result[index];

            double sum = 0;

            for (var period = 0; period < Periods; period++)
            {
                sum += Math.Pow(Source[index - period] - average, 2.0);
            }

            Result[index] = Math.Sqrt(sum / Periods);
        }
    }
}


AN
andrey.thales18

Joined on 31.08.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: StdTest.algo
  • Rating: 5
  • Installs: 1293
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
No comments found.