Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This indicator is useful for determining which markets you want to trade. If you're a channel trader, you want to look for ranging markets.
- // If you are a trend trader, you want to look for trending markets. This indicator includes three other indicators (ATR [combined with an SMA], ADX, and RSI)
- // to determine whether the market is trending or ranging. It also includes a time frame specification for identifying the long term behavior of the security
- // you are trading. Simply select which indicators you want to use to determine market behavior. This indicator is a great tool to use to filter trades, and
- // I personally use it when trading every day.
- //@version=4
- study("Trending/Ranging", resolution = "", overlay = true)
- // Inputs
- atrColor = input(title = "ATR Color", type = input.color, defval = color.green)
- adxColor = input(title = "ADX Color", type = input.color, defval = color.blue)
- rsiColor = input(title = "RSI Color", type = input.color, defval = color.yellow)
- // ATR
- atr = rma(tr(true), 14)
- sma = sma(atr, 20)
- atrTrending = if atr > sma
- true
- else
- false
- // ADX
- adxlen = 14
- dilen = 14
- dirmov(len) =>
- up = change(high)
- down = -change(low)
- plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
- minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
- truerange = rma(tr, len)
- plus = fixnan(100 * rma(plusDM, len) / truerange)
- minus = fixnan(100 * rma(minusDM, len) / truerange)
- [plus, minus]
- adx(dilen, adxlen) =>
- [plus, minus] = dirmov(dilen)
- sum = plus + minus
- adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
- sig = adx(dilen, adxlen)
- adxTrending = if sig > 20
- true
- else
- false
- // RSI
- up = rma(max(change(close), 0), 14)
- down = rma(-min(change(close), 0), 14)
- rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
- rsiTrending = if rsi > 60 or rsi < 40
- true
- else
- false
- // Plots
- bgcolor(atrTrending ? color.green : na)
- bgcolor(adxTrending ? color.red : na)
- bgcolor(rsiTrending ? color.yellow : na)
Advertisement
Add Comment
Please, Sign In to add comment