Simple Moving Average with Shift

Created at 15 Apr 2013, 12:07
admin's avatar

Spotware Support

Joined 30.09.2011

Simple Moving Average with Shift
15 Apr 2013, 12:07


// -------------------------------------------------------------------------------------------------
//
//    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];
        }
    }
}

 


@admin
Replies

traderfxmaster007
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. 


@traderfxmaster007