Simple Moving Average with Shift

admin's avatar

admin since: 30 Nov -0001;

  15 Apr 2013, 12:07
Simple Moving Average with Shift
// -------------------------------------------------------------------------------------------------
//
//    Simple Moving Average Shift
//    This code is a cAlgo API example.
//    
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class SMAShift : Indicator
    {
        [Parameter]
        public DataSeries Source { get; set; }

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

        [Parameter(DefaultValue = 5, MinValue = -100, MaxValue = 500)]
        public int Shift { get; set; }

        [Output("Main", Color = Colors.Blue)]
        public IndicatorDataSeries Result { get; set; }

        private SimpleMovingAverage _simpleMovingAverage;
        
        protected override void Initialize()
        {
            _simpleMovingAverage = Indicators.SimpleMovingAverage(Source, Period);
        }

        public override void Calculate(int index)
        {
            if(Shift < 0 && index < Math.Abs(Shift))
                return;

            Result[index + Shift] = _simpleMovingAverage.Result[index];
        }
    }
}
TRADERS FIRSTâ„¢

traderfxmaster007 since: 09 Jul 2019;

  16 Dec 2021, 14:45
Simple moving average shift for cbot.

Hi thank you for the simple moving average shift indicator. I would like to ask you a favor to also make a cbot sample with simple moving average shift. Thanks.