Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Volatility Adjusted Momentum", "VAM", timeframe = "", timeframe_gaps = true)
- // +++++++++++++++++++++
- // ++ INPUT ++
- // +++++++++++++++++++++
- // Momentum
- lenMom = input.int(10, "Length", 1, group = "Momentum Settings")
- srcMom = input.source(close, "Source", group = "Momentum Settings")
- upLvl = input.float(3, "Upper Level", group = "Momentum Settings")
- dnLvl = input.float(-3, "Lower Level", group = "Momentum Settings")
- // Volatility
- optVol = input.string("STD | Standard Deviation", "Volatility",
- ["ATR | Average True Range", "STD | Standard Deviation"], group = "Volatility Settings")
- lenVol = input.int(10, "Length", 1, group = "Volatility Settings")
- // +++++++++++++++++++++
- // ++ CALCULATION ++
- // +++++++++++++++++++++
- mom = srcMom - srcMom[lenMom]
- std = ta.stdev(srcMom, lenVol)
- atr = ta.sma(ta.tr, lenVol)
- // Volatility Adjusted Momentum
- val = mom/(optVol == "STD | Standard Deviation" ? std : atr)
- // +++++++++++++++++++++
- // ++ PLOT ++
- // +++++++++++++++++++++
- plot(val, "Volatility Adjusted Momentum",
- val >= upLvl ? color.red : val <= dnLvl ? color.green : color.yellow, 2)
- hline(0, "Mid Line", color.gray)
- upperLine = hline(upLvl, "Upper Line", color.gray)
- lowerLine = hline(dnLvl, "Lower Line", color.gray)
- fill(upperLine, lowerLine, color.new(color.purple, 90), "Background Fill")
Advertisement
Add Comment
Please, Sign In to add comment