Category Oscilators  Published on 17/12/2021

Absolute Strength Advanced

Description

Original indicator posted at https://ctrader.com/algos/indicators/show/1936

=========================================================================

I changed Bull & Bear line to include calculations according to CCI (Mode 3).
Mode 4 calculates the average of all 1, 2 & 3 and automatically normalises the results.
Mode 5 calculated average for 1 & 2.
I personally recommend mode 4 which I find better than the rest.

 


/*
=========================================================================
=========================================================================
Original indicator posted at https://ctrader.com/algos/indicators/show/1936


 Modifications done by: Jan // https://ctrader.com/users/profile/23066
 Telegram:  @Fibonacci2011 
=========================================================================
I changed Bull & Bear line to include calculations according to CCI (Mode 3).
Mode 4 calculates the average of all 1, 2 & 3 and automatically normalises the results.
Mode 5 calculated average for 1 & 2.
I personally recommend mode 4 which I find better than the rest.


Additional modifications:

2021/12/10  Changed Normalization formula to  Norm = (xi – min(x)) / (max(x) – min(x)) * 100
            

*/

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 AbsoluteStrengthAdvanced : Indicator
    {
        [Parameter("Period", Group = " --- Period ---", DefaultValue = 14)]
        public int Period { get; set; }

        [Parameter("Smoothing", Group = " --- Smoothing ---", DefaultValue = 4)]
        public int Smoothing { get; set; }

        [Parameter("Mode, 1=RSI, 2=Stoch, 3=CCI, 4=All Average (Normal.), 5=1&2 Average", Group = " --- Mode --- (1, 2, 3, 4 & 5) ---", DefaultValue = 4, MaxValue = 5, MinValue = 1)]
        public int mode { get; set; }

        [Parameter("Use Normalization (for 1,2, or3)", Group = " --- Normalization ---", DefaultValue = true)]
        public bool UseNorm { get; set; }

        [Output("Bulls", LineColor = "Lime", Thickness = 2)]
        public IndicatorDataSeries BullsSma { get; set; }

        [Output("Bears", LineColor = "Red", Thickness = 2)]
        public IndicatorDataSeries BearsSma { get; set; }

        [Output("Histogram Up", PlotType = PlotType.Histogram, Color = Colors.DeepSkyBlue)]
        public IndicatorDataSeries HistogramUp { get; set; }

        [Output("Histogram Down", PlotType = PlotType.Histogram, Color = Colors.Red)]
        public IndicatorDataSeries HistogramDown { get; set; }


        private IndicatorDataSeries bulls, bears;
        private ExponentialMovingAverage avgBulls, avgBears, smtBulls, smtBears;

        private SimpleMovingAverage SMA;
        private IndicatorDataSeries MeanDeviation;

        private IndicatorDataSeries BullMode1;
        private IndicatorDataSeries BullMode2;
        private IndicatorDataSeries BullMode3;
        private IndicatorDataSeries BullMode4;

        private IndicatorDataSeries _BullMode1;
        private IndicatorDataSeries _BullMode2;
        private IndicatorDataSeries _BullMode3;
        private IndicatorDataSeries _BullMode4;
        private IndicatorDataSeries _BullMode5;

        private IndicatorDataSeries BearMode1;
        private IndicatorDataSeries BearMode2;
        private IndicatorDataSeries BearMode3;
        private IndicatorDataSeries BearMode4;

        private IndicatorDataSeries _BearMode1;
        private IndicatorDataSeries _BearMode2;
        private IndicatorDataSeries _BearMode3;
        private IndicatorDataSeries _BearMode4;
        private IndicatorDataSeries _BearMode5;

        public IndicatorDataSeries BullMode1A;

        int lastindex = 0;
        double factor;


        protected override void Initialize()
        {

            if (mode == 4)
            {
                ChartObjects.DrawText("Norm1", "!!! NOTICE !!!  Mode 4 used - Values Normalized: ", StaticPosition.TopLeft, Colors.Red);
            }

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

            MeanDeviation = CreateDataSeries();

            SMA = Indicators.SimpleMovingAverage(Bars.TypicalPrices, Period);

            avgBulls = Indicators.ExponentialMovingAverage(bulls, Period);
            avgBears = Indicators.ExponentialMovingAverage(bears, Period);

            smtBulls = Indicators.ExponentialMovingAverage(avgBulls.Result, Smoothing);
            smtBears = Indicators.ExponentialMovingAverage(avgBears.Result, Smoothing);

            BullMode1 = CreateDataSeries();
            BullMode2 = CreateDataSeries();
            BullMode3 = CreateDataSeries();
            BullMode4 = CreateDataSeries();

            _BullMode1 = CreateDataSeries();
            _BullMode2 = CreateDataSeries();
            _BullMode3 = CreateDataSeries();
            _BullMode4 = CreateDataSeries();
            _BullMode5 = CreateDataSeries();

            BearMode1 = CreateDataSeries();
            BearMode2 = CreateDataSeries();
            BearMode3 = CreateDataSeries();
            BearMode4 = CreateDataSeries();

            _BearMode1 = CreateDataSeries();
            _BearMode2 = CreateDataSeries();
            _BearMode3 = CreateDataSeries();
            _BearMode4 = CreateDataSeries();
            _BearMode5 = CreateDataSeries();

        }

        public override void Calculate(int index)
        {

            if (index < Period)
            {
                return;
            }

            if (IsLastBar)
            {
                if (index != lastindex)
                    lastindex = index;
                else
                    return;
            }
            if (mode == 3 || mode == 4)
            {
                double sum = 0;
                for (var i = 0; i < Period; i++)
                {
                    sum += Math.Abs(Bars.TypicalPrices[index - i] - Bars.ClosePrices.Sum(Period));
                }
                MeanDeviation[index] = sum / Period;
            }
            if (mode == 1 || mode == 4 || mode == 5)
                BullMode1[index] = 0.5 * (Math.Abs(Bars.ClosePrices[index] - Bars.ClosePrices[index - 1]) + (Bars.ClosePrices[index] - Bars.ClosePrices[index - 1]));
            if (mode == 2 || mode == 4 || mode == 5)
                BullMode2[index] = Bars.ClosePrices[index] - Bars.LowPrices.Minimum(Period);
            if (mode == 3 || mode == 4)
                BullMode3[index] = (Bars.TypicalPrices[index] - SMA.Result[index]) / (MeanDeviation[index] * Symbol.PipSize / 100);

            if (mode == 1 || mode == 4 || mode == 5)
                BearMode1[index] = 0.5 * (Math.Abs(Bars.ClosePrices[index] - Bars.ClosePrices[index - 1]) - (Bars.ClosePrices[index] - Bars.ClosePrices[index - 1]));
            if (mode == 2 || mode == 4 || mode == 5)
                BearMode2[index] = Bars.HighPrices.Maximum(Period) - Bars.ClosePrices[index];
            if (mode == 3 || mode == 4)
                BearMode3[index] = (SMA.Result[index] - Bars.TypicalPrices[index]) / (MeanDeviation[index] * Symbol.PipSize / 100);


            ////////////////////////////////// Normalization //////////////////////////////////////
            if (UseNorm || mode == 4)
            {
                if (mode == 1)
                {
                    _BullMode1[index] = (BullMode1[index] - BullMode1.Minimum(Period)) / (BullMode1.Maximum(Period) - BullMode1.Minimum(Period)) * 100;
                    _BearMode1[index] = (BearMode1[index] - BearMode1.Minimum(Period)) / (BearMode1.Maximum(Period) - BearMode1.Minimum(Period)) * 100;
                }

                else if (mode == 2)
                {
                    _BullMode2[index] = (BullMode2[index] - BullMode2.Minimum(Period)) / (BullMode2.Maximum(Period) - BullMode2.Minimum(Period)) * 100;
                    _BearMode2[index] = (BearMode2[index] - BearMode2.Minimum(Period)) / (BearMode2.Maximum(Period) - BearMode2.Minimum(Period)) * 100;
                }
                else if (mode == 3)
                {
                    _BullMode3[index] = (BullMode3[index] - BullMode3.Minimum(Period)) / (BullMode3.Maximum(Period) - BullMode3.Minimum(Period)) * 100;
                    _BearMode3[index] = (BearMode3[index] - BearMode3.Minimum(Period)) / (BearMode3.Maximum(Period) - BearMode3.Minimum(Period)) * 100;
                }

                else if (mode == 4)
                {
                    _BullMode1[index] = (BullMode1[index] - BullMode1.Minimum(Period)) / (BullMode1.Maximum(Period) - BullMode1.Minimum(Period)) * 100;
                    _BearMode1[index] = (BearMode1[index] - BearMode1.Minimum(Period)) / (BearMode1.Maximum(Period) - BearMode1.Minimum(Period)) * 100;

                    _BullMode2[index] = (BullMode2[index] - BullMode2.Minimum(Period)) / (BullMode2.Maximum(Period) - BullMode2.Minimum(Period)) * 100;
                    _BearMode2[index] = (BearMode2[index] - BearMode2.Minimum(Period)) / (BearMode2.Maximum(Period) - BearMode2.Minimum(Period)) * 100;

                    _BullMode3[index] = (BullMode3[index] - BullMode3.Minimum(Period)) / (BullMode3.Maximum(Period) - BullMode3.Minimum(Period)) * 100;
                    _BearMode3[index] = (BearMode3[index] - BearMode3.Minimum(Period)) / (BearMode3.Maximum(Period) - BearMode3.Minimum(Period)) * 100;

                    _BullMode4[index] = (_BullMode1[index] + _BullMode2[index] + _BullMode3[index]) / 3;

                    _BearMode4[index] = (_BearMode1[index] + _BearMode2[index] + _BearMode3[index]) / 3;
                }

                else if (mode == 5)
                {
                    _BullMode1[index] = (BullMode1[index] - BullMode1.Minimum(Period)) / (BullMode1.Maximum(Period) - BullMode1.Minimum(Period)) * 100;
                    _BearMode1[index] = (BearMode1[index] - BearMode1.Minimum(Period)) / (BearMode1.Maximum(Period) - BearMode1.Minimum(Period)) * 100;

                    _BullMode2[index] = (BullMode2[index] - BullMode2.Minimum(Period)) / (BullMode2.Maximum(Period) - BullMode2.Minimum(Period)) * 100;
                    _BearMode2[index] = (BearMode2[index] - BearMode2.Minimum(Period)) / (BearMode2.Maximum(Period) - BearMode2.Minimum(Period)) * 100;

                    _BullMode3[index] = (BullMode3[index] - BullMode3.Minimum(Period)) / (BullMode3.Maximum(Period) - BullMode3.Minimum(Period)) * 100;
                    _BearMode3[index] = (BearMode3[index] - BearMode3.Minimum(Period)) / (BearMode3.Maximum(Period) - BearMode3.Minimum(Period)) * 100;

                    _BullMode5[index] = (_BullMode1[index] + _BullMode2[index]) / 3;

                    _BearMode5[index] = (_BearMode1[index] + _BearMode2[index]) / 3;
                }

            }


            else
            {
                _BullMode1[index] = BullMode1[index];
                _BullMode2[index] = BullMode2[index];
                _BullMode3[index] = BullMode3[index];

                _BearMode1[index] = BearMode1[index];
                _BearMode2[index] = BearMode2[index];
                _BearMode3[index] = BearMode3[index];

                _BullMode5[index] = (BullMode1[index] + BullMode2[index]) / 3;
                _BearMode5[index] = (BearMode1[index] + BearMode2[index]) / 3;

            }

            bulls[index] = mode == 1 ? _BullMode1[index] : mode == 2 ? _BullMode2[index] : mode == 3 ? _BullMode3[index] : mode == 4 ? _BullMode4[index] : _BullMode5[index];
            bears[index] = mode == 1 ? _BearMode1[index] : mode == 2 ? _BearMode2[index] : mode == 3 ? _BearMode3[index] : mode == 4 ? _BearMode4[index] : _BearMode5[index];

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





jani's avatar
jani

Joined on 05.04.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Absolute Strength Advanced.algo
  • Rating: 0
  • Installs: 1505
  • Modified: 17/12/2021 19:53
Comments
Log in to add a comment.
MA
manasbhattacharya007 · 2 years ago

Why It dose not show the histogram??