Category Oscilators  Published on 31/07/2023

DPO of GHLA indicator

An update for this algorithm is currently pending moderation. Please revisit this page shortly to access the algorithm's latest version.
Description

The Detrended Price Oscillator (DPO) is a well-known market sentiment indicator, displaying values above (bullish) and below (bearish) the zero level. This version of the custom indicator colors the values after smoothing DPO with the FIR method, indicating confident market conditions as:

  • Very bullish: Above zero, colored green.
  • Weak bullish: Above zero, colored red.
  • Very bearish: Below zero, colored red.
  • Weak bearish: Below zero, colored green.



mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mDPOgann.algo
  • Rating: 5
  • Installs: 572
  • Modified: 31/07/2023 07:22
Comments
Log in to add a comment.
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mDPOgann : Indicator
    {
        [Parameter("Period (12)", DefaultValue = 12)]
        public int inpPeriod { get; set; }
        [Parameter("Smooth Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType inpSmoothType { get; set; }
        [Parameter("GHLA Range Period (10)", DefaultValue = 10, MinValue = 1)]
        public int inpRangePeriod { get; set; }

        [Output("DPO/Gann HiLo Activator", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outGHLA { get; set; }
        [Output("DPO/Gann HiLo Activator Bullish", LineColor = "Green", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outGHLAbull { get; set; }
        [Output("DPO/Gann HiLo Activator Bearish", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outGHLAbear { get; set; }

        private IndicatorDataSeries _firc, _firh, _firl;
        private DetrendedPriceOscillator _dpoc, _dpoh, _dpol;
        private MovingAverage _ragehigh, _ragelow;
        private IndicatorDataSeries _trend, _ghla, _bull, _bear;


        protected override void Initialize()
        {
            _firc = CreateDataSeries();
            _firh = CreateDataSeries();
            _firl = CreateDataSeries();
            _dpoc = Indicators.DetrendedPriceOscillator(_firc, inpPeriod, inpSmoothType);
            _dpoh = Indicators.DetrendedPriceOscillator(_firh, inpPeriod, inpSmoothType);
            _dpol = Indicators.DetrendedPriceOscillator(_firl, inpPeriod, inpSmoothType);
            _ragehigh = Indicators.MovingAverage(_dpoh.Result, inpRangePeriod, MovingAverageType.Simple);
            _ragelow = Indicators.MovingAverage(_dpol.Result, inpRangePeriod, MovingAverageType.Simple);
            _ghla = CreateDataSeries();
            _trend = CreateDataSeries();
            _bull = CreateDataSeries();
            _bear = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _firc[i] = i>3 ? (Bars.ClosePrices[i] + 2.0 * Bars.ClosePrices[i-1] + 2.0 * Bars.ClosePrices[i-2] + Bars.ClosePrices[i-3]) / 6.0 : Bars.ClosePrices[i];
            _firh[i] = i>3 ? (Bars.HighPrices[i] + 2.0 * Bars.HighPrices[i-1] + 2.0 * Bars.HighPrices[i-2] + Bars.HighPrices[i-3]) / 6.0 : Bars.HighPrices[i];
            _firl[i] = i>3 ? (Bars.LowPrices[i] + 2.0 * Bars.LowPrices[i-1] + 2.0 * Bars.LowPrices[i-2] + Bars.LowPrices[i-3]) / 6.0 : Bars.LowPrices[i];
            _trend[i] = _dpoc.Result[i] > _ragehigh.Result[i] ? +1 : _dpoc.Result[i] < _ragelow.Result[i] ? -1 : (i>1 ? _trend[i-1] : +1);
            _ghla[i] = _trend[i] < 0 ? _ragehigh.Result[i] : _ragelow.Result[i];
            _bull[i] = _trend[i] < 0 ? double.NaN : _ragelow.Result[i];
            _bear[i] = _trend[i] < 0 ? _ragehigh.Result[i] : double.NaN; 
            
            outGHLA[i] = _ghla[i] / Symbol.PipSize;
            outGHLAbull[i] = _bull[i] / Symbol.PipSize;
            outGHLAbear[i] = _bear[i] / Symbol.PipSize;
        }
    }
}