# dmi_mtf_0a
# DMI
# TD Ameritrade IP Company, Inc. (c) 2008-2022
declare lower;
input prices = { default second_agg, chart };
input agg = AggregationPeriod.HOUR;
def mopen;
def mhigh;
def mlow;
def mclose;
switch (prices) {
case second_agg:
mopen = open(period = agg);
mhigh = high(period = agg);
mlow = low(period = agg);
mclose = close(period = agg);
case chart:
mopen = open;
mhigh = high;
mlow = low;
mclose = close;
}
input length = 14;
input averageType = AverageType.WILDERS;
#def hiDiff = high - high[1];
#def loDiff = low[1] - low;
def hiDiff = mhigh - mhigh[1];
def loDiff = mlow[1] - mlow;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
#def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
def ATR = MovingAverage(averageType, TrueRange(mhigh, mclose, mlow), length);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, length);
"DI+".SetDefaultColor(color.green);
"DI-".SetDefaultColor(color.red);
ADX.SetDefaultColor(color.cyan);
# points
"di+".SetPaintingStrategy(PaintingStrategy.POINTS);
"di-".SetPaintingStrategy(PaintingStrategy.POINTS);
adx.SetPaintingStrategy(PaintingStrategy.POINTS);
"di+".setlineweight(1);
"di-".setlineweight(1);
adx.setlineweight(1);
"di+".hidebubble();
"di-".hidebubble();
adx.hidebubble();
#