25% Candle-Level

Remigius1974 · study · 36 行 · 点赞 18 · TradingView 原页

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

Pine Script

//@version=6
indicator("25% Candle-Level", overlay=true)
 
// === Eingaben ===
pct      = input.float(25.0, "Percent", minval=0.0, maxval=100.0, step=1.0) / 100
lineLen  = input.int(10, "Length (Candles)", minval=1)
bullCol  = input.color(color.green, "Color bullish")
bearCol  = input.color(color.red, "Color bearish")
 
// === Berechnung des Levels für eine Kerze ===
calcLevel(float o, float h, float l, float c) =>
    bull = c >= o
    float lvl = na
    if bull
        lvl := c - (c - l) * pct
    else
        lvl := c + (h - c) * pct
    lvl
 
useOffset1 = not barstate.isconfirmed
 
o_ = useOffset1 ? open[1]  : open
h_ = useOffset1 ? high[1]  : high
l_ = useOffset1 ? low[1]   : low
c_ = useOffset1 ? close[1] : close
startIdx = useOffset1 ? bar_index - 1 : bar_index
 
level  = calcLevel(o_, h_, l_, c_)
isBull = c_ >= o_
 
// === Eine einzige Linie, wird jedes Mal ersetzt ===
var line ln = na
if barstate.islast
    line.delete(ln)
    ln := line.new(startIdx, level, startIdx + lineLen, level,
         color=isBull ? bullCol : bearCol, width=1)

← 返回列表