ADX indicator
ADX indicator
10 Nov 2016, 15:05
hope someone have or used the Standard MT4 adx 14 indicator i have try to convert it but i missed the experience,The D M S from c trader is different (smoother) the mt4 EMA based we think Hope some one can help , best regards , Pascal.
Replies
... Deleted by UFO ...
sktradingfx
14 Dec 2016, 21:44
RE:
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
@sktradingfx
sktradingfx
15 Dec 2016, 00:03
RE:
tmc. said:
What you mean by the smoothing method? If I am not mistaken ADXR is equal to the last ADX value plus the value N bars ago devided by 2, there isn't used the regular smoothing method known as Moving Average.
Hi tmc.
thanks a lot for your swift reply.
You are right! ADXR is not calculated by applying a MA to the ADX but by smoothing as you said: current ADX + ADX n bars ago / 2.
Could you implement that?
Best
sk
@sktradingfx
whis.gg
15 Dec 2016, 01:03
Here you go.
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; } [Parameter("ADXR", DefaultValue = 14, MinValue = 0)] public int AdxrPeriod { get; set; } [Output("ADX", Color = Colors.Cyan)] public IndicatorDataSeries ADX { get; set; } [Output("ADXR", Color = Colors.Yellow)] public IndicatorDataSeries ADXR { 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]; ADXR[index] = (ADX[index] + ADX[index - AdxrPeriod]) / 2; } } } }
@whis.gg
sktradingfx
15 Dec 2016, 20:59
RE:
tmc.,
you are awesome!!! The indy works perfectly.
Thank you very much!!
I wish you a lot of green pips!
Best
sk
tmc. said:
Here you go.
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; } [Parameter("ADXR", DefaultValue = 14, MinValue = 0)] public int AdxrPeriod { get; set; } [Output("ADX", Color = Colors.Cyan)] public IndicatorDataSeries ADX { get; set; } [Output("ADXR", Color = Colors.Yellow)] public IndicatorDataSeries ADXR { 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]; ADXR[index] = (ADX[index] + ADX[index - AdxrPeriod]) / 2; } } } }
@sktradingfx
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
whis.gg
15 Nov 2016, 00:38
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.
@whis.gg