# ADX Crossover Indicator System for ThinkorSwim

#### jox51

##### Member
2019 Donor
The below indicator is a replica of the ADX system that Chris Moody coded for TradingView at the link below. Feel free to edit and use as you wish. He uses the Gann Swing Hi Low indicator, I used the PSAR indicator as an alternate. Some images attached below. Code:
``````#
# This study attempts to replicate Chris Moody's ADX System for TOS. All credit goes to him. This study incorporates the GannHiLo study to determine the swing hi's and lows.

# Take a look at the video here where he explains this system.

# This study attempts to catch the beginning of a swing move in a trending underlying. What you want to do is waiting for crossovers of the DI+/DI- respectively while the ADX is beginning to Trend above 20 while the ParabolicSAR is in a supportive Swing High or Low. The buy/sell signals will alert you to this. Use your own discretion.

# When the ADX is over 40, the trend is exhausted and you should be looking at exiting your positions.

# Load this indicator along with the ADXMod and DMIMod indicators.

# Gann High Low
# Converted by theelderwand

input HPeriod= 13;
input LPeriod= 21;

def HLd = if close > SimpleMovingAvg(high, HPeriod)
then 1
else (if close< SimpleMovingAvg(low, LPeriod)
then -1
else 0);

def HLv = if HLd != 0 then HLd else 0;

plot HiLo = if HLv == -1
then SimpleMovingAvg(high, HPeriod)
else SimpleMovingAvg(low, LPeriod);

HiLo.AssignValueColor(if HLv==-1 then Color.Red else Color.Green);

#Below code is for ADX and DMI confirmation

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

def hiDiff = high - high;
def loDiff = low - low;

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 "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, length);

#Defines buy and sell setups

def buy = ADX > 20 && ADX > ADX && "DI+" crosses above "DI-" && HLv<>-1;

def sell = ADX > 20 && ADX > ADX && "DI-" crosses above "DI+" && HLv==-1;

# Plot Signals
plot sellsignal = sell;
sellsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sellsignal.SetDefaultColor(Color.CYAN);
sellsignal.SetLineWeight(1);``````

DMIMod code below https://tos.mx/CUaFybK

Incorporated the GannHiLow study to stay true to the original system.

Thanks @BenTen for pointing me to the GannHiLo study on this site.

Last edited:

#### diazlaz

##### Well-known member
2019 Donor
VIP
Hi @jox51 -awesome ty! - the buy and sell plots are not plotting not sure if the HLv criteria is valid I changed the buy from <> to != and it started the buy signal, haven't seen a sell condition triggered yet. Have you compared GANN to the PSAR? Something I added to backlog to test. thanks for the conversion.

Here's the built-in ADX crossover script from ThinkorSwim

Code:
``````#wizard text: ADX crosses
#wizard input: crossingType
#wizard input: threshold
#wizard text: Inputs: length:
#wizard input: length

input length = 14;
input crossingType = {default above, below};
input threshold = 20;
input averageType = AverageType.WILDERS;

plot signal = crosses(DMI(length, averageType).ADX, threshold, crossingType == CrossingType.above);

signal.DefineColor("Above", GetColor(0));
signal.DefineColor("Below", GetColor(1));
signal.AssignValueColor(if crossingType == CrossingType.above then signal.color("Above") else signal.color("Below"));

signal.SetPaintingStrategy(if crossingType == CrossingType.above
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);``````

• dnnfin

#### raphiecee

##### New member
I am trying to add a column on my watch list that will tell me how many bars in a row a specified condition has been meet
The condition is DMI+ is greater than or equal to 25 and DMI- is less than or equal to 20 and the ADX is greater than or = to 20
So when this first happens I would like the column to say the number 1 and if it happens for a second candle in a row I would like it to say the number 2 and so on until it doesn't happen than it would drop off my list

#### hashy

##### Member
Does anyone know of a multi-time frame ADX script? From what I gather because ADX calls up another study (DMI) it isn't as simple as input Period = aggregationPeriod.DAY; or similar.

i.e., I want to be on a 1m chart but have an ADX indicator showing me ADX on 5m.

Thanks!

#### Pensar

##### Well-known member
VIP
@hashy Here is a multi-timeframe ADX -
Code:
``````# Multi-Timeframe ADX
# based on DMI indicator code by TD Ameritrade IP Company, Inc. (c) 2008-2020

declare lower;

input length = 14;
input averageType = AverageType.WILDERS;
input aggregation = aggregationperiod.FIVE_MIN;
def h = high(period = aggregation);
def l = low(period = aggregation);
def c = close(period = aggregation);

def hiDiff = h - h;
def loDiff = l - l;

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(h, c, l), length);

def "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def "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);

• zeller427, hashy and BenTen

#### tomsk

##### Well-known member
VIP
@MBF Here's the scan code for ADX above 24. Place this in the scanner. I obtained 214 hits on the S&P 500 on a daily aggregation scan

Code:
``````input length = 14;
input averageType = AverageType.WILDERS;
plot scan = ADX > 24;``````

• J007RMC

#### malinois1983

##### New member
VIP
So I don't own the code. I found it on the web but it is what I was looking for. I also just want to say sorry if this is a stupid question. Is there anyway to add a condition to this code that the ADX has to be above 25?

Code:
``````input length = 14;
input averageType = AverageType.WILDERS;
input threshold = 20;
input lookBack = 90;
def hiDiff = high - high;
def loDiff = low - low;
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 diPlus = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def diMinus = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def DX = if (diPlus + diMinus > 0) then 100 * AbsValue(diPlus - diMinus) / (diPlus + diMinus) else 0;
def diPlusCrossesAbove = diPlus < diMinus and diPlus > diMinus;
def diPlusCrossesBelow = diPlus > diMinus and diPlus < diMinus;
# use this scan to check for DI+ crossing above DI-
plot scan = Highest(diPlusCrossesAbove, lookBack) < 1 and diPlusCrossesAbove;
# use this scan to check for DI+ crossing below DI-
#plot scan = Highest(diPlusCrossesBelow, lookBack) < 1 and diPlusCrossesBelow;``````

Last edited by a moderator:

##### Well-known member
VIP
@malinois1983 Here you go... Notice the 1st line and the addition to the end of your plot line...

Ruby:
``````def adx = ADX() >= 25;
input length = 14;
input averageType = AverageType.WILDERS;
input threshold = 20;
input lookBack = 90;
def hiDiff = high - high;
def loDiff = low - low;
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 diPlus = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def diMinus = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def DX = if (diPlus + diMinus > 0) then 100 * AbsValue(diPlus - diMinus) / (diPlus + diMinus) else 0;
def diPlusCrossesAbove = diPlus < diMinus and diPlus > diMinus;
def diPlusCrossesBelow = diPlus > diMinus and diPlus < diMinus;
# use this scan to check for DI+ crossing above DI-
plot scan = Highest(diPlusCrossesAbove, lookBack) < 1 and diPlusCrossesAbove;
# use this scan to check for DI+ crossing below DI-
#plot scan = Highest(diPlusCrossesBelow, lookBack) < 1 and diPlusCrossesBelow and adx;`````` ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• Add-ons and resources
• 1 full year of unlimited support

### Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
{"ft_lang_label":"__label__en","ft_lang_prob":0.71073437,"math_prob":0.8272275,"size":3413,"snap":"2022-40-2023-06","text_gpt3_token_len":984,"char_repetition_ratio":0.10706952,"word_repetition_ratio":0.14198783,"special_character_ratio":0.2677996,"punctuation_ratio":0.1594203,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9566467,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12],"im_url_duplicate_count":[null,2,null,2,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-09-26T21:56:22Z\",\"WARC-Record-ID\":\"<urn:uuid:bc74fefe-0481-4f63-b20b-557a99047086>\",\"Content-Length\":\"95932\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bb65ae9d-cc41-4765-a465-5a59a6752698>\",\"WARC-Concurrent-To\":\"<urn:uuid:dbcab3f5-e1ad-4a58-9d00-68eda1829b30>\",\"WARC-IP-Address\":\"104.21.34.158\",\"WARC-Target-URI\":\"https://usethinkscript.com/threads/adx-crossover-indicator-system-for-thinkorswim.1031/\",\"WARC-Payload-Digest\":\"sha1:XSDHSKDNKCEHHQ2NOIEQN2QT3NFILYS4\",\"WARC-Block-Digest\":\"sha1:MUKHBKFSYLTPE56J4GMXWGMNFA7PI7K3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030334942.88_warc_CC-MAIN-20220926211042-20220927001042-00586.warc.gz\"}"}