Khajanchi Wealth Auto-Levels Engine

rishabfinances · study · 133 行 · 点赞 5 · TradingView 原页

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

Pine Script

//@version=6
indicator('Khajanchi Wealth Auto-Levels Engine', overlay = true, max_lines_count = 100, max_labels_count = 50)
 
// ==========================================
// 1. MOVING AVERAGES (Institutional Trend)
// ==========================================
sma50 = ta.sma(close, 50)
sma200 = ta.sma(close, 200)
 
plot(sma50, color = color.new(#2962FF, 0), linewidth = 2, title = '50 SMA')
plot(sma200, color = color.new(#FF6D00, 0), linewidth = 2, title = '200 SMA')
 
// Golden / Death Cross Alerts & Visual Markers
bullCross = ta.crossover(sma50, sma200)
bearCross = ta.crossunder(sma50, sma200)
 
plotshape(bullCross, style = shape.triangleup, location = location.belowbar, color = color.new(#00E676, 0), size = size.small, title = 'Golden Cross')
plotshape(bearCross, style = shape.triangledown, location = location.abovebar, color = color.new(#FF5252, 0), size = size.small, title = 'Death Cross')
 
alertcondition(bullCross, title = 'Golden Cross Alert', message = 'Golden Cross Detected: 50 SMA crossed above 200 SMA on {{ticker}}.')
alertcondition(bearCross, title = 'Death Cross Alert', message = 'Death Cross Detected: 50 SMA crossed below 200 SMA on {{ticker}}.')
 
// ==========================================
// 2. DYNAMIC PIVOT SUPPORT & RESISTANCE
// ==========================================
pivotLeg = input.int(10, title = 'Pivot Lookback (Bars Left/Right)', minval = 2)
ph = ta.pivothigh(high, pivotLeg, pivotLeg)
pl = ta.pivotlow(low, pivotLeg, pivotLeg)
 
var float last_high = na
var float last_low = na
var int last_high_idx = na
var int last_low_idx = na
 
if not na(ph)
    last_high := ph
    last_high_idx := bar_index - pivotLeg
    last_high_idx
 
if not na(pl)
    last_low := pl
    last_low_idx := bar_index - pivotLeg
    last_low_idx
 
plot(last_high, 'Key Resistance', color = color.new(#EF5350, 0), style = plot.style_linebr, linewidth = 2)
plot(last_low, 'Key Support', color = color.new(#26A69A, 0), style = plot.style_linebr, linewidth = 2)
 
// ==========================================
// 3. FIBONACCI RETRACEMENT & EXTENSION CLUSTERS
// ==========================================
showFib = input.bool(true, title = 'Display Dynamic Fibonacci Bands')
 
var line fib_0 = na
var line fib_236 = na
var line fib_382 = na
var line fib_500 = na
var line fib_618 = na
var line fib_786 = na
var line fib_100 = na
var line fib_161 = na
 
var label lbl_618 = na
var label lbl_161 = na
 
if showFib and barstate.islast and not na(last_high) and not na(last_low)
    // Clear previous lines and labels
    line.delete(fib_0)
    line.delete(fib_236)
    line.delete(fib_382)
    line.delete(fib_500)
    line.delete(fib_618)
    line.delete(fib_786)
    line.delete(fib_100)
    line.delete(fib_161)
    label.delete(lbl_618)
    label.delete(lbl_161)
 
    // Determine directional swing polarity
    bool isBullTrend = last_high_idx > last_low_idx
    float swingHigh = last_high
    float swingLow = last_low
    float diff = swingHigh - swingLow
    int startBar = math.min(last_high_idx, last_low_idx)
    int endBar = bar_index + 15
 
    float p0 = isBullTrend ? swingHigh : swingLow
    float p100 = isBullTrend ? swingLow : swingHigh
 
    float l236 = isBullTrend ? swingHigh - diff * 0.236 : swingLow + diff * 0.236
    float l382 = isBullTrend ? swingHigh - diff * 0.382 : swingLow + diff * 0.382
    float l500 = isBullTrend ? swingHigh - diff * 0.500 : swingLow + diff * 0.500
    float l618 = isBullTrend ? swingHigh - diff * 0.618 : swingLow + diff * 0.618
    float l786 = isBullTrend ? swingHigh - diff * 0.786 : swingLow + diff * 0.786
    float l161 = isBullTrend ? swingHigh + diff * 0.618 : swingLow - diff * 0.618
 
    // Draw active projection lines
    fib_0 := line.new(startBar, p0, endBar, p0, color = color.new(color.gray, 50), style = line.style_dashed)
    fib_236 := line.new(startBar, l236, endBar, l236, color = color.new(#787B86, 60), style = line.style_dotted)
    fib_382 := line.new(startBar, l382, endBar, l382, color = color.new(#FF9800, 40), style = line.style_solid)
    fib_500 := line.new(startBar, l500, endBar, l500, color = color.new(#2962FF, 30), style = line.style_solid, width = 2)
    fib_618 := line.new(startBar, l618, endBar, l618, color = color.new(#E91E63, 0), style = line.style_solid, width = 2)
    fib_786 := line.new(startBar, l786, endBar, l786, color = color.new(#9C27B0, 40), style = line.style_dotted)
    fib_100 := line.new(startBar, p100, endBar, p100, color = color.new(color.gray, 50), style = line.style_dashed)
    fib_161 := line.new(startBar, l161, endBar, l161, color = color.new(#00E676, 0), style = line.style_solid, width = 2)
 
    // Key cluster level tags
    lbl_618 := label.new(endBar, l618, 'Golden Pocket (0.618): ' + str.tostring(l618, '#.##'), color = color.new(#E91E63, 20), textcolor = color.white, style = label.style_label_left, size = size.small)
    lbl_161 := label.new(endBar, l161, 'Target Extension (1.618): ' + str.tostring(l161, '#.##'), color = color.new(#00E676, 20), textcolor = color.white, style = label.style_label_left, size = size.small)
    lbl_161
 
// ==========================================
// 4. REGIME MONITOR (HUD DASHBOARD)
// ==========================================
showHUD = input.bool(true, title = 'Display Regime Telemetry Box')
 
var table hud = table.new(position.top_right, 2, 4, bgcolor = color.new(#1E293B, 15), border_width = 1, border_color = color.new(#475569, 30))
 
if showHUD and barstate.islast
    bool isBullRegime = close > sma200
    bool isTrendStrong = sma50 > sma200
    float dist200 = (close - sma200) / sma200 * 100
 
    table.cell(hud, 0, 0, 'Regime Bias', text_color = color.white, text_size = size.small, text_halign = text.align_left)
    table.cell(hud, 1, 0, isBullRegime ? 'BULLISH' : 'BEARISH', bgcolor = isBullRegime ? color.new(#16A34A, 20) : color.new(#DC2626, 20), text_color = isBullRegime ? color.green : color.red, text_size = size.small, text_halign = text.align_right)
 
    table.cell(hud, 0, 1, '50/200 Alignment', text_color = color.white, text_size = size.small, text_halign = text.align_left)
    table.cell(hud, 1, 1, isTrendStrong ? 'Golden Stack' : 'Death Stack', text_color = isTrendStrong ? color.green : color.red, text_size = size.small, text_halign = text.align_right)
 
    table.cell(hud, 0, 2, 'Distance to 200 SMA', text_color = color.white, text_size = size.small, text_halign = text.align_left)
    table.cell(hud, 1, 2, (dist200 >= 0 ? '+' : '') + str.tostring(dist200, '#.##') + '%', text_color = dist200 >= 0 ? color.green : color.red, text_size = size.small, text_halign = text.align_right)
 
    table.cell(hud, 0, 3, '200 SMA Level', text_color = color.white, text_size = size.small, text_halign = text.align_left)
    table.cell(hud, 1, 3, str.tostring(sma200, '#.##'), text_color = color.yellow, text_size = size.small, text_halign = text.align_right)

← 返回列表