Trinity MidPoint ATR Ribbon

EMA34TRADER · study · 41 行 · 点赞 242 · 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/
// © EMA34TRADER
//@version=6
indicator("Trinity MidPoint ATR Ribbon", overlay=true)
 
// ─────────────────────────────────────────
// Inputs with tooltips
// ─────────────────────────────────────────
midLen = input.int(15, "Midpoint Length", minval=1, tooltip="Lookback for the midpoint of highest high + lowest low. 15 was the best in the 1,725-test study on NQ 60-min.")
atrLen = input.int(5, "ATR Length", minval=1, tooltip="ATR period used for the space. 5 worked well with the 0.4 multiplier. Try 5, 20, or 40.")
mult   = input.float(0.4, "ATR Multiplier", minval=0.0, step=0.1, tooltip="How many ATRs above/below the midpoint to place the ribbon edges. 0.4 was the example that scored well. Lower = tighter ribbon, higher = wider.")
 
bullColor = input.color(color.new(color.lime, 80), "Bullish Fill")
bearColor = input.color(color.new(color.red, 80), "Bearish Fill")
midColor  = input.color(color.gray, "Midpoint Line")
lineWidth = input.int(1, "Ribbon Edge Width", minval=1)
 
// ─────────────────────────────────────────
// Calculations
// ─────────────────────────────────────────
mid     = (ta.highest(high, midLen) + ta.lowest(low, midLen)) / 2
atr     = ta.atr(atrLen)
upper   = mid + mult * atr
lower   = mid - mult * atr
 
// Bullish when price is above the midpoint
isBull  = close > mid
 
// ─────────────────────────────────────────
// Plots
// ─────────────────────────────────────────
midPlot   = plot(mid,   "Midpoint", color=midColor, linewidth=1)
upperPlot = plot(upper, "Upper",    color=isBull ? color.lime : color.red, linewidth=lineWidth)
lowerPlot = plot(lower, "Lower",    color=isBull ? color.lime : color.red, linewidth=lineWidth)
 
// Ribbon fill (flips green/red)
fill(upperPlot, lowerPlot, color=isBull ? bullColor : bearColor, title="Ribbon")
 
// Optional: plot the raw breakout levels more visibly
plot(upper, "Long Level",  color=color.new(color.lime, 0), linewidth=1, style=plot.style_linebr)
plot(lower, "Short Level", color=color.new(color.red, 0),  linewidth=1, style=plot.style_linebr)

← 返回列表