Topics

Forum Topics not found

Replies

erkin3021186
31 Mar 2017, 02:52

RE: RE:

sktradingfx said:

tmc. said:

Hi, Directional Movement System in cTrader platform is using Wilder Smoothing that can't be changed. I have re-built the indicator with an option to choose different smoothing methods. Build the indicator and change MA Type to Exponential, it should match the MT4 results.

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

namespace cAlgo
{
    [Indicator("DMS", IsOverlay = false, ScalePrecision = 0, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DirectionalMovementSystem : Indicator
    {
        [Parameter("Period", DefaultValue = 14, MinValue = 1)]
        public int Period { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.WilderSmoothing)]
        public MovingAverageType MaType { get; set; }

        [Output("ADX", Color = Colors.Cyan)]
        public IndicatorDataSeries ADX { get; set; }

        [Output("DI+", Color = Colors.Green)]
        public IndicatorDataSeries DiPlus { get; set; }

        [Output("Di-", Color = Colors.Red)]
        public IndicatorDataSeries DiMinus { get; set; }

        private DataSeries high, low, close;
        private IndicatorDataSeries tr, dmPlus, dmMinus, adx;
        private MovingAverage maTr, maDmPlus, maDmMinus, maAdx;

        protected override void Initialize()
        {
            high = MarketSeries.High;
            low = MarketSeries.Low;
            close = MarketSeries.Close;

            tr = CreateDataSeries();
            dmPlus = CreateDataSeries();
            dmMinus = CreateDataSeries();
            adx = CreateDataSeries();

            maTr = Indicators.MovingAverage(tr, Period, MaType);
            maDmPlus = Indicators.MovingAverage(dmPlus, Period, MaType);
            maDmMinus = Indicators.MovingAverage(dmMinus, Period, MaType);
            maAdx = Indicators.MovingAverage(adx, Period, MaType);
        }

        public override void Calculate(int index)
        {
            if (index == 0)
            {
                tr[0] = high[0] - low[0];
                dmPlus[0] = 0;
                dmMinus[0] = 0;
            }
            else
            {
                tr[index] = Math.Max(Math.Abs(low[index] - close[index - 1]), Math.Max(Math.Abs(high[index] - close[index - 1]), high[index] - low[index]));
                dmPlus[index] = high[index] - high[index - 1] > low[index - 1] - low[index] ? Math.Max(high[index] - high[index - 1], 0) : 0;
                dmMinus[index] = low[index - 1] - low[index] > high[index] - high[index - 1] ? Math.Max(low[index - 1] - low[index], 0) : 0;

                DiPlus[index] = 100 * (maTr.Result[index] == 0 ? 0 : maDmPlus.Result[index] / maTr.Result[index]);
                DiMinus[index] = 100 * (maTr.Result[index] == 0 ? 0 : maDmMinus.Result[index] / maTr.Result[index]);

                adx[index] = Math.Abs((DiPlus[index] - DiMinus[index]) / (DiPlus[index] + DiMinus[index]));
                ADX[index] = adx[index] == 0 ? 50 : 100 * maAdx.Result[index];
            }
        }
    }
}

 

Hi tmc.

great indicator, highly appreciated!!

Would it be possible to add ADXR (Average Directional Movement Index Rating = smoothed version of ADX) to the indicator and have everything in one window?

If you could code that with the option to choose the smoothing method of the ADXR as well, this would be the deluxe version of the directional movement system.

Many thanks in advance!

sk

 


@erkin3021186