Partial Moving Average free

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/

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 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;
            }
        }
    }
}
Comments
0