11/21/19 - Colored candles fixed, ADXLength variable renamed to ADXLevels

11/20/19 - 7:45p, fixed label code conditions for ADX so all time frame charts now match to what they are supposed to be

11/20/19 - Separated labels into separate conditions, to avoid label logic from confusing TOS. 

11/19/19 - Logic behind bullish, bearish and neutral zones updated, thanks to member feedback. More detail available in DMI Power Scans tutorial video.

11/14/19 - Arrows are not added to the current version of the code, only colored candles

Welcome to the eleventh episode of “How to Thinkscript”. We are TOSIndicators.com, home of the Volatility Box, the most robust ThinkOrSwim indicator based on statistical models built for large institutions and hedge funds.

We just launched our new Stock Volatility Box which has helped our traders absolutely crush the market. This tool is currently invite only. If you’d like to be added to the list, you can send us a note at contact[at]tosindicators.com.

In this tutorial, we show you how to build a Multi Time Frame DMI indicator, which you can use if the Dynamic RSI doesn’t fit your trading style.

This project was a collaboration with one of our Volatility Box members, Dick K. who mentioned that the Dynamic RSI often times had late signals, for entries he was looking at.

We started observing different indicators that we might be able to use for momentum trading, and landed on the DMI. In this episode, we unpack the DMI, as well as apply the capabilities of multiple time frame analysis, to really highlight the power of thinkScript.

If you’d like to skip the tutorial and start playing with the indicator right away, you can download the MTF DMI Indicator for free below.

 

Concepts That We’ll Focus On

There are several key concepts that you can expect to take away from this tutorial video:

  • 1. Reading ThinkOrSwim indicator documentation, to understand how to use the given plot code
  • 2. Integrating multiple time frame analysis, on a single chart (to start to use with any indicator)
  • 3. User controlled plots for the colored candles

Final product preview:

 

Multiple Time Frame Code

For those of you following along the tutorial, here is the multiple time frame code, which we are using to help us plot our multiple labels:

def monthPlus;
 def monthMinus;
 def monthAdx;
 def monthBullishSignal;
 def monthBearishSignal;
 def monthNarrowRange;
 def monthNarrowRangeTest;
 def monthBullishZone;
 def monthBearishZone;
 def monthNeutralZone;
 def monthHiDiff;
 def monthLoDiff;
 def monthPlusDM;
 def monthMinusDM;
 def monthATR;
 if GetAggregationPeriod() <= AggregationPeriod.MONTH {
 monthHiDiff = high(period = "Month") - high(period = "Month")[1]; monthLoDiff = low(period = "Month")[1] - low(period = "Month"); monthPlusDM = if monthHiDiff > monthLoDiff and monthHiDiff > 0 then monthHiDiff else 0; monthMinusDM =  if monthLoDiff > monthHiDiff and monthLoDiff > 0 then monthLoDiff else 0; monthATR = MovingAverage(averageType, TrueRange(high(period = "Month"), close(period = "Month"),        low(period = "Month")), length); monthAdx = DMI(length, averageType).ADX; monthPlus = 100 * MovingAverage(averageType, monthPlusDM, length) / monthATR; monthMinus = 100 * MovingAverage(averageType, monthMinusDM, length) / monthATR; monthBullishSignal = monthPlus crosses above monthMinus; monthBearishSignal = monthPlus crosses below monthMinus; monthNarrowRange = if monthMinus > monthPlus then monthMinus - monthPlus else if monthPlus > monthMinus then monthPlus - monthMinus else 0; monthNarrowRangeTest = monthNarrowRange >= 10; monthBullishZone = monthPlus > monthMinus and monthNarrowRangeTest; monthBearishZone = monthPlus < monthMinus and monthNarrowRangeTest; monthNeutralZone = !monthBullishZone and !monthBearishZone; } else { monthPlus = 0; monthMinus = 0; monthAdx = 0; monthPlusDM = 0; monthMinusDM = 0; monthBullishSignal = 0; monthBearishSignal = 0; monthNarrowRange = 0; monthNarrowRangeTest = 0; monthBullishZone = 0; monthBearishZone = 0; monthNeutralZone = 0; monthHiDiff = 0; monthLoDiff = 0; monthATR = 0; } AddLabel(monthBullishZone or monthBearishZone or monthNeutralZone, "M", if monthBullishZone then Color.GREEN else if monthBearishZone then Color.RED else if monthNeutralZone then Color.YELLOW else Color.GRAY); def weekPlus; def weekMinus; def weekAdx; def weekBullishSignal; def weekBearishSignal; def weekNarrowRange; def weekNarrowRangeTest; def weekBullishZone; def weekBearishZone; def weekNeutralZone; def weekHiDiff; def weekLoDiff; def weekPlusDM; def weekMinusDM; def weekATR; if GetAggregationPeriod() <= AggregationPeriod.WEEK { weekHiDiff = high(period = "week") - high(period = "week")[1]; weekLoDiff = low(period = "week")[1] - low(period = "week"); weekPlusDM = if weekHiDiff > weekLoDiff and weekHiDiff > 0 then weekHiDiff else 0; weekMinusDM =  if weekLoDiff > weekHiDiff and weekLoDiff > 0 then weekLoDiff else 0; weekATR = MovingAverage(averageType, TrueRange(high(period = "week"), close(period = "week"),        low(period = "week")), length); weekAdx = DMI(length, averageType).ADX; weekPlus = 100 * MovingAverage(averageType, weekPlusDM, length) / weekATR; weekMinus = 100 * MovingAverage(averageType, weekMinusDM, length) / weekATR; weekBullishSignal = weekPlus crosses above weekMinus; weekBearishSignal = weekPlus crosses below weekMinus; weekNarrowRange = if weekMinus > weekPlus then weekMinus - weekPlus else if weekPlus > weekMinus then weekPlus - weekMinus else 0; weekNarrowRangeTest = weekNarrowRange >= 10; weekBullishZone = weekPlus > weekMinus and weekNarrowRangeTest; weekBearishZone = weekPlus < weekMinus and weekNarrowRangeTest; weekNeutralZone = !weekBullishZone and !weekBearishZone; } else { weekPlus = 0; weekMinus = 0; weekAdx = 0; weekPlusDM = 0; weekMinusDM = 0; weekBullishSignal = 0; weekBearishSignal = 0; weekNarrowRange = 0; weekNarrowRangeTest = 0; weekBullishZone = 0; weekBearishZone = 0; weekNeutralZone = 0; weekHiDiff = 0; weekLoDiff = 0; weekATR = 0; } AddLabel(weekBullishZone or weekBearishZone or weekNeutralZone, "W", if weekBullishZone then Color.GREEN else if weekBearishZone then Color.RED else if weekNeutralZone then Color.YELLOW else Color.GRAY); def fourDayPlus; def fourDayMinus; def fourDayAdx; def fourDayBullishSignal; def fourDayBearishSignal; def fourDayNarrowRange; def fourDayNarrowRangeTest; def fourDayBullishZone; def fourDayBearishZone; def fourDayNeutralZone; def fourDayHiDiff; def fourDayLoDiff; def fourDayPlusDM; def fourDayMinusDM; def fourDayATR; if GetAggregationPeriod() <= AggregationPeriod.FOUR_DAYS { fourDayHiDiff = high(period = "4 Days") - high(period = "4 Days")[1]; fourDayLoDiff = low(period = "4 Days")[1] - low(period = "4 Days"); fourDayPlusDM = if fourDayHiDiff > fourDayLoDiff and fourDayHiDiff > 0 then fourDayHiDiff else 0; fourDayMinusDM =  if fourDayLoDiff > fourDayHiDiff and fourDayLoDiff > 0 then fourDayLoDiff else 0; fourDayATR = MovingAverage(averageType, TrueRange(high(period = "4 Days"), close(period = "4 Days"),        low(period = "4 Days")), length); fourDayAdx = DMI(length, averageType).ADX; fourDayPlus = 100 * MovingAverage(averageType, fourDayPlusDM, length) / fourDayATR; fourDayMinus = 100 * MovingAverage(averageType, fourDayMinusDM, length) / fourDayATR; fourDayBullishSignal = fourDayPlus crosses above fourDayMinus; fourDayBearishSignal = fourDayPlus crosses below fourDayMinus; fourDayNarrowRange = if fourDayMinus > fourDayPlus then fourDayMinus - fourDayPlus else if fourDayPlus > fourDayMinus then fourDayPlus - fourDayMinus else 0; fourDayNarrowRangeTest = fourDayNarrowRange >= 10; fourDayBullishZone = fourDayPlus > fourDayMinus and fourDayNarrowRangeTest; fourDayBearishZone = fourDayPlus < fourDayMinus and fourDayNarrowRangeTest; fourDayNeutralZone = !fourDayBullishZone and !fourDayBearishZone; } else { fourDayPlus = 0; fourDayMinus = 0; fourDayAdx = 0; fourDayPlusDM = 0; fourDayMinusDM = 0; fourDayBullishSignal = 0; fourDayBearishSignal = 0; fourDayNarrowRange = 0; fourDayNarrowRangeTest = 0; fourDayBullishZone = 0; fourDayBearishZone = 0; fourDayNeutralZone = 0; fourDayHiDiff = 0; fourDayLoDiff = 0; fourDayATR = 0; } AddLabel(fourDayBullishZone or fourDayBearishZone or fourDayNeutralZone, "4D", if fourDayBullishZone then Color.GREEN else if fourDayBearishZone then Color.RED else if fourDayNeutralZone then Color.YELLOW else Color.GRAY); def threeDayPlus; def threeDayMinus; def threeDayAdx; def threeDayBullishSignal; def threeDayBearishSignal; def threeDayNarrowRange; def threeDayNarrowRangeTest; def threeDayBullishZone; def threeDayBearishZone; def threeDayNeutralZone; def threeDayHiDiff; def threeDayLoDiff; def threeDayPlusDM; def threeDayMinusDM; def threeDayATR; if GetAggregationPeriod() <= AggregationPeriod.THREE_DAYS { threeDayHiDiff = high(period = "3 Days") - high(period = "3 Days")[1]; threeDayLoDiff = low(period = "3 Days")[1] - low(period = "3 Days"); threeDayPlusDM = if threeDayHiDiff > threeDayLoDiff and threeDayHiDiff > 0 then threeDayHiDiff else 0; threeDayMinusDM =  if threeDayLoDiff > threeDayHiDiff and threeDayLoDiff > 0 then threeDayLoDiff else 0; threeDayATR = MovingAverage(averageType, TrueRange(high(period = "3 Days"), close(period = "3 Days"),        low(period = "3 Days")), length); threeDayAdx = DMI(length, averageType).ADX; threeDayPlus = 100 * MovingAverage(averageType, threeDayPlusDM, length) / threeDayATR; threeDayMinus = 100 * MovingAverage(averageType, threeDayMinusDM, length) / threeDayATR; threeDayBullishSignal = threeDayPlus crosses above threeDayMinus; threeDayBearishSignal = threeDayPlus crosses below threeDayMinus; threeDayNarrowRange = if threeDayMinus > threeDayPlus then threeDayMinus - threeDayPlus else if threeDayPlus > threeDayMinus then threeDayPlus - threeDayMinus else 0; threeDayNarrowRangeTest = threeDayNarrowRange >= 10; threeDayBullishZone = threeDayPlus > threeDayMinus and threeDayNarrowRangeTest; threeDayBearishZone = threeDayPlus < threeDayMinus and threeDayNarrowRangeTest; threeDayNeutralZone = !threeDayBullishZone and !threeDayBearishZone; } else { threeDayPlus = 0; threeDayMinus = 0; threeDayAdx = 0; threeDayPlusDM = 0; threeDayMinusDM = 0; threeDayBullishSignal = 0; threeDayBearishSignal = 0; threeDayNarrowRange = 0; threeDayNarrowRangeTest = 0; threeDayBullishZone = 0; threeDayBearishZone = 0; threeDayNeutralZone = 0; threeDayHiDiff = 0; threeDayLoDiff = 0; threeDayATR = 0; } AddLabel(threeDayBullishZone or threeDayBearishZone or threeDayNeutralZone, "3D", if threeDayBullishZone then Color.GREEN else if threeDayBearishZone then Color.RED else if threeDayNeutralZone then Color.YELLOW else Color.GRAY); def twoDayPlus; def twoDayMinus; def twoDayAdx; def twoDayBullishSignal; def twoDayBearishSignal; def twoDayNarrowRange; def twoDayNarrowRangeTest; def twoDayBullishZone; def twoDayBearishZone; def twoDayNeutralZone; def twoDayHiDiff; def twoDayLoDiff; def twoDayPlusDM; def twoDayMinusDM; def twoDayATR; if GetAggregationPeriod() <= AggregationPeriod.TWO_DAYS { twoDayHiDiff = high(period = "2 Days") - high(period = "2 Days")[1]; twoDayLoDiff = low(period = "2 Days")[1] - low(period = "2 Days"); twoDayPlusDM = if twoDayHiDiff > twoDayLoDiff and twoDayHiDiff > 0 then twoDayHiDiff else 0; twoDayMinusDM =  if twoDayLoDiff > twoDayHiDiff and twoDayLoDiff > 0 then twoDayLoDiff else 0; twoDayATR = MovingAverage(averageType, TrueRange(high(period = "2 Days"), close(period = "2 Days"),        low(period = "2 Days")), length); twoDayAdx = DMI(length, averageType).ADX; twoDayPlus = 100 * MovingAverage(averageType, twoDayPlusDM, length) / twoDayATR; twoDayMinus = 100 * MovingAverage(averageType, twoDayMinusDM, length) / twoDayATR; twoDayBullishSignal = twoDayPlus crosses above twoDayMinus; twoDayBearishSignal = twoDayPlus crosses below twoDayMinus; twoDayNarrowRange = if twoDayMinus > twoDayPlus then twoDayMinus - twoDayPlus else if twoDayPlus > twoDayMinus then twoDayPlus - twoDayMinus else 0; twoDayNarrowRangeTest = twoDayNarrowRange >= 10; twoDayBullishZone = twoDayPlus > twoDayMinus and twoDayNarrowRangeTest; twoDayBearishZone = twoDayPlus < twoDayMinus and twoDayNarrowRangeTest; twoDayNeutralZone = !twoDayBullishZone and !twoDayBearishZone; } else { twoDayPlus = 0; twoDayMinus = 0; twoDayAdx = 0; twoDayPlusDM = 0; twoDayMinusDM = 0; twoDayBullishSignal = 0; twoDayBearishSignal = 0; twoDayNarrowRange = 0; twoDayNarrowRangeTest = 0; twoDayBullishZone = 0; twoDayBearishZone = 0; twoDayNeutralZone = 0; twoDayHiDiff = 0; twoDayLoDiff = 0; twoDayATR = 0; } AddLabel(twoDayBullishZone or twoDayBearishZone or twoDayNeutralZone, "2D", if twoDayBullishZone then Color.GREEN else if twoDayBearishZone then Color.RED else if twoDayNeutralZone then Color.YELLOW else Color.GRAY); def DayPlus; def DayMinus; def DayAdx; def DayBullishSignal; def DayBearishSignal; def DayNarrowRange; def DayNarrowRangeTest; def DayBullishZone; def DayBearishZone; def DayNeutralZone; def DayHiDiff; def DayLoDiff; def DayPlusDM; def DayMinusDM; def DayATR; if GetAggregationPeriod() <= AggregationPeriod.DAY { DayHiDiff = high(period = "Day") - high(period = "Day")[1]; DayLoDiff = low(period = "Day")[1] - low(period = "Day"); DayPlusDM = if DayHiDiff > DayLoDiff and DayHiDiff > 0 then DayHiDiff else 0; DayMinusDM =  if DayLoDiff > DayHiDiff and DayLoDiff > 0 then DayLoDiff else 0; DayATR = MovingAverage(averageType, TrueRange(high(period = "Day"), close(period = "Day"),        low(period = "Day")), length); DayAdx = DMI(length, averageType).ADX; DayPlus = 100 * MovingAverage(averageType, DayPlusDM, length) / DayATR; DayMinus = 100 * MovingAverage(averageType, DayMinusDM, length) / DayATR; DayBullishSignal = DayPlus crosses above DayMinus; DayBearishSignal = DayPlus crosses below DayMinus; DayNarrowRange = if DayMinus > DayPlus then DayMinus - DayPlus else if DayPlus > DayMinus then DayPlus - DayMinus else 0; DayNarrowRangeTest = DayNarrowRange >= 10; DayBullishZone = DayPlus > DayMinus and DayNarrowRangeTest; DayBearishZone = DayPlus < DayMinus and DayNarrowRangeTest; DayNeutralZone = !DayBullishZone and !DayBearishZone; } else { DayPlus = 0; DayMinus = 0; DayAdx = 0; DayPlusDM = 0; DayMinusDM = 0; DayBullishSignal = 0; DayBearishSignal = 0; DayNarrowRange = 0; DayNarrowRangeTest = 0; DayBullishZone = 0; DayBearishZone = 0; DayNeutralZone = 0; DayHiDiff = 0; DayLoDiff = 0; DayATR = 0; } AddLabel(DayBullishZone or DayBearishZone or DayNeutralZone, "D", if DayBullishZone then Color.GREEN else if DayBearishZone then Color.RED else if DayNeutralZone then Color.YELLOW else Color.GRAY); def fourHoursPlus; def fourHoursMinus; def fourHoursAdx; def fourHoursBullishSignal; def fourHoursBearishSignal; def fourHoursNarrowRange; def fourHoursNarrowRangeTest; def fourHoursBullishZone; def fourHoursBearishZone; def fourHoursNeutralZone; def fourHoursHiDiff; def fourHoursLoDiff; def fourHoursPlusDM; def fourHoursMinusDM; def fourHoursATR; if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS { fourHoursHiDiff = high(period = "4 hours") - high(period = "4 hours")[1]; fourHoursLoDiff = low(period = "4 hours")[1] - low(period = "4 hours"); fourHoursPlusDM = if fourHoursHiDiff > fourHoursLoDiff and fourHoursHiDiff > 0 then fourHoursHiDiff else 0; fourHoursMinusDM =  if fourHoursLoDiff > fourHoursHiDiff and fourHoursLoDiff > 0 then fourHoursLoDiff else 0; fourHoursATR = MovingAverage(averageType, TrueRange(high(period = "4 hours"), close(period = "4 hours"),        low(period = "4 hours")), length); fourHoursAdx = DMI(length, averageType).ADX; fourHoursPlus = 100 * MovingAverage(averageType, fourHoursPlusDM, length) / fourHoursATR; fourHoursMinus = 100 * MovingAverage(averageType, fourHoursMinusDM, length) / fourHoursATR; fourHoursBullishSignal = fourHoursPlus crosses above fourHoursMinus; fourHoursBearishSignal = fourHoursPlus crosses below fourHoursMinus; fourHoursNarrowRange = if fourHoursMinus > fourHoursPlus then fourHoursMinus - fourHoursPlus else if fourHoursPlus > fourHoursMinus then fourHoursPlus - fourHoursMinus else 0; fourHoursNarrowRangeTest = fourHoursNarrowRange >= 10; fourHoursBullishZone = fourHoursPlus > fourHoursMinus and fourHoursNarrowRangeTest; fourHoursBearishZone = fourHoursPlus < fourHoursMinus and fourHoursNarrowRangeTest; fourHoursNeutralZone = !fourHoursBullishZone and !fourHoursBearishZone; } else { fourHoursPlus = 0; fourHoursMinus = 0; fourHoursAdx = 0; fourHoursPlusDM = 0; fourHoursMinusDM = 0; fourHoursBullishSignal = 0; fourHoursBearishSignal = 0; fourHoursNarrowRange = 0; fourHoursNarrowRangeTest = 0; fourHoursBullishZone = 0; fourHoursBearishZone = 0; fourHoursNeutralZone = 0; fourHoursHiDiff = 0; fourHoursLoDiff = 0; fourHoursATR = 0; } AddLabel(fourHoursBullishZone or fourHoursBearishZone or fourHoursNeutralZone, "4H", if fourHoursBullishZone then Color.GREEN else if fourHoursBearishZone then Color.RED else if fourHoursNeutralZone then Color.YELLOW else Color.GRAY); def twoHoursPlus; def twoHoursMinus; def twoHoursAdx; def twoHoursBullishSignal; def twoHoursBearishSignal; def twoHoursNarrowRange; def twoHoursNarrowRangeTest; def twoHoursBullishZone; def twoHoursBearishZone; def twoHoursNeutralZone; def twoHoursHiDiff; def twoHoursLoDiff; def twoHoursPlusDM; def twoHoursMinusDM; def twoHoursATR; if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS { twoHoursHiDiff = high(period = "2 hours") - high(period = "2 hours")[1]; twoHoursLoDiff = low(period = "2 hours")[1] - low(period = "2 hours"); twoHoursPlusDM = if twoHoursHiDiff > twoHoursLoDiff and twoHoursHiDiff > 0 then twoHoursHiDiff else 0; twoHoursMinusDM =  if twoHoursLoDiff > twoHoursHiDiff and twoHoursLoDiff > 0 then twoHoursLoDiff else 0; twoHoursATR = MovingAverage(averageType, TrueRange(high(period = "2 hours"), close(period = "2 hours"),        low(period = "2 hours")), length); twoHoursAdx = DMI(length, averageType).ADX; twoHoursPlus = 100 * MovingAverage(averageType, twoHoursPlusDM, length) / twoHoursATR; twoHoursMinus = 100 * MovingAverage(averageType, twoHoursMinusDM, length) / twoHoursATR; twoHoursBullishSignal = twoHoursPlus crosses above twoHoursMinus; twoHoursBearishSignal = twoHoursPlus crosses below twoHoursMinus; twoHoursNarrowRange = if twoHoursMinus > twoHoursPlus then twoHoursMinus - twoHoursPlus else if twoHoursPlus > twoHoursMinus then twoHoursPlus - twoHoursMinus else 0; twoHoursNarrowRangeTest = twoHoursNarrowRange >= 10; twoHoursBullishZone = twoHoursPlus > twoHoursMinus and twoHoursNarrowRangeTest; twoHoursBearishZone = twoHoursPlus < twoHoursMinus and twoHoursNarrowRangeTest; twoHoursNeutralZone = !twoHoursBullishZone and !twoHoursBearishZone; } else { twoHoursPlus = 0; twoHoursMinus = 0; twoHoursAdx = 0; twoHoursPlusDM = 0; twoHoursMinusDM = 0; twoHoursBullishSignal = 0; twoHoursBearishSignal = 0; twoHoursNarrowRange = 0; twoHoursNarrowRangeTest = 0; twoHoursBullishZone = 0; twoHoursBearishZone = 0; twoHoursNeutralZone = 0; twoHoursHiDiff = 0; twoHoursLoDiff = 0; twoHoursATR = 0; } AddLabel(twoHoursBullishZone or twoHoursBearishZone or twoHoursNeutralZone, "2H", if twoHoursBullishZone then Color.GREEN else if twoHoursBearishZone then Color.RED else if twoHoursNeutralZone then Color.YELLOW else Color.GRAY); def HourPlus; def HourMinus; def HourAdx; def HourBullishSignal; def HourBearishSignal; def HourNarrowRange; def HourNarrowRangeTest; def HourBullishZone; def HourBearishZone; def HourNeutralZone; def HourHiDiff; def HourLoDiff; def HourPlusDM; def HourMinusDM; def HourATR; if GetAggregationPeriod() <= AggregationPeriod.HOUR { HourHiDiff = high(period = "1 Hour") - high(period = "1 Hour")[1]; HourLoDiff = low(period = "1 Hour")[1] - low(period = "1 Hour"); HourPlusDM = if HourHiDiff > HourLoDiff and HourHiDiff > 0 then HourHiDiff else 0; HourMinusDM =  if HourLoDiff > HourHiDiff and HourLoDiff > 0 then HourLoDiff else 0; HourATR = MovingAverage(averageType, TrueRange(high(period = "1 Hour"), close(period = "1 Hour"),        low(period = "1 Hour")), length); HourAdx = DMI(length, averageType).ADX; HourPlus = 100 * MovingAverage(averageType, HourPlusDM, length) / HourATR; HourMinus = 100 * MovingAverage(averageType, HourMinusDM, length) / HourATR; HourBullishSignal = HourPlus crosses above HourMinus; HourBearishSignal = HourPlus crosses below HourMinus; HourNarrowRange = if HourMinus > HourPlus then HourMinus - HourPlus else if HourPlus > HourMinus then HourPlus - HourMinus else 0; HourNarrowRangeTest = HourNarrowRange >= 10; HourBullishZone = HourPlus > HourMinus and HourNarrowRangeTest; HourBearishZone = HourPlus < HourMinus and HourNarrowRangeTest; HourNeutralZone = !HourBullishZone and !HourBearishZone; } else { HourPlus = 0; HourMinus = 0; HourAdx = 0; HourPlusDM = 0; HourMinusDM = 0; HourBullishSignal = 0; HourBearishSignal = 0; HourNarrowRange = 0; HourNarrowRangeTest = 0; HourBullishZone = 0; HourBearishZone = 0; HourNeutralZone = 0; HourHiDiff = 0; HourLoDiff = 0; HourATR = 0; } AddLabel(HourBullishZone or HourBearishZone or HourNeutralZone, "H", if HourBullishZone then Color.GREEN else if HourBearishZone then Color.RED else if HourNeutralZone then Color.YELLOW else Color.GRAY); def thirtyMinutesPlus; def thirtyMinutesMinus; def thirtyMinutesAdx; def thirtyMinutesBullishSignal; def thirtyMinutesBearishSignal; def thirtyMinutesNarrowRange; def thirtyMinutesNarrowRangeTest; def thirtyMinutesBullishZone; def thirtyMinutesBearishZone; def thirtyMinutesNeutralZone; def thirtyMinutesHiDiff; def thirtyMinutesLoDiff; def thirtyMinutesPlusDM; def thirtyMinutesMinusDM; def thirtyMinutesATR; if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN { thirtyMinutesHiDiff = high(period = "30 Min") - high(period = "30 Min")[1]; thirtyMinutesLoDiff = low(period = "30 Min")[1] - low(period = "30 Min"); thirtyMinutesPlusDM = if thirtyMinutesHiDiff > thirtyMinutesLoDiff and thirtyMinutesHiDiff > 0 then thirtyMinutesHiDiff else 0; thirtyMinutesMinusDM =  if thirtyMinutesLoDiff > thirtyMinutesHiDiff and thirtyMinutesLoDiff > 0 then thirtyMinutesLoDiff else 0; thirtyMinutesATR = MovingAverage(averageType, TrueRange(high(period = "30 Min"), close(period = "30 Min"),        low(period = "30 Min")), length); thirtyMinutesAdx = DMI(length, averageType).ADX; thirtyMinutesPlus = 100 * MovingAverage(averageType, thirtyMinutesPlusDM, length) / thirtyMinutesATR; thirtyMinutesMinus = 100 * MovingAverage(averageType, thirtyMinutesMinusDM, length) / thirtyMinutesATR; thirtyMinutesBullishSignal = thirtyMinutesPlus crosses above thirtyMinutesMinus; thirtyMinutesBearishSignal = thirtyMinutesPlus crosses below thirtyMinutesMinus; thirtyMinutesNarrowRange = if thirtyMinutesMinus > thirtyMinutesPlus then thirtyMinutesMinus - thirtyMinutesPlus else if thirtyMinutesPlus > thirtyMinutesMinus then thirtyMinutesPlus - thirtyMinutesMinus else 0; thirtyMinutesNarrowRangeTest = thirtyMinutesNarrowRange >= 10; thirtyMinutesBullishZone = thirtyMinutesPlus > thirtyMinutesMinus and thirtyMinutesNarrowRangeTest; thirtyMinutesBearishZone = thirtyMinutesPlus < thirtyMinutesMinus and thirtyMinutesNarrowRangeTest; thirtyMinutesNeutralZone = !thirtyMinutesBullishZone and !thirtyMinutesBearishZone; } else { thirtyMinutesPlus = 0; thirtyMinutesMinus = 0; thirtyMinutesAdx = 0; thirtyMinutesPlusDM = 0; thirtyMinutesMinusDM = 0; thirtyMinutesBullishSignal = 0; thirtyMinutesBearishSignal = 0; thirtyMinutesNarrowRange = 0; thirtyMinutesNarrowRangeTest = 0; thirtyMinutesBullishZone = 0; thirtyMinutesBearishZone = 0; thirtyMinutesNeutralZone = 0; thirtyMinutesHiDiff = 0; thirtyMinutesLoDiff = 0; thirtyMinutesATR = 0; } AddLabel(thirtyMinutesBullishZone or thirtyMinutesBearishZone or thirtyMinutesNeutralZone, "30m", if thirtyMinutesBullishZone then Color.GREEN else if thirtyMinutesBearishZone then Color.RED else if thirtyMinutesNeutralZone then Color.YELLOW else Color.GRAY); def fifteenMinutesPlus; def fifteenMinutesMinus; def fifteenMinutesAdx; def fifteenMinutesBullishSignal; def fifteenMinutesBearishSignal; def fifteenMinutesNarrowRange; def fifteenMinutesNarrowRangeTest; def fifteenMinutesBullishZone; def fifteenMinutesBearishZone; def fifteenMinutesNeutralZone; def fifteenMinutesHiDiff; def fifteenMinutesLoDiff; def fifteenMinutesPlusDM; def fifteenMinutesMinusDM; def fifteenMinutesATR; if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN { fifteenMinutesHiDiff = high(period = "15 Min") - high(period = "15 Min")[1]; fifteenMinutesLoDiff = low(period = "15 Min")[1] - low(period = "15 Min"); fifteenMinutesPlusDM = if fifteenMinutesHiDiff > fifteenMinutesLoDiff and fifteenMinutesHiDiff > 0 then fifteenMinutesHiDiff else 0; fifteenMinutesMinusDM =  if fifteenMinutesLoDiff > fifteenMinutesHiDiff and fifteenMinutesLoDiff > 0 then fifteenMinutesLoDiff else 0; fifteenMinutesATR = MovingAverage(averageType, TrueRange(high(period = "15 Min"), close(period = "15 Min"),        low(period = "15 Min")), length); fifteenMinutesAdx = DMI(length, averageType).ADX; fifteenMinutesPlus = 100 * MovingAverage(averageType, fifteenMinutesPlusDM, length) / fifteenMinutesATR; fifteenMinutesMinus = 100 * MovingAverage(averageType, fifteenMinutesMinusDM, length) / fifteenMinutesATR; fifteenMinutesBullishSignal = fifteenMinutesPlus crosses above fifteenMinutesMinus; fifteenMinutesBearishSignal = fifteenMinutesPlus crosses below fifteenMinutesMinus; fifteenMinutesNarrowRange = if fifteenMinutesMinus > fifteenMinutesPlus then fifteenMinutesMinus - fifteenMinutesPlus else if fifteenMinutesPlus > fifteenMinutesMinus then fifteenMinutesPlus - fifteenMinutesMinus else 0; fifteenMinutesNarrowRangeTest = fifteenMinutesNarrowRange >= 10; fifteenMinutesBullishZone = fifteenMinutesPlus > fifteenMinutesMinus and fifteenMinutesNarrowRangeTest; fifteenMinutesBearishZone = fifteenMinutesPlus < fifteenMinutesMinus and fifteenMinutesNarrowRangeTest; fifteenMinutesNeutralZone = !fifteenMinutesBullishZone and !fifteenMinutesBearishZone; } else { fifteenMinutesPlus = 0; fifteenMinutesMinus = 0; fifteenMinutesAdx = 0; fifteenMinutesPlusDM = 0; fifteenMinutesMinusDM = 0; fifteenMinutesBullishSignal = 0; fifteenMinutesBearishSignal = 0; fifteenMinutesNarrowRange = 0; fifteenMinutesNarrowRangeTest = 0; fifteenMinutesBullishZone = 0; fifteenMinutesBearishZone = 0; fifteenMinutesNeutralZone = 0; fifteenMinutesHiDiff = 0; fifteenMinutesLoDiff = 0; fifteenMinutesATR = 0; } AddLabel(fifteenMinutesBullishZone or fifteenMinutesBearishZone or fifteenMinutesNeutralZone, "15m", if fifteenMinutesBullishZone then Color.GREEN else if fifteenMinutesBearishZone then Color.RED else if fifteenMinutesNeutralZone then Color.YELLOW else Color.GRAY); def tenMinutesPlus; def tenMinutesMinus; def tenMinutesAdx; def tenMinutesBullishSignal; def tenMinutesBearishSignal; def tenMinutesNarrowRange; def tenMinutesNarrowRangeTest; def tenMinutesBullishZone; def tenMinutesBearishZone; def tenMinutesNeutralZone; def tenMinutesHiDiff; def tenMinutesLoDiff; def tenMinutesPlusDM; def tenMinutesMinusDM; def tenMinutesATR; if GetAggregationPeriod() <= AggregationPeriod.TEN_MIN { tenMinutesHiDiff = high(period = "10 Min") - high(period = "10 Min")[1]; tenMinutesLoDiff = low(period = "10 Min")[1] - low(period = "10 Min"); tenMinutesPlusDM = if tenMinutesHiDiff > tenMinutesLoDiff and tenMinutesHiDiff > 0 then tenMinutesHiDiff else 0; tenMinutesMinusDM =  if tenMinutesLoDiff > tenMinutesHiDiff and tenMinutesLoDiff > 0 then tenMinutesLoDiff else 0; tenMinutesATR = MovingAverage(averageType, TrueRange(high(period = "10 Min"), close(period = "10 Min"),        low(period = "10 Min")), length); tenMinutesAdx = DMI(length, averageType).ADX; tenMinutesPlus = 100 * MovingAverage(averageType, tenMinutesPlusDM, length) / tenMinutesATR; tenMinutesMinus = 100 * MovingAverage(averageType, tenMinutesMinusDM, length) / tenMinutesATR; tenMinutesBullishSignal = tenMinutesPlus crosses above tenMinutesMinus; tenMinutesBearishSignal = tenMinutesPlus crosses below tenMinutesMinus; tenMinutesNarrowRange = if tenMinutesMinus > tenMinutesPlus then tenMinutesMinus - tenMinutesPlus else if tenMinutesPlus > tenMinutesMinus then tenMinutesPlus - tenMinutesMinus else 0; tenMinutesNarrowRangeTest = tenMinutesNarrowRange >= 10; tenMinutesBullishZone = tenMinutesPlus > tenMinutesMinus and tenMinutesNarrowRangeTest; tenMinutesBearishZone = tenMinutesPlus < tenMinutesMinus and tenMinutesNarrowRangeTest; tenMinutesNeutralZone = !tenMinutesBullishZone and !tenMinutesBearishZone; } else { tenMinutesPlus = 0; tenMinutesMinus = 0; tenMinutesAdx = 0; tenMinutesPlusDM = 0; tenMinutesMinusDM = 0; tenMinutesBullishSignal = 0; tenMinutesBearishSignal = 0; tenMinutesNarrowRange = 0; tenMinutesNarrowRangeTest = 0; tenMinutesBullishZone = 0; tenMinutesBearishZone = 0; tenMinutesNeutralZone = 0; tenMinutesHiDiff = 0; tenMinutesLoDiff = 0; tenMinutesATR = 0; } AddLabel(tenMinutesBullishZone or tenMinutesBearishZone or tenMinutesNeutralZone, "10m", if tenMinutesBullishZone then Color.GREEN else if tenMinutesBearishZone then Color.RED else if tenMinutesNeutralZone then Color.YELLOW else Color.GRAY); AssignPriceColor(if monthNeutralZone then color.yellow else if monthBullishZone then color.green else if monthBearishZone then color.red else color.yellow); def fiveMinutesPlus; def fiveMinutesMinus; def fiveMinutesAdx; def fiveMinutesBullishSignal; def fiveMinutesBearishSignal; def fiveMinutesNarrowRange; def fiveMinutesNarrowRangeTest; def fiveMinutesBullishZone; def fiveMinutesBearishZone; def fiveMinutesNeutralZone; def fiveMinutesHiDiff; def fiveMinutesLoDiff; def fiveMinutesPlusDM; def fiveMinutesMinusDM; def fiveMinutesATR; if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN { fiveMinutesHiDiff = high(period = "5 Min") - high(period = "5 Min")[1]; fiveMinutesLoDiff = low(period = "5 Min")[1] - low(period = "5 Min"); fiveMinutesPlusDM = if fiveMinutesHiDiff > fiveMinutesLoDiff and fiveMinutesHiDiff > 0 then fiveMinutesHiDiff else 0; fiveMinutesMinusDM =  if fiveMinutesLoDiff > fiveMinutesHiDiff and fiveMinutesLoDiff > 0 then fiveMinutesLoDiff else 0; fiveMinutesATR = MovingAverage(averageType, TrueRange(high(period = "5 Min"), close(period = "5 Min"),        low(period = "5 Min")), length); fiveMinutesAdx = DMI(length, averageType).ADX; fiveMinutesPlus = 100 * MovingAverage(averageType, fiveMinutesPlusDM, length) / fiveMinutesATR; fiveMinutesMinus = 100 * MovingAverage(averageType, fiveMinutesMinusDM, length) / fiveMinutesATR; fiveMinutesBullishSignal = fiveMinutesPlus crosses above fiveMinutesMinus; fiveMinutesBearishSignal = fiveMinutesPlus crosses below fiveMinutesMinus; fiveMinutesNarrowRange = if fiveMinutesMinus > fiveMinutesPlus then fiveMinutesMinus - fiveMinutesPlus else if fiveMinutesPlus > fiveMinutesMinus then fiveMinutesPlus - fiveMinutesMinus else 0; fiveMinutesNarrowRangeTest = fiveMinutesNarrowRange >= 10; fiveMinutesBullishZone = fiveMinutesPlus > fiveMinutesMinus and fiveMinutesNarrowRangeTest; fiveMinutesBearishZone = fiveMinutesPlus < fiveMinutesMinus and fiveMinutesNarrowRangeTest; fiveMinutesNeutralZone = !fiveMinutesBullishZone and !fiveMinutesBearishZone; } else { fiveMinutesPlus = 0; fiveMinutesMinus = 0; fiveMinutesAdx = 0; fiveMinutesPlusDM = 0; fiveMinutesMinusDM = 0; fiveMinutesBullishSignal = 0; fiveMinutesBearishSignal = 0; fiveMinutesNarrowRange = 0; fiveMinutesNarrowRangeTest = 0; fiveMinutesBullishZone = 0; fiveMinutesBearishZone = 0; fiveMinutesNeutralZone = 0; fiveMinutesHiDiff = 0; fiveMinutesLoDiff = 0; fiveMinutesATR = 0; } AddLabel(fiveMinutesBullishZone or fiveMinutesBearishZone or fiveMinutesNeutralZone, "5m", if fiveMinutesBullishZone then Color.GREEN else if fiveMinutesBearishZone then Color.RED else if fiveMinutesNeutralZone then Color.YELLOW else Color.GRAY); def fourMinutesPlus; def fourMinutesMinus; def fourMinutesAdx; def fourMinutesBullishSignal; def fourMinutesBearishSignal; def fourMinutesNarrowRange; def fourMinutesNarrowRangeTest; def fourMinutesBullishZone; def fourMinutesBearishZone; def fourMinutesNeutralZone; def fourMinutesHiDiff; def fourMinutesLoDiff; def fourMinutesPlusDM; def fourMinutesMinusDM; def fourMinutesATR; if GetAggregationPeriod() <= AggregationPeriod.FOUR_MIN { fourMinutesHiDiff = high(period = "4 Min") - high(period = "4 Min")[1]; fourMinutesLoDiff = low(period = "4 Min")[1] - low(period = "4 Min"); fourMinutesPlusDM = if fourMinutesHiDiff > fourMinutesLoDiff and fourMinutesHiDiff > 0 then fourMinutesHiDiff else 0; fourMinutesMinusDM =  if fourMinutesLoDiff > fourMinutesHiDiff and fourMinutesLoDiff > 0 then fourMinutesLoDiff else 0; fourMinutesATR = MovingAverage(averageType, TrueRange(high(period = "4 Min"), close(period = "4 Min"),        low(period = "4 Min")), length); fourMinutesAdx = DMI(length, averageType).ADX; fourMinutesPlus = 100 * MovingAverage(averageType, fourMinutesPlusDM, length) / fourMinutesATR; fourMinutesMinus = 100 * MovingAverage(averageType, fourMinutesMinusDM, length) / fourMinutesATR; fourMinutesBullishSignal = fourMinutesPlus crosses above fourMinutesMinus; fourMinutesBearishSignal = fourMinutesPlus crosses below fourMinutesMinus; fourMinutesNarrowRange = if fourMinutesMinus > fourMinutesPlus then fourMinutesMinus - fourMinutesPlus else if fourMinutesPlus > fourMinutesMinus then fourMinutesPlus - fourMinutesMinus else 0; fourMinutesNarrowRangeTest = fourMinutesNarrowRange >= 10; fourMinutesBullishZone = fourMinutesPlus > fourMinutesMinus and fourMinutesNarrowRangeTest; fourMinutesBearishZone = fourMinutesPlus < fourMinutesMinus and fourMinutesNarrowRangeTest; fourMinutesNeutralZone = !fourMinutesBullishZone and !fourMinutesBearishZone; } else { fourMinutesPlus = 0; fourMinutesMinus = 0; fourMinutesAdx = 0; fourMinutesPlusDM = 0; fourMinutesMinusDM = 0; fourMinutesBullishSignal = 0; fourMinutesBearishSignal = 0; fourMinutesNarrowRange = 0; fourMinutesNarrowRangeTest = 0; fourMinutesBullishZone = 0; fourMinutesBearishZone = 0; fourMinutesNeutralZone = 0; fourMinutesHiDiff = 0; fourMinutesLoDiff = 0; fourMinutesATR = 0; } AddLabel(fourMinutesBullishZone or fourMinutesBearishZone or fourMinutesNeutralZone, "4m", if fourMinutesBullishZone then Color.GREEN else if fourMinutesBearishZone then Color.RED else if fourMinutesNeutralZone then Color.YELLOW else Color.GRAY); def threeMinutesPlus; def threeMinutesMinus; def threeMinutesAdx; def threeMinutesBullishSignal; def threeMinutesBearishSignal; def threeMinutesNarrowRange; def threeMinutesNarrowRangeTest; def threeMinutesBullishZone; def threeMinutesBearishZone; def threeMinutesNeutralZone; def threeMinutesHiDiff; def threeMinutesLoDiff; def threeMinutesPlusDM; def threeMinutesMinusDM; def threeMinutesATR; if GetAggregationPeriod() <= AggregationPeriod.THREE_MIN { threeMinutesHiDiff = high(period = "3 Min") - high(period = "3 Min")[1]; threeMinutesLoDiff = low(period = "3 Min")[1] - low(period = "3 Min"); threeMinutesPlusDM = if threeMinutesHiDiff > threeMinutesLoDiff and threeMinutesHiDiff > 0 then threeMinutesHiDiff else 0; threeMinutesMinusDM =  if threeMinutesLoDiff > threeMinutesHiDiff and threeMinutesLoDiff > 0 then threeMinutesLoDiff else 0; threeMinutesATR = MovingAverage(averageType, TrueRange(high(period = "3 Min"), close(period = "3 Min"),        low(period = "3 Min")), length); threeMinutesAdx = DMI(length, averageType).ADX; threeMinutesPlus = 100 * MovingAverage(averageType, threeMinutesPlusDM, length) / threeMinutesATR; threeMinutesMinus = 100 * MovingAverage(averageType, threeMinutesMinusDM, length) / threeMinutesATR; threeMinutesBullishSignal = threeMinutesPlus crosses above threeMinutesMinus; threeMinutesBearishSignal = threeMinutesPlus crosses below threeMinutesMinus; threeMinutesNarrowRange = if threeMinutesMinus > threeMinutesPlus then threeMinutesMinus - threeMinutesPlus else if threeMinutesPlus > threeMinutesMinus then threeMinutesPlus - threeMinutesMinus else 0; threeMinutesNarrowRangeTest = threeMinutesNarrowRange >= 10; threeMinutesBullishZone = threeMinutesPlus > threeMinutesMinus and threeMinutesNarrowRangeTest; threeMinutesBearishZone = threeMinutesPlus < threeMinutesMinus and threeMinutesNarrowRangeTest; threeMinutesNeutralZone = !threeMinutesBullishZone and !threeMinutesBearishZone; } else { threeMinutesPlus = 0; threeMinutesMinus = 0; threeMinutesAdx = 0; threeMinutesPlusDM = 0; threeMinutesMinusDM = 0; threeMinutesBullishSignal = 0; threeMinutesBearishSignal = 0; threeMinutesNarrowRange = 0; threeMinutesNarrowRangeTest = 0; threeMinutesBullishZone = 0; threeMinutesBearishZone = 0; threeMinutesNeutralZone = 0; threeMinutesHiDiff = 0; threeMinutesLoDiff = 0; threeMinutesATR = 0; } AddLabel(threeMinutesBullishZone or threeMinutesBearishZone or threeMinutesNeutralZone, "3m", if threeMinutesBullishZone then Color.GREEN else if threeMinutesBearishZone then Color.RED else if threeMinutesNeutralZone then Color.YELLOW else Color.GRAY); def twoMinutesPlus; def twoMinutesMinus; def twoMinutesAdx; def twoMinutesBullishSignal; def twoMinutesBearishSignal; def twoMinutesNarrowRange; def twoMinutesNarrowRangeTest; def twoMinutesBullishZone; def twoMinutesBearishZone; def twoMinutesNeutralZone; def twoMinutesHiDiff; def twoMinutesLoDiff; def twoMinutesPlusDM; def twoMinutesMinusDM; def twoMinutesATR; if GetAggregationPeriod() <= AggregationPeriod.TWO_MIN { twoMinutesHiDiff = high(period = "2 Min") - high(period = "2 Min")[1]; twoMinutesLoDiff = low(period = "2 Min")[1] - low(period = "2 Min"); twoMinutesPlusDM = if twoMinutesHiDiff > twoMinutesLoDiff and twoMinutesHiDiff > 0 then twoMinutesHiDiff else 0; twoMinutesMinusDM =  if twoMinutesLoDiff > twoMinutesHiDiff and twoMinutesLoDiff > 0 then twoMinutesLoDiff else 0; twoMinutesATR = MovingAverage(averageType, TrueRange(high(period = "2 Min"), close(period = "2 Min"),        low(period = "2 Min")), length); twoMinutesAdx = DMI(length, averageType).ADX; twoMinutesPlus = 100 * MovingAverage(averageType, twoMinutesPlusDM, length) / twoMinutesATR; twoMinutesMinus = 100 * MovingAverage(averageType, twoMinutesMinusDM, length) / twoMinutesATR; twoMinutesBullishSignal = twoMinutesPlus crosses above twoMinutesMinus; twoMinutesBearishSignal = twoMinutesPlus crosses below twoMinutesMinus; twoMinutesNarrowRange = if twoMinutesMinus > twoMinutesPlus then twoMinutesMinus - twoMinutesPlus else if twoMinutesPlus > twoMinutesMinus then twoMinutesPlus - twoMinutesMinus else 0; twoMinutesNarrowRangeTest = twoMinutesNarrowRange >= 10; twoMinutesBullishZone = twoMinutesPlus > twoMinutesMinus and twoMinutesNarrowRangeTest; twoMinutesBearishZone = twoMinutesPlus < twoMinutesMinus and twoMinutesNarrowRangeTest; twoMinutesNeutralZone = !twoMinutesBullishZone and !twoMinutesBearishZone; } else { twoMinutesPlus = 0; twoMinutesMinus = 0; twoMinutesAdx = 0; twoMinutesPlusDM = 0; twoMinutesMinusDM = 0; twoMinutesBullishSignal = 0; twoMinutesBearishSignal = 0; twoMinutesNarrowRange = 0; twoMinutesNarrowRangeTest = 0; twoMinutesBullishZone = 0; twoMinutesBearishZone = 0; twoMinutesNeutralZone = 0; twoMinutesHiDiff = 0; twoMinutesLoDiff = 0; twoMinutesATR = 0; } AddLabel(twoMinutesBullishZone or twoMinutesBearishZone or twoMinutesNeutralZone, "2m", if twoMinutesBullishZone then Color.GREEN else if twoMinutesBearishZone then Color.RED else if twoMinutesNeutralZone then Color.YELLOW else Color.GRAY); def minutesPlus; def minutesMinus; def minutesAdx; def minutesBullishSignal; def minutesBearishSignal; def minutesNarrowRange; def minutesNarrowRangeTest; def minutesBullishZone; def minutesBearishZone; def minutesNeutralZone; def minutesHiDiff; def minutesLoDiff; def minutesPlusDM; def minutesMinusDM; def minutesATR; if GetAggregationPeriod() <= AggregationPeriod.MIN { minutesHiDiff = high(period = "1 Min") - high(period = "1 Min")[1]; minutesLoDiff = low(period = "1 Min")[1] - low(period = "1 Min"); minutesPlusDM = if minutesHiDiff > minutesLoDiff and minutesHiDiff > 0 then minutesHiDiff else 0; minutesMinusDM =  if minutesLoDiff > minutesHiDiff and minutesLoDiff > 0 then minutesLoDiff else 0; minutesATR = MovingAverage(averageType, TrueRange(high(period = "1 Min"), close(period = "1 Min"),        low(period = "1 Min")), length); minutesAdx = DMI(length, averageType).ADX; minutesPlus = 100 * MovingAverage(averageType, minutesPlusDM, length) / minutesATR; minutesMinus = 100 * MovingAverage(averageType, minutesMinusDM, length) / minutesATR; minutesBullishSignal = minutesPlus crosses above minutesMinus; minutesBearishSignal = minutesPlus crosses below minutesMinus; minutesNarrowRange = if minutesMinus > minutesPlus then minutesMinus - minutesPlus else if minutesPlus > minutesMinus then minutesPlus - minutesMinus else 0; minutesNarrowRangeTest = minutesNarrowRange >= 10; minutesBullishZone = minutesPlus > minutesMinus and minutesNarrowRangeTest; minutesBearishZone = minutesPlus < minutesMinus and minutesNarrowRangeTest; minutesNeutralZone = !minutesBullishZone and !minutesBearishZone; } else { minutesPlus = 0; minutesMinus = 0; minutesAdx = 0; minutesPlusDM = 0; minutesMinusDM = 0; minutesBullishSignal = 0; minutesBearishSignal = 0; minutesNarrowRange = 0; minutesNarrowRangeTest = 0; minutesBullishZone = 0; minutesBearishZone = 0; minutesNeutralZone = 0; minutesHiDiff = 0; minutesLoDiff = 0; minutesATR = 0; } AddLabel(minutesBullishZone or minutesBearishZone or minutesNeutralZone, "1m", if minutesBullishZone then Color.GREEN else if minutesBearishZone then Color.RED else if minutesNeutralZone then Color.YELLOW else Color.GRAY);

Conclusion & Download

Thanks for watching the eleventh episode of “How to thinkScript”… I hope you enjoyed the un-polished, raw version of the entire process, from ideation to the final-ish product.

And a special thank you to Dick K. for working through the DMI ideas and sharing observations around the Dynamic RSI.

Click the button below to download the Multiple Time Frame (MTF) DMI Indicator