本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// ============================================================
// Super CCI Indicator - Pine Script V6
// Enhanced Visual Version with Vivid Colors
// ============================================================
// 【Script Summary】
// Indicator Name: Super CCI (Commodity Channel Index)
// Indicator Type: Sub-chart Indicator
// Core Function: Overbought/Oversold indicator based on CCI
//
// 【Buy/Sell Signal Generation Logic (Based on Duality Principle)】
// - Strong Buy: CCI crosses above CI line in oversold zone (CCI < -100)
// - Normal Buy: CCI crosses above CI line in weak zone (-100 <= CCI < 0)
// - Strong Sell: CCI crosses below CI line in overbought zone (CCI > 100)
// - Normal Sell: CCI crosses below CI line in strong zone (0 < CCI <= 100)
// ============================================================
// Calculate average deviation (avgDev equivalent)
calcAvgDev(source, calcLength) =>
float meanValue = ta.sma(source, calcLength)
float sumDev = 0.0
for i = 0 to calcLength - 1
sumDev := sumDev + math.abs(source[i] - meanValue)
sumDev / calcLength
indicator("[blackcat] L3 Super CCI Indicator", overlay=false, max_bars_back=5000)
// === Input Parameters ===
int inputCciLength = input.int(11, "CCI Length", minval=1)
int inputCiLength = input.int(5, "CI (EMA) Length", minval=1)
// === Color Theme Inputs ===
color inputColorOverbought = input.color(color.new(#ff1744, 0), "Overbought Zone Color")
color inputColorOversold = input.color(color.new(#00e676, 0), "Oversold Zone Color")
color inputColorNeutral = input.color(color.new(#2962ff, 0), "Neutral Zone Color")
color inputColorBullish = input.color(#00ff88, "Bullish Momentum")
color inputColorBearish = input.color(#ff4757, "Bearish Momentum")
color inputColorCi = input.color(#ffd700, "CI Line Color")
// Calculate typical price: (high + low + close) / 3
float calcTypicalPrice = (high + low + close) / 3
// Calculate CCI indicator
float calcCciValue = (calcTypicalPrice - ta.sma(calcTypicalPrice, inputCciLength)) / (0.015 * calcAvgDev(calcTypicalPrice, inputCciLength))
// Calculate CI line: EMA of CCI
float calcCiValue = ta.ema(calcCciValue, inputCiLength)
// Define reference levels
float levelUpperBound = 100
float levelMiddleBound = 0
float levelLowerBound = -100
float levelExtremeUpper = 200
float levelExtremeLower = -200
// === Gradient Background Fills for Zones ===
// Overbought zone fill (above 100) - Red gradient
bgcolor(calcCciValue > levelUpperBound ? color.new(inputColorOverbought, 85) : na, title="Overbought Zone BG")
// Oversold zone fill (below -100) - Green gradient
bgcolor(calcCciValue < levelLowerBound ? color.new(inputColorOversold, 85) : na, title="Oversold Zone BG")
// === Enhanced Reference Lines ===
// Extreme levels (dashed)
hline(levelExtremeUpper, "Extreme +200", color=color.new(#ff1744, 50), linestyle=hline.style_dashed, linewidth=1)
hline(levelExtremeLower, "Extreme -200", color=color.new(#00e676, 50), linestyle=hline.style_dashed, linewidth=1)
// Main levels with gradient effect
hline(levelUpperBound, "Overbought (+100)", color=color.new(#ff6b6b, 30), linestyle=hline.style_solid, linewidth=2)
hline(levelMiddleBound, "Zero Line", color=color.new(#74b9ff, 30), linestyle=hline.style_solid, linewidth=2)
hline(levelLowerBound, "Oversold (-100)", color=color.new(#55efc4, 30), linestyle=hline.style_solid, linewidth=2)
// === Dynamic CCI Color Based on Zone and Momentum ===
// Color gradient based on CCI value and direction
bool isCciRising = calcCciValue > calcCciValue[1]
bool isCciAboveCi = calcCciValue > calcCiValue
// Multi-color gradient based on zone
color plotCciColor = na
if calcCciValue > levelUpperBound
plotCciColor := isCciRising ? color.new(#ff1744, 0) : color.new(#ff6b6b, 20)
else if calcCciValue < levelLowerBound
plotCciColor := isCciRising ? color.new(#00e676, 0) : color.new(#55efc4, 20)
else if calcCciValue >= levelMiddleBound
plotCciColor := isCciRising ? color.new(#00bcd4, 0) : color.new(#4dd0e1, 20)
else
plotCciColor := isCciRising ? color.new(#7c4dff, 0) : color.new(#b388ff, 20)
// === Plot CCI with Enhanced Styling ===
// Main CCI line
plot(calcCciValue, "CCI", color=plotCciColor, linewidth=3)
// CCI histogram for visual impact
color plotCciHistColor = calcCciValue >= 0 ?
(calcCciValue > levelUpperBound ? color.new(#ff1744, 60) : color.new(#00bcd4, 60)) :
(calcCciValue < levelLowerBound ? color.new(#00e676, 60) : color.new(#7c4dff, 60))
plot(calcCciValue, "CCI Histogram", style=plot.style_columns, color=color.new(plotCciHistColor, 70), linewidth=1)
// === Plot CI Line with Glow Effect ===
plot(calcCiValue, "CI Signal", color=color.new(inputColorCi, 0), linewidth=2)
plot(calcCiValue, "CI Glow", color=color.new(inputColorCi, 70), linewidth=6) // Glow effect
// === Fill Between CCI and CI ===
color fillColorCciCi = calcCciValue > calcCiValue ? color.new(inputColorBullish, 80) : color.new(inputColorBearish, 80)
fill(plot(calcCciValue, display=display.none), plot(calcCiValue, display=display.none), color=fillColorCciCi, title="CCI-CI Fill")
// === Zone Bands ===
// Overbought band (100-200)
plotBandUpper = plot(levelUpperBound, display=display.none)
plotBandExtremeUpper = plot(levelExtremeUpper, display=display.none)
fill(plotBandUpper, plotBandExtremeUpper, color=color.new(#ff1744, 90), title="Overbought Band")
// Oversold band (-200 to -100)
plotBandLower = plot(levelLowerBound, display=display.none)
plotBandExtremeLower = plot(levelExtremeLower, display=display.none)
fill(plotBandExtremeLower, plotBandLower, color=color.new(#00e676, 90), title="Oversold Band")
// === Signal Conditions ===
// Strong Buy: Golden cross in oversold zone
bool signalStrongBuy = ta.crossover(calcCciValue, calcCiValue) and calcCciValue < levelLowerBound
// Normal Buy: Golden cross in weak zone
bool signalNormalBuy = ta.crossover(calcCciValue, calcCiValue) and calcCciValue >= levelLowerBound and calcCciValue < levelMiddleBound
// Strong Sell: Death cross in overbought zone
bool signalStrongSell = ta.crossunder(calcCciValue, calcCiValue) and calcCciValue > levelUpperBound
// Normal Sell: Death cross in strong zone
bool signalNormalSell = ta.crossunder(calcCciValue, calcCiValue) and calcCciValue <= levelUpperBound and calcCciValue > levelMiddleBound
// === Enhanced Signal Markers ===
// Signal marker size based on signal strength
string markerSizeStrong = size.normal
string markerSizeNormal = size.small
// Strong Buy Signal - Large cyan marker with glow
plotshape(signalStrongBuy, "Strong Buy", shape.triangleup, location=location.bottom,
color=color.new(#00ffff, 0), size=markerSizeStrong, offset=0)
plotshape(signalStrongBuy, "Strong Buy Glow", shape.triangleup, location=location.bottom,
color=color.new(#00ffff, 70), size=size.large, offset=0)
// Normal Buy Signal - Green marker
plotshape(signalNormalBuy, "Buy", shape.triangleup, location=location.bottom,
color=color.new(#00ff88, 0), size=markerSizeNormal, offset=0)
// Strong Sell Signal - Large red marker with glow
plotshape(signalStrongSell, "Strong Sell", shape.triangledown, location=location.top,
color=color.new(#ff1744, 0), size=markerSizeStrong, offset=0)
plotshape(signalStrongSell, "Strong Sell Glow", shape.triangledown, location=location.top,
color=color.new(#ff1744, 70), size=size.large, offset=0)
// Normal Sell Signal - Orange marker
plotshape(signalNormalSell, "Sell", shape.triangledown, location=location.top,
color=color.new(#ff9800, 0), size=markerSizeNormal, offset=0)
// === Enhanced Labels with Emoji and Colors ===
var label labelStrongBuy = na
var label labelNormalBuy = na
var label labelStrongSell = na
var label labelNormalSell = na
if signalStrongBuy
labelStrongBuy := label.new(bar_index, levelLowerBound - 20, "🚀 Strong Buy",
color=color.new(#00ffff, 20),
textcolor=color.new(#000000, 0),
style=label.style_label_up,
size=size.normal)
if signalNormalBuy
labelNormalBuy := label.new(bar_index, levelMiddleBound - 10, "📈 Buy",
color=color.new(#00ff88, 30),
textcolor=color.new(#000000, 0),
style=label.style_label_up,
size=size.small)
if signalStrongSell
labelStrongSell := label.new(bar_index, levelUpperBound + 20, "💥 Strong Sell 📉",
color=color.new(#ff1744, 20),
textcolor=color.new(#ffffff, 0),
style=label.style_label_down,
size=size.normal)
if signalNormalSell
labelNormalSell := label.new(bar_index, levelMiddleBound + 10, " 📉 Sell",
color=color.new(#ff9800, 30),
textcolor=color.new(#351515, 0),
style=label.style_label_down,
size=size.small)
// === CCI Value Display ===
// Display current CCI value with color
var label labelCciValue = na
if barstate.islast
labelCciValue := label.new(bar_index, calcCciValue, "CCI: " + str.tostring(calcCciValue, "#.##"),
color=color.new(plotCciColor, 50),
textcolor=color.new(#ffffff, 0),
style=label.style_label_left,
size=size.small)
// === Alert Conditions ===
alertcondition(signalStrongBuy, "Strong Buy Signal", "🚀 Super CCI Strong Buy Signal!")
alertcondition(signalNormalBuy, "Buy Signal", "📈 Super CCI Buy Signal")
alertcondition(signalStrongSell, "Strong Sell Signal", "💥 Super CCI Strong Sell Signal!")
alertcondition(signalNormalSell, "Sell Signal", "📉 Super CCI Sell Signal")
// === Info Table ===
var table displayInfoTable = table.new(position.top_right, 2, 4, bgcolor=color.new(#1a1a2e, 20), border_width=1)
if barstate.islast
table.cell(displayInfoTable, 0, 0, "CCI Value", text_color=color.new(#ffffff, 0), text_size=size.small)
table.cell(displayInfoTable, 1, 0, str.tostring(calcCciValue, "#.##"), text_color=plotCciColor, text_size=size.small)
table.cell(displayInfoTable, 0, 1, "CI Value", text_color=color.new(#ffffff, 0), text_size=size.small)
table.cell(displayInfoTable, 1, 1, str.tostring(calcCiValue, "#.##"), text_color=inputColorCi, text_size=size.small)
table.cell(displayInfoTable, 0, 2, "Zone", text_color=color.new(#ffffff, 0), text_size=size.small)
displayZoneText = calcCciValue > levelUpperBound ? "Overbought" : calcCciValue < levelLowerBound ? "Oversold" : "Neutral"
displayZoneColor = calcCciValue > levelUpperBound ? inputColorOverbought : calcCciValue < levelLowerBound ? inputColorOversold : inputColorNeutral
table.cell(displayInfoTable, 1, 2, displayZoneText, text_color=displayZoneColor, text_size=size.small)
table.cell(displayInfoTable, 0, 3, "Trend", text_color=color.new(#ffffff, 0), text_size=size.small)
displayTrendText = isCciRising ? "↑ Rising" : "↓ Falling"
displayTrendColor = isCciRising ? inputColorBullish : inputColorBearish
table.cell(displayInfoTable, 1, 3, displayTrendText, text_color=displayTrendColor, text_size=size.small)