SUPER INDIBOT - EMA Ribbon Trend

Quantum-Edge-Capital · study · 93 行 · 点赞 55 · 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/
// © Quantum-Edge-Capital
//@version=6
indicator("SUPER INDIBOT - EMA Ribbon Trend", overlay=true, max_labels_count=50)
 
// ---------------- Inputs ----------------
grpLen = "Ribbon Lengths"
len1 = input.int(5, "EMA 1", minval=1, group=grpLen)
len2 = input.int(11, "EMA 2", minval=1, group=grpLen)
len3 = input.int(15, "EMA 3", minval=1, group=grpLen)
len4 = input.int(18, "EMA 4", minval=1, group=grpLen)
len5 = input.int(21, "EMA 5", minval=1, group=grpLen)
len6 = input.int(24, "EMA 6", minval=1, group=grpLen)
len7 = input.int(28, "EMA 7", minval=1, group=grpLen)
len8 = input.int(34, "EMA 8", minval=1, group=grpLen)
 
grpVis = "Visuals"
bullColor = input.color(color.new(#00c2a8, 0), "Bullish color", group=grpVis)
bearColor = input.color(color.new(#ff8a3d, 0), "Bearish color", group=grpVis)
neutralColor = input.color(color.new(color.gray, 40), "Neutral color", group=grpVis)
showTable = input.bool(true, "Show status table", group=grpVis)
showSignals = input.bool(true, "Show trend-flip signals", group=grpVis)
 
// ---------------- EMAs ----------------
ema1 = ta.ema(close, len1)
ema2 = ta.ema(close, len2)
ema3 = ta.ema(close, len3)
ema4 = ta.ema(close, len4)
ema5 = ta.ema(close, len5)
ema6 = ta.ema(close, len6)
ema7 = ta.ema(close, len7)
ema8 = ta.ema(close, len8)
 
// ---------------- Trend strength / alignment ----------------
bullCount = 0
bullCount := bullCount + (ema1 > ema2 ? 1 : 0)
bullCount := bullCount + (ema2 > ema3 ? 1 : 0)
bullCount := bullCount + (ema3 > ema4 ? 1 : 0)
bullCount := bullCount + (ema4 > ema5 ? 1 : 0)
bullCount := bullCount + (ema5 > ema6 ? 1 : 0)
bullCount := bullCount + (ema6 > ema7 ? 1 : 0)
bullCount := bullCount + (ema7 > ema8 ? 1 : 0)
 
strength = bullCount / 7.0
ribbonColor = color.from_gradient(strength, 0.0, 1.0, bearColor, bullColor)
 
fullyBull = bullCount == 7
fullyBear = bullCount == 0
trendState = fullyBull ? "Strong Up" : fullyBear ? "Strong Down" : strength > 0.5 ? "Mild Up" : strength < 0.5 ? "Mild Down" : "Mixed"
 
// ---------------- Plots ----------------
p1 = plot(ema1, "EMA 5", color=ribbonColor, linewidth=1)
p2 = plot(ema2, "EMA 11", color=ribbonColor, linewidth=1)
p3 = plot(ema3, "EMA 15", color=ribbonColor, linewidth=1)
p4 = plot(ema4, "EMA 18", color=ribbonColor, linewidth=1)
p5 = plot(ema5, "EMA 21", color=ribbonColor, linewidth=1)
p6 = plot(ema6, "EMA 24", color=ribbonColor, linewidth=1)
p7 = plot(ema7, "EMA 28", color=ribbonColor, linewidth=1)
p8 = plot(ema8, "EMA 34", color=ribbonColor, linewidth=2)
 
fill(p1, p8, color=color.new(ribbonColor, 85), title="Ribbon Fill")
 
// ---------------- Trend-flip signals ----------------
var bool wasBull = false
var bool wasBear = false
 
bullFlip = fullyBull and not wasBull
bearFlip = fullyBear and not wasBear
 
if fullyBull
    wasBull := true
    wasBear := false
else if fullyBear
    wasBear := true
    wasBull := false
else
    wasBull := false
    wasBear := false
 
plotshape(showSignals and bullFlip, title="Buy Signal", style=shape.triangleup, location=location.belowbar, color=bullColor, size=size.tiny, text="BUY")
plotshape(showSignals and bearFlip, title="Sell Signal", style=shape.triangledown, location=location.abovebar, color=bearColor, size=size.tiny, text="SELL")
 
alertcondition(bullFlip, title="Ribbon Bull Flip", message="SUPER INDIBOT: EMA ribbon turned fully bullish")
alertcondition(bearFlip, title="Ribbon Bear Flip", message="SUPER INDIBOT: EMA ribbon turned fully bearish")
 
// ---------------- Status table ----------------
var table statusTable = table.new(position.top_right, 2, 2, bgcolor=color.new(color.gray, 85), border_width=1)
 
if showTable and barstate.islast
    table.cell(statusTable, 0, 0, "Trend", text_color=color.white, bgcolor=color.new(color.gray, 70))
    table.cell(statusTable, 1, 0, trendState, text_color=ribbonColor, bgcolor=color.new(color.gray, 70))
    table.cell(statusTable, 0, 1, "Strength", text_color=color.white, bgcolor=color.new(color.gray, 75))
    table.cell(statusTable, 1, 1, str.tostring(math.round(strength * 100)) + "%", text_color=ribbonColor, bgcolor=color.new(color.gray, 75))

← 返回列表