Absolute Strength Averages free

by kaneida84 in category Trend at 25/04/2021
Description

Absolute strength of averages.

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 = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AbsoluteStrengthAverages : Indicator
    {
        [Parameter("Periods", DefaultValue = 14)]
        public int per { get; set; }
        [Parameter("Smoothing", DefaultValue = 4)]
        public int smt { get; set; }
        [Parameter("Mode", DefaultValue = 1)]
        public int mode { get; set; }
        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType maType { get; set; }



        [Output("Bulls", Color = Colors.DarkGreen)]
        public IndicatorDataSeries BullsSma { get; set; }
        [Output("Bears", Color = Colors.Red)]
        public IndicatorDataSeries BearsSma { get; set; }

        private IndicatorDataSeries bulls, bears;
        // private MovingAverageType avgBulls, avgBears, smtBulls, smtBears;
        private MovingAverage avgBulls, avgBears, smtBulls, smtBears;


        protected override void Initialize()
        {
            mode = mode > 2 ? 2 : mode < 1 ? 1 : mode;

            bulls = CreateDataSeries();
            bears = CreateDataSeries();

            avgBulls = Indicators.MovingAverage(bulls, per, maType);
            avgBears = Indicators.MovingAverage(bears, per, maType);
            //avgBulls = Indicators.ExponentialMovingAverage(bulls, per);
            //avgBears = Indicators.ExponentialMovingAverage(bears, per);
            smtBulls = Indicators.MovingAverage(avgBulls.Result, smt, maType);
            smtBears = Indicators.MovingAverage(avgBears.Result, smt, maType);
            //smtBulls = Indicators.ExponentialMovingAverage(avgBulls.Result, smt);
            // smtBears = Indicators.ExponentialMovingAverage(avgBears.Result, smt);
        }

        public override void Calculate(int index)
        {
            bulls[index] = mode == 1 ? 0.5 * (Math.Abs(MarketSeries.Close[index] - MarketSeries.Close[index - 1]) + (MarketSeries.Close[index] - MarketSeries.Close[index - 1])) : MarketSeries.Close[index] - MarketSeries.Low.Minimum(per);
            bears[index] = mode == 1 ? 0.5 * (Math.Abs(MarketSeries.Close[index] - MarketSeries.Close[index - 1]) - (MarketSeries.Close[index] - MarketSeries.Close[index - 1])) : MarketSeries.High.Maximum(per) - MarketSeries.Close[index];

            BullsSma[index] = smtBulls.Result[index];
            BearsSma[index] = smtBears.Result[index];


        }
    }
}
Comments
0