xmd79

Volatility Adjusted Momentum

Oct 26th, 2022
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1.  
  2. //@version=5
  3. indicator("Volatility Adjusted Momentum", "VAM", timeframe = "", timeframe_gaps = true)
  4.  
  5. // +++++++++++++++++++++
  6. // ++ INPUT ++
  7. // +++++++++++++++++++++
  8. // Momentum
  9. lenMom = input.int(10, "Length", 1, group = "Momentum Settings")
  10. srcMom = input.source(close, "Source", group = "Momentum Settings")
  11. upLvl = input.float(3, "Upper Level", group = "Momentum Settings")
  12. dnLvl = input.float(-3, "Lower Level", group = "Momentum Settings")
  13.  
  14. // Volatility
  15. optVol = input.string("STD | Standard Deviation", "Volatility",
  16. ["ATR | Average True Range", "STD | Standard Deviation"], group = "Volatility Settings")
  17. lenVol = input.int(10, "Length", 1, group = "Volatility Settings")
  18.  
  19.  
  20. // +++++++++++++++++++++
  21. // ++ CALCULATION ++
  22. // +++++++++++++++++++++
  23. mom = srcMom - srcMom[lenMom]
  24. std = ta.stdev(srcMom, lenVol)
  25. atr = ta.sma(ta.tr, lenVol)
  26.  
  27. // Volatility Adjusted Momentum
  28. val = mom/(optVol == "STD | Standard Deviation" ? std : atr)
  29.  
  30.  
  31. // +++++++++++++++++++++
  32. // ++ PLOT ++
  33. // +++++++++++++++++++++
  34. plot(val, "Volatility Adjusted Momentum",
  35. val >= upLvl ? color.red : val <= dnLvl ? color.green : color.yellow, 2)
  36.  
  37. hline(0, "Mid Line", color.gray)
  38.  
  39. upperLine = hline(upLvl, "Upper Line", color.gray)
  40. lowerLine = hline(dnLvl, "Lower Line", color.gray)
  41. fill(upperLine, lowerLine, color.new(color.purple, 90), "Background Fill")
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment