AW Moving Average free

by khoshroomahdi in category Trend at 28/06/2021
Description

 this moving include everything that a trader needs from Moving Average.

PriceType: Open,Close,High,Low, Median,Typical,Weighted

Support all moving average type.

 

 

 

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
//AcademyWave
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 AWMovingAverage : Indicator
    {

        [Parameter("Source", DefaultValue = Price.Close)]
        public Price PriceType { get; set; }

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

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

        [Parameter("Shift:", DefaultValue = 0)]
        public int Shift { get; set; }

        [Output("Main", Color = Colors.Red, Thickness = 2)]
        public IndicatorDataSeries MAResult { get; set; }


        private MovingAverage movingAverage;

        private IndicatorDataSeries dataSeries;


        protected override void Initialize()
        {
            dataSeries = CreateDataSeries();

            movingAverage = Indicators.MovingAverage(dataSeries, Period, MAType);
        }

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


            ////
            switch (PriceType)
            {
                case Price.Open:
                    dataSeries[index] = Bars.OpenPrices[index];
                    break;

                case Price.Close:
                    dataSeries[index] = Bars.ClosePrices[index];
                    break;
                case Price.High:
                    dataSeries[index] = Bars.HighPrices[index];
                    break;
                case Price.Low:
                    dataSeries[index] = Bars.LowPrices[index];
                    break;
                case Price.Median:
                    dataSeries[index] = Bars.MedianPrices[index];
                    break;
                case Price.Typical:
                    dataSeries[index] = Bars.TypicalPrices[index];
                    break;
                case Price.Weighted:
                    dataSeries[index] = Bars.WeightedPrices[index];
                    break;
                default:
                    dataSeries[index] = Bars.ClosePrices[index];
                    break;
            }
            /////////


            MAResult[index + Shift] = movingAverage.Result[index];


        }
    }

    public enum Price
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
Comments
0