本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// © Mishundare | IntelligenceFlow
// Successor of "1min - EMA Scalping System" (2020), fully rewritten.
indicator("Twin Ribbon Scalper [@Mishu]", shorttitle = "TRS", overlay = true)
// ─────────────────────────── Inputs ───────────────────────────
grpF = "Fast ribbon (EMA lengths)"
f1 = input.int(3, "1", minval = 1, inline = "f", group = grpF)
f2 = input.int(5, "2", minval = 1, inline = "f", group = grpF)
f3 = input.int(8, "3", minval = 1, inline = "f", group = grpF)
f4 = input.int(10, "4", minval = 1, inline = "f2", group = grpF)
f5 = input.int(12, "5", minval = 1, inline = "f2", group = grpF)
f6 = input.int(15, "6", minval = 1, inline = "f2", group = grpF)
grpS = "Slow ribbon (EMA lengths)"
s1 = input.int(30, "1", minval = 1, inline = "s", group = grpS)
s2 = input.int(35, "2", minval = 1, inline = "s", group = grpS)
s3 = input.int(40, "3", minval = 1, inline = "s", group = grpS)
s4 = input.int(45, "4", minval = 1, inline = "s2", group = grpS)
s5 = input.int(50, "5", minval = 1, inline = "s2", group = grpS)
s6 = input.int(55, "6", minval = 1, inline = "s2", group = grpS)
grpQ = "Setup rules"
needAlign = input.bool(true, "Slow ribbon must be in order", group = grpQ, tooltip = "Long: slow EMAs stacked short above long. Short: the opposite.")
minGapAtr = input.float(0.0, "Min. gap between ribbons (× ATR)", minval = 0.0, step = 0.05, group = grpQ, tooltip = "0 = any visible gap. Higher values filter out weak separations.")
atrLen = input.int(14, "ATR length", minval = 1, group = grpQ)
useTrend = input.bool(true, "Trend filter", group = grpQ, tooltip = "Long setups only above the trend EMA, short setups only below.")
trendLen = input.int(200, "Trend EMA length", minval = 1, group = grpQ)
grpV = "Display"
showLines = input.bool(true, "Ribbon lines", group = grpV)
showFill = input.bool(true, "Ribbon fill", group = grpV)
showMarks = input.bool(true, "Setup markers", group = grpV)
showTrend = input.bool(true, "Trend EMA", group = grpV)
colorBars = input.bool(false, "Color bars by ribbon state", group = grpV)
showTable = input.bool(true, "Status table", group = grpV)
colBull = input.color(#26a69a, "Bullish", group = grpV)
colBear = input.color(#ef5350, "Bearish", group = grpV)
// ─────────────────────────── Calculation ───────────────────────────
ef1 = ta.ema(close, f1)
ef2 = ta.ema(close, f2)
ef3 = ta.ema(close, f3)
ef4 = ta.ema(close, f4)
ef5 = ta.ema(close, f5)
ef6 = ta.ema(close, f6)
es1 = ta.ema(close, s1)
es2 = ta.ema(close, s2)
es3 = ta.ema(close, s3)
es4 = ta.ema(close, s4)
es5 = ta.ema(close, s5)
es6 = ta.ema(close, s6)
trendEma = ta.ema(close, trendLen)
atr = ta.atr(atrLen)
fastTop = math.max(ef1, ef2, ef3, ef4, ef5, ef6)
fastBot = math.min(ef1, ef2, ef3, ef4, ef5, ef6)
slowTop = math.max(es1, es2, es3, es4, es5, es6)
slowBot = math.min(es1, es2, es3, es4, es5, es6)
slowBullOrder = es1 > es2 and es2 > es3 and es3 > es4 and es4 > es5 and es5 > es6
slowBearOrder = es1 < es2 and es2 < es3 and es3 < es4 and es4 < es5 and es5 < es6
gapUp = (fastBot - slowTop) / atr // > 0: fast ribbon fully above slow ribbon
gapDn = (slowBot - fastTop) / atr // > 0: fast ribbon fully below slow ribbon
bullState = gapUp > minGapAtr and (not needAlign or slowBullOrder) and (not useTrend or close > trendEma)
bearState = gapDn > minGapAtr and (not needAlign or slowBearOrder) and (not useTrend or close < trendEma)
// Setups are only confirmed on bar close -> no repainting of markers or alerts
longSetup = bullState and not bullState[1] and barstate.isconfirmed
shortSetup = bearState and not bearState[1] and barstate.isconfirmed
// ─────────────────────────── Plots ───────────────────────────
fastCol = bullState ? colBull : bearState ? colBear : color.gray
slowCol = slowBullOrder ? colBull : slowBearOrder ? colBear : color.gray
plot(showLines ? ef1 : na, "Fast 1", color.new(fastCol, 30))
plot(showLines ? ef2 : na, "Fast 2", color.new(fastCol, 30))
plot(showLines ? ef3 : na, "Fast 3", color.new(fastCol, 30))
plot(showLines ? ef4 : na, "Fast 4", color.new(fastCol, 30))
plot(showLines ? ef5 : na, "Fast 5", color.new(fastCol, 30))
plot(showLines ? ef6 : na, "Fast 6", color.new(fastCol, 0), 2)
plot(showLines ? es1 : na, "Slow 1", color.new(slowCol, 0), 2)
plot(showLines ? es2 : na, "Slow 2", color.new(slowCol, 40))
plot(showLines ? es3 : na, "Slow 3", color.new(slowCol, 40))
plot(showLines ? es4 : na, "Slow 4", color.new(slowCol, 40))
plot(showLines ? es5 : na, "Slow 5", color.new(slowCol, 40))
plot(showLines ? es6 : na, "Slow 6", color.new(slowCol, 40))
pFT = plot(fastTop, "Fast top", color = na, editable = false, display = display.none)
pFB = plot(fastBot, "Fast bottom", color = na, editable = false, display = display.none)
pST = plot(slowTop, "Slow top", color = na, editable = false, display = display.none)
pSB = plot(slowBot, "Slow bottom", color = na, editable = false, display = display.none)
fill(pFT, pFB, color = showFill ? color.new(fastCol, 80) : na, title = "Fast ribbon fill")
fill(pST, pSB, color = showFill ? color.new(slowCol, 88) : na, title = "Slow ribbon fill")
plot(showTrend ? trendEma : na, "Trend EMA", close > trendEma ? colBull : colBear, 1, plot.style_circles)
plotshape(showMarks and longSetup, "Long setup", shape.triangleup, location.belowbar, colBull, size = size.small)
plotshape(showMarks and shortSetup, "Short setup", shape.triangledown, location.abovebar, colBear, size = size.small)
barcolor(colorBars ? (bullState ? colBull : bearState ? colBear : color.gray) : na)
// ─────────────────────────── Status table ───────────────────────────
var table tbl = table.new(position.top_right, 2, 2, border_width = 1)
if showTable and barstate.islast
stateTxt = bullState ? "Bullish" : bearState ? "Bearish" : "Neutral"
stateCol = bullState ? colBull : bearState ? colBear : color.gray
gapVal = math.max(gapUp, gapDn)
table.cell(tbl, 0, 0, "Ribbon state", text_color = color.white, bgcolor = color.new(color.black, 30))
table.cell(tbl, 1, 0, stateTxt, text_color = color.white, bgcolor = stateCol)
table.cell(tbl, 0, 1, "Gap (× ATR)", text_color = color.white, bgcolor = color.new(color.black, 30))
table.cell(tbl, 1, 1, gapVal > 0 ? str.tostring(gapVal, "#.##") : "overlap", text_color = color.white, bgcolor = color.new(color.black, 30))
// ─────────────────────────── Alerts ───────────────────────────
trendCross = ta.cross(close, trendEma) and barstate.isconfirmed
alertcondition(longSetup, "Long setup", "TRS: long setup on {{ticker}} ({{interval}}), close {{close}}")
alertcondition(shortSetup, "Short setup", "TRS: short setup on {{ticker}} ({{interval}}), close {{close}}")
alertcondition(longSetup or shortSetup, "Any setup", "TRS: new setup on {{ticker}} ({{interval}}), close {{close}}")
alertcondition(trendCross, "Trend EMA cross", "TRS: price crossed the trend EMA on {{ticker}} ({{interval}})")
if longSetup
alert("TRS long setup | " + syminfo.ticker + " | " + timeframe.period + " | close " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)
if shortSetup
alert("TRS short setup | " + syminfo.ticker + " | " + timeframe.period + " | close " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)