ADX using WIlder smoothing
I believe that it is due to ADX in PTMC does not employ Wilder Smoothing method.
I desperately need ADX based on Wilder Smoothing. Can anybody help me about this?
Thank you
----- below is unmodified original ADX pre-built in PTMC
#region (ADX)Average Directional Index
//---------------------------------------------------
// Project: ADX
// Type: Indicator
// Author: PFSoft LLC
// Company: PFSoft LLC /www.pfsoft.com/
// Copyright: (C) PFSoft LLC Dnepopetrovsk. Ukraine
// Created: Nov, 28,2006
//---------------------------------------------------
public class ADX : NETIndicator
{
public ADX()
: base()
{
ProjectName = "Average Directional Index";
Comments = "Determines the strength of a prevailing trend";
SetIndicatorLine("adx", Color.Green, 1, LineStyle.SimpleChart);
SetIndicatorLine("plusDI", Color.Blue, 1, LineStyle.SimpleChart);
SetIndicatorLine("minusDI", Color.Red, 1, LineStyle.SimpleChart);
SeparateWindow = true;
}
[InputParameter("Type of Moving Average", 0, new object[] {
"Simple", MAMode.SMA,
"Exponential", MAMode.EMA,
"Modified", MAMode.SMMA,
"Linear Weighted", MAMode.LWMA}
)]
public MAMode MAType = MAMode.SMA;
[InputParameter("Period of Moving Average", 1, 1, 9999)]
public int MAPeriod = 13;
public override void Init()
{
IndicatorShortName(string.Format("ADX({0})", MAPeriod));
SetIndexDrawBegin(0, MAPeriod);
SetIndexDrawBegin(1, MAPeriod);
SetIndexDrawBegin(2, MAPeriod);
plusMa = Indicators.iMA(
delegate(int index)
{
double plusDM, minusDM;
GetPlusMinus(index, out plusDM, out minusDM);
return plusDM;
},
MAPeriod, MAType);
minusMa = Indicators.iMA(
delegate(int index)
{
double plusDM, minusDM;
GetPlusMinus(index, out plusDM, out minusDM);
return minusDM;
},
MAPeriod, MAType);
adxMa = Indicators.iMA(getADX, MAPeriod, MAType);
}
private double getTrueRange(int index)
{
double hi = CurrentData.GetPrice(PriceType.High, index);
double lo = CurrentData.GetPrice(PriceType.Low, index);
double prevClose = (CurrentData.Count > index + 1) ? CurrentData.GetPrice(PriceType.Close, index + 1) : CurrentData.GetPrice(PriceType.Close, index);
return Math.Max(hi - lo, Math.Max(Math.Abs(prevClose - hi), Math.Abs(prevClose - lo)));
}
private Indicator plusMa;
private Indicator minusMa;
private void GetPlusMinus(int index, out double plusDM, out double minusDM)
{
double smoothedTR = getTrueRange(index);
if (smoothedTR == 0 || index + 1 >= CurrentData.Count)
{
plusDM = 0D;
minusDM = 0D;
return;
}
// Calculation of directional movement (DMs)
plusDM = CurrentData.GetPrice(PriceType.High, index) - CurrentData.GetPrice(PriceType.High, index + 1);
if (plusDM < 0.0)
plusDM = 0.0;
else
plusDM *= 100D / smoothedTR;
minusDM = CurrentData.GetPrice(PriceType.Low, index + 1) - CurrentData.GetPrice(PriceType.Low, index);
if (minusDM < 0.0)
minusDM = 0.0;
else
minusDM *= 100D / smoothedTR;
if (plusDM > minusDM)
minusDM = 0.0;
else
plusDM = 0.0;
}
private Indicator adxMa;
private double getADX(int index)
{
double plusDI = plusMa.GetValue(0, index);
double minusDI = minusMa.GetValue(0, index);
return plusDI != -minusDI ? Math.Abs(plusDI - minusDI) / (plusDI + minusDI) : 0D;
}
public override void OnQuote()
{
SetValue(0, 0, 100 * adxMa.GetValue());
SetValue(1, 0, plusMa.GetValue());
SetValue(2, 0, minusMa.GetValue());
}
}
#endregion
Hello PTMCjhj!
I published an update version "ADXW" (on CodeBase) which is based on Wilder smoothing. Link here => Average Directional Index Wilder
You're welcome!
Not able to compile this indicator. It says error! Both ADX and DMI indicators in your Protrader platform might not be accurate. Compare the ADX and DMI indicators from Tradingview to Protrader ADX and DMI indicators you will see the difference.
Pls add a ADX/DMI indicator similar to tradingview DMI indicator where user can assign different values for ADX and DMI instead of the same value for both.