xmd79

Moving Average Contrarian Indicator

May 26th, 2023
217
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © LeafAlgo
  3.  
  4. //@version=5
  5. indicator("Moving Average Contrarian Indicator", overlay=false)
  6.  
  7. length = input(40, "Moving Average Length")
  8. src = input(close)
  9.  
  10. // Calculate moving average
  11. ma = ta.sma(src, length)
  12.  
  13. // Calculate distance from price to moving average
  14. distance = src - ma
  15.  
  16. // Calculate normalized MACI
  17. distance_min = ta.lowest(distance, length)
  18. distance_max = ta.highest(distance, length)
  19. maci = ((distance - distance_min) / (distance_max - distance_min)) * 100
  20.  
  21. // Determine barcolor and background color conditions
  22. maci_sma = ta.sma(maci, length)
  23. barC = maci > maci_sma and maci > 30 ? color.lime : maci < maci_sma and maci < 70 ? color.fuchsia : color.yellow
  24. backC = maci > maci_sma and maci > 30 ? color.new(color.lime, 80) : maci < maci_sma and maci < 70 ? color.new(color.fuchsia, 80) : color.new(color.yellow, 80)
  25.  
  26. // Color
  27. barcolor(barC)
  28. bgcolor(backC, transp=70)
  29.  
  30. // Plotting
  31. plot(maci, title="MACI", color=barC, style=plot.style_histogram, linewidth=4)
  32. plot(maci_sma, title='MACI SMA', color=color.maroon, linewidth=2)
  33.  
  34. // Overbought and oversold levels
  35. hline(70, "Overbought", color=color.fuchsia)
  36. hline(30, "Oversold", color=color.lime)
Advertisement
Comments
  • # text 0.12 KB | 0 0
    1. download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment