本页源码来自 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/
// © CryptoNejc
//@version=6
indicator("KAMA Adaptive RSI [NJ]", "KAR", overlay = false, behind_chart = 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 ✧"
src = input.source(open, "RSI source", group = g2)
rsiLen = input.int(12, "RSI length", group = g2)
smoothLen = input.int(13, "Smoothing length", group = g2)
longThr = input.int(40, "Long threshold", group = g2)
shortThr = input.int(50, "Short threshold", group = g2)
// ✧══════════════════════✧
// ║ CALCULATION ║
// ✧══════════════════════✧
// Kaufman's Adaptive Moving Average
kama(src, len) =>
num = math.abs(src - src[len])
float den = 0
for i = 0 to len - 1
den += math.abs(src[i] - src[i+1])
er = num / den
sc = math.pow(er * (2/3 - 2/31) + 2/31, 2)
float kama = na
kama := na(kama[1]) ? src : kama[1] + sc * (src - kama[1])
// Smoothed RSI
rsi = ta.rsi(src, rsiLen)
smoothRsi = kama(rsi, smoothLen)
// ✧═══════════════════════✧
// ║ FINAL SIGNAL ║
// ✧═══════════════════════✧
var int NJ = 0
if ta.crossover(smoothRsi, longThr) or ta.crossover(smoothRsi, shortThr)
NJ := 1
if ta.crossunder(smoothRsi, shortThr) or ta.crossunder(smoothRsi, longThr)
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
plot(smoothRsi, "Smoothed RSI", sigCol, 2)
hline(longThr, "Long threshold", longCol)
hline(shortThr, "Short threshold", shortCol)