Category Trend  Published on 12/10/2020

Partial Moving Average

Description

 

Responding to forum request: https://ctrader.com/forum/indicator-support/24951

This shows only a certain number of bars of the moving average.
Let us know if you find any bugs.

If you need some dev work, you can contact us via development@fxtradersystems.com or via fxtradersystems.com/support/


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

        [Parameter("Periods for MA", DefaultValue = 10, MinValue = 1)]
        public int Periods { get; set; }

        [Parameter("Periods Shown", DefaultValue = 55, MinValue = 1)]
        public int PeriodsShown { get; set; }

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

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

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

        public override void Calculate(int index)
        {
            if (index <= PeriodsShown)
            {
                Result[index] = movingAverage.Result[index];
                return;
            }
            else
            {
                Result[index] = movingAverage.Result[index];
                Result[0] = double.NaN;
                Result[index - PeriodsShown] = double.NaN;
            }
        }
    }
}


fxtradersystems's avatar
fxtradersystems

Joined on 10.09.2020

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