Percentile Momentum | NAL

NordicAlphaLab · study · 73 行 · 点赞 297 · 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/
// © NordicAlphaLab
 
//@version=6
indicator("Percentile Momentum | NAL", "Percentile Momentum", overlay = false)
 
//                                     ███╗   ██╗ █████╗ ██╗
//                                     ████╗  ██║██╔══██╗██║
//                                     ██╔██╗ ██║███████║██║
//                                     ██║╚██╗██║██╔══██║██║
//                                     ██║ ╚████║██║  ██║███████╗
//                                     ╚═╝  ╚═══╝╚═╝  ╚═╝╚══════╝
 
// ══════════════════════════════════════ ◈ Visuals ◈ ══════════════════════════════════════
 
string col_mode = input.string("Standard", title = "Color Mode", group = "Visuals", options = ["Standard", "Nordic", "Simple"])
 
[col_up, col_dn, col_nu] = switch col_mode
    "Standard" => [color.rgb(0, 255, 200), color.rgb(32, 94, 144), color.gray]
    "Nordic"   => [color.rgb(46, 161, 255), color.rgb(150, 154, 169), color.gray]
    "Simple"   => [color.lime, color.red, color.gray]
 
// ══════════════════════════════════════ ◈ Inputs ◈ ══════════════════════════════════════
 
string G1 = "Parameters"
 
float Src = input.source(close, "Source", group = G1)
int Len = input.int(40, "Length", minval = 1, group = G1)
int Per = input.int(70, "Percentile", group = G1, minval = 0, maxval = 100)
 
int upperPer = input.int(70, "Upper Percentile Threshold", group = G1, minval = 0, maxval = 100)
int lowerPer = input.int(10, "Lower Percentile Threshold", group = G1, minval = 0, maxval = 100)
 
// ══════════════════════════════════════ ◈ Logic ◈ ══════════════════════════════════════
 
float Percentile = ta.percentile_linear_interpolation(Src, Len, Per)
float Momentum   = Src - Percentile
 
float upperB = ta.percentile_linear_interpolation(Momentum, Len, upperPer)
float lowerB = ta.percentile_linear_interpolation(Momentum, Len, lowerPer)
 
// ══════════════════════════════════════ ◈ NAL State ◈ ══════════════════════════════════════
 
bool Bullish = Momentum > upperB and close > Percentile
bool Bearish = Momentum < lowerB
 
int NAL = 0
NAL := Bullish ? 1 : Bearish ? -1 : nz(NAL[1], 0)
 
bool BullishFlip = barstate.isconfirmed and NAL == 1 and nz(NAL[1], 0) != 1
bool BearishFlip = barstate.isconfirmed and NAL == -1 and nz(NAL[1], 0) != -1
 
color col = NAL == 1 ? col_up : NAL == -1 ? col_dn : col_nu
 
// ══════════════════════════════════════ ◈ Plots ◈ ══════════════════════════════════════
 
momPlot = plot(Momentum, "Percentile Adaptive RSI", color = col, linewidth = 2)
 
UpperPlot = plot(NAL == 1 ? na : upperB, "Upper Percentile Band", color = color.gray, style = plot.style_linebr)
LowerPlot = plot(NAL == -1 ? na : lowerB, "Lower Percentile Band", color = color.gray, style = plot.style_linebr)
 
// NAL gradients fade from the RSI toward the opposite percentile band.
fill(momPlot, LowerPlot, NAL == 1 ? Momentum : na, NAL == 1 ? lowerB : na, color.new(col_up, 50), color.new(col_up, 100), title = "Bullish Gradient", fillgaps = false)
 
fill(momPlot, UpperPlot, NAL == -1 ? upperB : na, NAL == -1 ? Momentum : na, color.new(col_dn, 100), color.new(col_dn, 50), title = "Bearish Gradient", fillgaps = false)
 
// Trend-colored candles.
plotcandle(open, high, low, close, "Bar Color", color = col, wickcolor = col, bordercolor = col, display = display.pane, force_overlay = true)
 
// ══════════════════════════════════════ ◈ Alerts ◈ ══════════════════════════════════════
 
alertcondition(BullishFlip, "Percentile Adaptive RSI Bullish", "Percentile Adaptive RSI changed to bullish on {{ticker}}.")
alertcondition(BearishFlip, "Percentile Adaptive RSI Bearish", "Percentile Adaptive RSI changed to bearish on {{ticker}}.")

← 返回列表