本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © NJ_Algo
//@version=6
indicator("Normalized ROC [NJ]", "VNR", overlay = false)
// ███╗ ██╗ ██╗ █████╗ ██╗ ██████╗ ██████╗
// ████╗ ██║ ██║ ██╔══██╗██║ ██╔════╝ ██╔═══██╗
// ██╔██╗ ██║ ██║ ███████║██║ ██║ ███╗██║ ██║
// ██║╚██╗██║ ██║ ██╔══██║██║ ██║ ██║██║ ██║
// ██║ ╚████║ ██╗ ██║ ██║ ██║██║ ██║ ██║██║ ██║
// ██║ ╚███║ ╚████╔╝ ██║ ██║███████╗╚██████╔╝╚██████╔╝
// ╚═╝ ╚══╝ ╚═══╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝
// ✧═════════════════✧
// ║ INPUTS ║
// ✧═════════════════✧
const string g1 = "✧ DISPLAY ✧"
colorMode = input.string("Colored", "Color mode", options = ["Colored", "Neutral"], group = g1)
dispCandles = input.bool(true, "Color candles", group = g1)
const string g2 = "✧ CALCULATION ✧"
normLen = input.int(22, "Normalization length", group = g2)
smthLen = input.int(8, "Smoothing length", group = g2)
smthMulti = input.float(0.4, "Smoothing multiplier", 0.05, 1.0, 0.05, group = g2)
// ✧══════════════════════✧
// ║ CALCULATION ║
// ✧══════════════════════✧
// Smoothed and capped ROC
roc = ta.roc(close, 30)
smthRoc = ta.sma(roc, smthLen)
capRoc = math.max(math.min(smthRoc, 10), -10)
// Variables
var float nRoc = na
var float snRoc = na
// Normalization and smoothing
lowRoc = ta.lowest(capRoc, normLen)
highRoc = ta.highest(capRoc, normLen)
nRoc := (highRoc - lowRoc) > 0 ? (capRoc - lowRoc) / (highRoc - lowRoc) * 100 : nz(nRoc[1])
snRoc := na(snRoc[1]) ? nRoc : snRoc[1] + smthMulti * (nRoc - snRoc[1])
// ✧═══════════════════════✧
// ║ FINAL SIGNAL ║
// ✧═══════════════════════✧
var int NJ = 0
if snRoc > 50
NJ := 1
else if snRoc < 50
NJ := -1
// ✧════════════════✧
// ║ PLOTS ║
// ✧════════════════✧
// Colors
longCol = colorMode == "Colored" ? color.rgb(0, 136, 100) : colorMode == "Neutral" ? color.rgb(179, 179, 179) : na
shortCol = colorMode == "Colored" ? color.rgb(120, 0, 32) : colorMode == "Neutral" ? color.rgb(60, 60, 60) : na
sigCol = NJ == 1 ? longCol : NJ == -1 ? shortCol : na
// Color candles
plotcandle(
open, high, low, close,
"Colored candles",
dispCandles ? sigCol : na,
dispCandles ? sigCol : na,
bordercolor = dispCandles ? sigCol : na,
display = display.all - display.status_line - display.price_scale,
force_overlay = true)
// Display ROC and threshold
plot(snRoc, "ROC", sigCol, 2)
hline(50, "Threshold", longCol)
// Glow
upperCol = NJ == 1 ? color.new(color.black, 100) : color.new(shortCol, 40)
lowerCol = NJ == 1 ? color.new(longCol, 40) : color.new(color.black, 100)
upper = NJ == 1 ? 50 : snRoc
lower = NJ == 1 ? snRoc : 50
upperPlot = plot(NJ == 1 ? 50 : snRoc, "Upper glow", color = na)
lowerPlot = plot(NJ == 1 ? snRoc : 50, "Lower glow", color = na)
fill(upperPlot, lowerPlot, upper, lower, upperCol, lowerCol)