Gold Compass Lite

Gold_Compass_Pro · study · 152 行 · 点赞 23 · TradingView 原页

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

Pine Script

//@version=6
indicator("Gold Compass Lite", overlay=true, max_labels_count=500)
 
//==================================================
// DISPLAY
//==================================================
panelMode = input.string("Full", "Panel Mode", options=["Full", "Compact"])
 
//==================================================
// INPUTS
//==================================================
fastLen        = input.int(50,  "Fast EMA")
slowLen        = input.int(100, "Slow EMA")
macroLen       = input.int(200, "Macro EMA")
pullbackEMALen = input.int(21,  "Pullback EMA")
 
stochLen = input.int(14, "Stochastic Length")
atrLen   = input.int(14, "ATR Length")
 
//==================================================
// CALCULATIONS
//==================================================
fastEMA     = ta.ema(close, fastLen)
slowEMA     = ta.ema(close, slowLen)
macroEMA    = ta.ema(close, macroLen)
pullbackEMA = ta.ema(close, pullbackEMALen)
 
rawK   = ta.stoch(close, high, low, stochLen)
stochK = ta.sma(rawK, 3)
stochD = ta.sma(stochK, 3)
 
atrValue = ta.atr(atrLen)
 
//==================================================
// TREND
//==================================================
bullMacro = close > macroEMA and fastEMA > slowEMA
bearMacro = close < macroEMA and fastEMA < slowEMA
 
watchLong  = bullMacro
watchShort = bearMacro
 
//==================================================
// CONTEXT LOGIC
//==================================================
bullRetracement = bullMacro and close < pullbackEMA
bearRetracement = bearMacro and close > pullbackEMA
 
bullMomentumShift = ta.crossover(stochK, stochD)
bearMomentumShift = ta.crossunder(stochK, stochD)
 
isCompression = ta.stdev(close, 8) < atrValue * 0.3
 
//==================================================
// INTERPRETATION
//==================================================
signalType =
     bearRetracement ? "Short-Term Retracement" :
     bullRetracement ? "Short-Term Retracement" :
     bullMomentumShift ? "Momentum Shift" :
     bearMomentumShift ? "Momentum Shift" :
     isCompression ? "Compression" :
     watchShort ? "Bearish Pressure" :
     watchLong ? "Bullish Pressure" :
     "No Clear Signal"
 
possibleAction =
     bearRetracement ? "Watch Short" :
     bullRetracement ? "Watch Long" :
     bullMomentumShift ? "Stay Patient" :
     bearMomentumShift ? "Stay Patient" :
     watchShort ? "Watch Short" :
     watchLong ? "Watch Long" :
     "Neutral"
 
//==================================================
// VISUALS
//==================================================
plot(macroEMA, "200 EMA", color=color.yellow, linewidth=2)
plot(pullbackEMA, "21 EMA", color=color.purple, linewidth=2)
 
//==================================================
// PANEL COLORS
//==================================================
trendBg =
     bullMacro ? color.new(color.green, 10) :
     bearMacro ? color.new(color.red, 10) :
     color.new(color.gray, 20)
 
signalBg =
     signalType == "Bullish Pressure" ? color.new(color.green, 20) :
     signalType == "Bearish Pressure" ? color.new(color.red, 20) :
     signalType == "Compression" ? color.new(color.orange, 20) :
     signalType == "Momentum Shift" ? color.new(color.yellow, 20) :
     color.new(color.gray, 30)
 
actionBg =
     possibleAction == "Watch Long" ? color.new(color.green, 10) :
     possibleAction == "Watch Short" ? color.new(color.red, 10) :
     color.new(color.gray, 30)
 
//==================================================
// PANEL TABLE
//==================================================
txtSize = size.small
var table dash = table.new(position.top_right, 2, 6, border_width=1)
 
if barstate.islast
    for r = 0 to 5
        table.cell(dash, 0, r, "", bgcolor=color.new(color.black, 100))
        table.cell(dash, 1, r, "", bgcolor=color.new(color.black, 100))
 
    if panelMode == "Full"
        table.cell(dash, 0, 0, "Gold Compass Lite", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 0, "Market Context", text_color=color.white, bgcolor=color.new(color.gray, 20), text_size=txtSize)
 
        table.cell(dash, 0, 1, "Trend", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 1, bullMacro ? "Bullish" : bearMacro ? "Bearish" : "Neutral", text_color=color.black, bgcolor=trendBg, text_size=txtSize)
 
        table.cell(dash, 0, 2, "Signal", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 2, signalType, text_color=color.black, bgcolor=signalBg, text_size=txtSize)
 
        table.cell(dash, 0, 3, "Action", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 3, possibleAction, text_color=color.black, bgcolor=actionBg, text_size=txtSize)
 
        table.cell(dash, 0, 4, "Market State", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 4,
             isCompression ? "Compression" :
             bullRetracement or bearRetracement ? "Pullback" :
             bullMacro or bearMacro ? "Trending" :
             "Neutral",
             text_color=color.black, bgcolor=color.new(color.gray, 10), text_size=txtSize)
 
        table.cell(dash, 0, 5, "Momentum", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 5,
             stochK > stochD ? "Bullish" :
             stochK < stochD ? "Bearish" :
             "Neutral",
             text_color=color.black, bgcolor=color.new(color.gray, 10), text_size=txtSize)
 
    else
        table.cell(dash, 0, 0, "Gold Compass Lite", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 0, "Compact", text_color=color.white, bgcolor=color.new(color.gray, 20), text_size=txtSize)
 
        table.cell(dash, 0, 1, "Trend", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 1, bullMacro ? "Bull" : bearMacro ? "Bear" : "Neutral", text_color=color.black, bgcolor=trendBg, text_size=txtSize)
 
        table.cell(dash, 0, 2, "Signal", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 2, signalType, text_color=color.black, bgcolor=signalBg, text_size=txtSize)
 
        table.cell(dash, 0, 3, "Action", text_color=color.white, bgcolor=color.black, text_size=txtSize)
        table.cell(dash, 1, 3, possibleAction, text_color=color.black, bgcolor=actionBg, text_size=txtSize)

← 返回列表