Category Oscilators  Published on 12/09/2019

DPO Enhacned

Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them. There's also a Discord Server now @ https://discord.gg/5GAPMtp and an Instagram page https://www.instagram.com/ctrader_community/

This is an enhanced version of the classic DPO, it has ATR and STDev based filters for volatility to filter out smaller movements.

Plus, the values of these indicators have been converted to pips, since the classic DPO values are not easy to deal with especially when passing on from one market to another.


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, ScalePrecision = 1, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DPOTrigger : Indicator
    {
        [Parameter("DPO Period", Group = "DPO", DefaultValue = 21)]
        public int DPOPer { get; set; }
        [Parameter("DPO Smoothing", Group = "DPO", DefaultValue = 4)]
        public int DPOSmt { get; set; }
        [Parameter("MA Type", Group = "DPO", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MAType { get; set; }
        [Parameter("ATR Period", Group = "ATR", DefaultValue = 200)]
        public int ATRPer { get; set; }
        [Parameter("ATR Multiplier", Group = "ATR", DefaultValue = 2, Step = 0.1)]
        public double ATRMul { get; set; }
        [Parameter("STD Period", Group = "ST Dev", DefaultValue = 200)]
        public int STDPer { get; set; }
        [Parameter("STD Multiplier", Group = "ST Dev", DefaultValue = 1)]
        public double STDMul { get; set; }
        [Parameter("Draw ATR Area", Group = "Areas", DefaultValue = true)]
        public bool ATRArea { get; set; }
        [Parameter("Draw STD Area", Group = "Areas", DefaultValue = false)]
        public bool STDArea { get; set; }

        [Output("STD Up", LineColor = "RoyalBlue", LineStyle = LineStyle.LinesDots)]
        public IndicatorDataSeries STDUp { get; set; }
        [Output("STD Down", LineColor = "RoyalBlue", LineStyle = LineStyle.LinesDots)]
        public IndicatorDataSeries STDDown { get; set; }
        [Output("ATR Up", LineColor = "83FFA500", LineStyle = LineStyle.Solid)]
        public IndicatorDataSeries ATRUp { get; set; }
        [Output("ATR Down", LineColor = "83FFA500", LineStyle = LineStyle.Solid)]
        public IndicatorDataSeries ATRDown { get; set; }
        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private DetrendedPriceOscillator DPO;
        private AverageTrueRange ATR;
        private StandardDeviation STD;
        private ExponentialMovingAverage EMA;

        private int Thickness = 3;

        protected override void Initialize()
        {
            DPO = Indicators.DetrendedPriceOscillator(MarketSeries.Close, DPOPer, MAType);
            EMA = Indicators.ExponentialMovingAverage(DPO.Result, DPOSmt);
            ATR = Indicators.AverageTrueRange(ATRPer, MovingAverageType.Exponential);
            STD = Indicators.StandardDeviation(MarketSeries.Close, STDPer, MovingAverageType.Simple);
            if (RunningMode == RunningMode.RealTime)
                IndicatorArea.DrawHorizontalLine("0", 0, Color.FromHex("807D00F1"));
        }

        public override void Calculate(int index)
        {
            Result[index] = EMA.Result[index] / Symbol.PipSize;
            ATRUp[index] = ATR.Result[index] * ATRMul / Symbol.PipSize;
            ATRDown[index] = -ATR.Result[index] * ATRMul / Symbol.PipSize;
            STDUp[index] = STD.Result[index] * STDMul / Symbol.PipSize;
            STDDown[index] = -STD.Result[index] * STDMul / Symbol.PipSize;

            if (ATRArea)
                if (Math.Abs(Result[index]) > ATRUp[index])
                    IndicatorArea.DrawTrendLine("ATR Area " + index, index, Result[index], index, Result[index] < 0 ? ATRDown[index] : ATRUp[index], Result[index] < 0 ? Color.FromArgb(50, 255, 0, 0) : Color.FromArgb(50, 0, 255, 0), Thickness);
            if (STDArea)
                if (Math.Abs(Result[index]) > STDUp[index])
                    IndicatorArea.DrawTrendLine("STD Area " + index, index, Result[index], index, Result[index] < 0 ? STDDown[index] : STDUp[index], Color.FromArgb(50, 0, 0, 255), Thickness);
        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: DPO.algo
  • Rating: 5
  • Installs: 1827
Comments
Log in to add a comment.
KO
koprzyk7 · 3 years ago

Hey bro, I love this indicator, really. How can I make him as MTF verion? It's easy without programming skills?