xmd79

Trending/Ranging

Apr 18th, 2021
2,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. // 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.
  2. // 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)
  3. // 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
  4. // 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
  5. // I personally use it when trading every day.
  6.  
  7. //@version=4
  8. study("Trending/Ranging", resolution = "", overlay = true)
  9.  
  10. // Inputs
  11. atrColor = input(title = "ATR Color", type = input.color, defval = color.green)
  12. adxColor = input(title = "ADX Color", type = input.color, defval = color.blue)
  13. rsiColor = input(title = "RSI Color", type = input.color, defval = color.yellow)
  14.  
  15.  
  16. // ATR
  17. atr = rma(tr(true), 14)
  18. sma = sma(atr, 20)
  19.  
  20. atrTrending = if atr > sma
  21. true
  22. else
  23. false
  24.  
  25. // ADX
  26. adxlen = 14
  27. dilen = 14
  28. dirmov(len) =>
  29. up = change(high)
  30. down = -change(low)
  31. plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
  32. minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
  33. truerange = rma(tr, len)
  34. plus = fixnan(100 * rma(plusDM, len) / truerange)
  35. minus = fixnan(100 * rma(minusDM, len) / truerange)
  36. [plus, minus]
  37. adx(dilen, adxlen) =>
  38. [plus, minus] = dirmov(dilen)
  39. sum = plus + minus
  40. adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
  41. sig = adx(dilen, adxlen)
  42.  
  43. adxTrending = if sig > 20
  44. true
  45. else
  46. false
  47.  
  48. // RSI
  49. up = rma(max(change(close), 0), 14)
  50. down = rma(-min(change(close), 0), 14)
  51. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
  52.  
  53. rsiTrending = if rsi > 60 or rsi < 40
  54. true
  55. else
  56. false
  57.  
  58.  
  59. // Plots
  60. bgcolor(atrTrending ? color.green : na)
  61. bgcolor(adxTrending ? color.red : na)
  62. bgcolor(rsiTrending ? color.yellow : na)
Advertisement
Add Comment
Please, Sign In to add comment