# Multiple Time Frame DMI Indicator for ThinkorSwim

#### hinkognito

##### New member
Hello All,

Could anyone help with this? Attempting to generate a MTF DMI Oscillator lower study. Here is what I got to, but I am getting errors with my time period. Any suggestions are welcome.

Many Thanks!

Code:
``````declare lower;

input length = 14;
input averageType = AverageType.WILDERS;
input Time2 = AggregationPeriod.FIFTEEN_MIN;
input Time3 = AggregationPeriod.FIVE_MIN;

def hiDiff1 = high - high;
def loDiff1 = low - low;

def plusDM1 = if hiDiff1 > loDiff1 and hiDiff1 > 0 then hiDiff1 else 0;
def minusDM1 =  if loDiff1 > hiDiff1 and loDiff1 > 0 then loDiff1 else 0;

def hiDiff2 = high(period=time2) - high(period=time2);
def loDiff2 = low(period=time2) - low(period=time2);

def plusDM2 = if hiDiff2 > loDiff2 and hiDiff2 > 0 then hiDiff2 else 0;
def minusDM2 =  if loDiff2 > hiDiff2 and loDiff2 > 0 then loDiff2 else 0;

def hiDiff3 = high(period=time3) - high(period=time3);
def loDiff3 = low(period=time3) - low(period=time3);

def plusDM2 = if hiDiff3 > loDiff3 and hiDiff3 > 0 then hiDiff3 else 0;
def minusDM2 =  if loDiff3 > hiDiff3 and loDiff3 > 0 then loDiff3 else 0;

plot osc1 = plusdm1-minusdm1;
plot osc2 = plusdm2-minusdm2;
plot osc3 = plusdm3-minusdm3;``````

#### BenTen

Staff
VIP
You put `` in the wrong spot. I just fixed the aggregation error for you. Feel free to continue to work on the rest.

Code:
``````declare lower;

input length = 14;
input averageType = AverageType.WILDERS;
input Time2 = AggregationPeriod.FIFTEEN_MIN;
input Time3 = AggregationPeriod.FIVE_MIN;

def hiDiff1 = high - high;
def loDiff1 = low - low;

def plusDM1 = if hiDiff1 > loDiff1 and hiDiff1 > 0 then hiDiff1 else 0;
def minusDM1 =  if loDiff1 > hiDiff1 and loDiff1 > 0 then loDiff1 else 0;

def hiDiff2 = high(period = Time2) - high(period=time2);
def loDiff2 = low(period=time2) - low(period=time2);

def plusDM2 = if hiDiff2 > loDiff2 and hiDiff2 > 0 then hiDiff2 else 0;
def minusDM2 =  if loDiff2 > hiDiff2 and loDiff2 > 0 then loDiff2 else 0;

def hiDiff3 = high(period=time3) - high(period=time3);
def loDiff3 = low(period=time3) - low(period=time3);

def plusDM2 = if hiDiff3 > loDiff3 and hiDiff3 > 0 then hiDiff3 else 0;
def minusDM2 =  if loDiff3 > hiDiff3 and loDiff3 > 0 then loDiff3 else 0;

plot osc1 = plusdm1-minusdm1;
plot osc2 = plusdm2-minusdm2;
plot osc3 = plusdm3-minusdm3;``````

• hinkognito

Thank you sir!

#### GimmickFace

##### Member
Thank you sir!
hinkognito can you post the final version when you are finished? I am very interested!

#### Pelonsax

##### Active member
VIP
hinkognito can you post the final version when you are finished? I am very interested!
Here's one I cooked up a while back
Code:
``````##################
# by PELONSAX
##################

declare lower;

input Agg = AggregationPeriod.THREE_MIN;
input length = 14;
input averageType = AverageType.WILDERS;

def hiDiff = high(period = Agg) - high(period = Agg);
def loDiff = low(period = Agg) - low(period = Agg);

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(period = Agg), close(period = Agg), low(period = Agg)), 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 level25 = 25;

input ShowDI_Plus = yes;
"DI+".SetDefaultColor(Color.GREEN);
"DI+".SetLineWeight(1);
"DI+".SetHiding(!ShowDI_Plus);

input ShowDI_Minus = yes;
"DI-".SetDefaultColor(Color.RED);
"DI-".SetLineWeight(1);
"DI-".SetHiding(!ShowDI_Minus);

• hinkognito

#### hectorgasm

##### Member Hello guys, I created a DMI MTF indicator that somehow works well on a 5 minute chart. It doesn't repaint, the only thing you need to do is to put the chart to plot 90 days of data. Feel free to check out and add your creativity haha.

Code:
``````## created by hectorgasm

input ap = AggregationPeriod.DAY;
DEF mthopen = close-close(period = ap);

input length = 50;
input averageType = AverageType.WILDERS;

def hiDiff = highest(MTHopen) - highest(MTHopen);
def loDiff = lowest(MTHopen) - lowest(MTHopen);

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(highest(MTHopen), MThopen, lowest(MTHopen)), 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);

plot level = 1;

"DI+".SetDefaultColor(GetColor(1));
"DI-".SetDefaultColor(GetColor(8));
• 