MACD-V Volatility Normalisation

Riliza · study · 53 行 · 点赞 1,650 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jamiedubauskas
 
//@version=5
indicator(title = "MACD-V Volatility Normalisation", shorttitle = "MACD-V Volatility Normalisation", overlay = false)
 
// asking for inputs for the parameters of the MACD-V indicator
fast_len = input.int(title = "MACD Fast Length", defval = 12, minval = 1, group = "Indicator Settings")
slow_len = input.int(title = "MACD Slow Length", defval = 26, minval = 1, group = "Indicator Settings")
source = input.source(title = "Source", defval = close, group = "Indicator Settings")
signal_len = input.int(title = "Signal Line Smoothing Length", defval = 9, minval = 1, group = "Indicator Settings")
atr_len = input.int(title = "ATR Length", defval = 26, minval = 1, tooltip = "Used to gauge volatility to standardize MACD. Keep at the same value as the MACD Slow Length parameter for best results", group = "Indicator Settings")
 
overbought_bounds = input.int(title = "Overbought Bounds", defval = 150, minval = 1, tooltip = "Threshold for MACD Line to cross above to be considered overbought. Original author of MACD-V placed it at 150.")
oversold_bounds = input.int(title = "Oversold Bounds", defval = -150, maxval = -1, tooltip = "Threshold for MACD Line to cross below to be considered oversold. Original author of MACD-V placed it at -150.")
rally_bounds = input.int(title = "Rally Bounds", defval = 50, minval = 1)
rebound_bounds = input.int(title = "Rebound Bounds", defval = -50, maxval = -1)
 
 
// indicator calculation
macd = ((ta.ema(source, fast_len) - ta.ema(source, slow_len)) / ta.atr(atr_len)) * 100
signal = ta.ema(macd, signal_len)
hist = macd - signal
 
 
// asking for input for the color of the macd and signal lines
macd_color = input.color(title = "MACD Line", defval = #2962FF, group = "Color Settings")
signal_color = input.color(title = "Signal Line", defval = #FF6D00, group = "Color Settings")
 
// getting colors for the histogram
col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
 
macd_plot = plot(title = "MACD Line", series = macd, color = macd_color)
plot(title = "Signal Line", series = signal, color = signal_color)
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
 
// plotting horizontal lines for overbought and oversold bounds
upper_band = plot(overbought_bounds, title = "Overbought Bounds", color = color.new(color.green,30))
lower_band = plot(oversold_bounds, title = "Oversold Bounds", color = color.new(color.red,30))
upper_band2 = plot(rally_bounds, title = "Rally Bounds", color = color.new(color.green,30))
lower_band2 = plot(rebound_bounds, title = "Rebound Bounds", color = color.new(color.red,30))
fill(upper_band2, lower_band2, color = color.new(color.yellow, 65), title = "Normal Bounds Background Ranging")
fill(upper_band, upper_band2, color = color.new(color.green, 65), title = "Normal Bounds Background Rallying")
fill(lower_band, lower_band2, color = color.new(color.red, 65), title = "Normal Bounds Background Rebounding ")
 
// filling between the lines and the bounds if Rally or Rebound
overbought_color2 = macd > rally_bounds ? color.new(color.green,30) : na
oversold_color2 = macd < rebound_bounds ? color.new(color.red,30) : na
fill(macd_plot, upper_band2, color = overbought_color2, title = "Overbought Fill2")
fill(lower_band2, macd_plot, color = oversold_color2, title = "Oversold Fill2")

← 返回列表