Dynamic RSI Trend [NJ]

NJ_Algo · study · 94 行 · 点赞 257 · TradingView 原页

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

Pine Script

// 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("Dynamic RSI Trend [NJ]", "DRT", 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 ✧"
rsiSmoothLen = input.int(20, "RSI smoothing", group = g2)
atrSmoothLen = input.int(50, "ATR smoothing", group=g2)
thr1         = input.int(54, "Threshold 1", group = g2)
thr2         = input.int(45, "Threshold 2", group = g2)
 
// ✧══════════════════════✧
// ║      CALCULATION     ║
// ✧══════════════════════✧
 
// Get RSI
rsi = ta.rsi(close, 14)
smoothRsi = ta.ema(rsi, rsiSmoothLen)
 
// Smoothed RSI ATR
rsiTR = math.abs(smoothRsi - smoothRsi[1])
rsiATR = ta.rma(rsiTR, 14)
avgATR = ta.sma(rsiATR, atrSmoothLen)
 
// Volatility deviation
atrDelta = rsiATR - avgATR
 
// Adaptive thresholds
adapThr1 = math.max(0.0, math.min(100.0, thr1 + atrDelta * 4))
adapThr2 = math.max(0.0, math.min(100.0, thr2 + atrDelta * 4))
 
// ✧═══════════════════════✧
// ║      FINAL SIGNAL      ║
// ✧═══════════════════════✧
 
var int NJ = 0
 
if ta.crossover(smoothRsi, adapThr1) or ta.crossover(smoothRsi, adapThr2)
    NJ := 1
else if ta.crossunder(smoothRsi, adapThr2) or ta.crossunder(smoothRsi, adapThr1)
    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 RSI and thresholds
plot(smoothRsi, "Smoothed RSI", sigCol, 2)
plot(adapThr1, "Threshold 1", longCol)
plot(adapThr2, "Threshold 2", shortCol)
 
// 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 : smoothRsi
lower = NJ == 1 ? smoothRsi : 50
 
upperPlot = plot(NJ == 1 ? 50 : smoothRsi, "Upper glow", color = na)
lowerPlot = plot(NJ == 1 ? smoothRsi : 50, "Lower glow", color = na)
 
fill(upperPlot, lowerPlot, upper, lower, upperCol, lowerCol)

← 返回列表