Zow ScalPro AI V1.3

Feezow89 · study · 427 行 · 点赞 27 · TradingView 原页

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

Pine Script

//@version=6
indicator("Zow ScalPro AI V1.3", overlay=true, max_labels_count=500, max_lines_count=500)
 
//====================================================
// ZOW SCALPRO AI V1.4
// Mobile Optimized - accuracy fixes
//====================================================
 
groupMA = "01 - Moving Average"
groupAI = "02 - AI / Signal"
groupRisk = "03 - Risk Management"
groupDisplay = "04 - Display"
groupAlert = "05 - Alerts"
 
// MOVING AVERAGE
fastLen = input.int(10, "Fast EMA", minval=1, group=groupMA)
midLen = input.int(20, "Middle EMA", minval=1, group=groupMA)
slowLen = input.int(50, "Slow EMA", minval=1, group=groupMA)
 
// AI
rsiLen = input.int(8, "RSI Length", minval=1, group=groupAI)
adxLen = input.int(8, "ADX Length", minval=1, group=groupAI)
atrLen = input.int(8, "ATR Length", minval=1, group=groupAI)
adxMin = input.float(20.0, "Minimum ADX", step=0.5, group=groupAI)
useConfirmed = input.bool(true, "Signal After Candle Close", group=groupAI)
crossFilter = input.bool(true, "Filter Cross (ADX + Slow EMA)", group=groupAI)
 
// RISK
slATR = input.float(1.91, "SL ATR Multiplier", step=0.01, group=groupRisk)
tp1RR = input.float(1.00, "TP1 RR", step=0.1, group=groupRisk)
tp2RR = input.float(1.80, "TP2 RR", step=0.1, group=groupRisk)
tp3RR = input.float(2.80, "TP3 RR", step=0.1, group=groupRisk)
pipOverride = input.float(0.0, "Pip Size Override (0 = auto)", step=0.0001, minval=0.0, group=groupRisk)
 
// DISPLAY
showEMA = input.bool(true, "Show EMA", group=groupDisplay)
showTradeLevels = input.bool(true, "Show Entry / SL / TP", group=groupDisplay)
showDashboard = input.bool(true, "Show Compact Dashboard", group=groupDisplay)
showSignalLabels = input.bool(true, "Show BUY / SELL", group=groupDisplay)
 
// ALERT
enableAlerts = input.bool(true, "Enable Alerts", group=groupAlert)
 
//====================================================
// MOVING AVERAGES
//====================================================
 
emaFast = ta.ema(close, fastLen)
emaMid = ta.ema(close, midLen)
emaSlow = ta.ema(close, slowLen)
 
plot(showEMA ? emaFast : na, title="Fast EMA", color=color.rgb(0, 190, 220), linewidth=2)
plot(showEMA ? emaMid : na, title="Middle EMA", color=color.rgb(255, 225, 0), linewidth=2)
plot(showEMA ? emaSlow : na, title="Slow EMA", color=color.rgb(0, 190, 220), linewidth=2)
 
//====================================================
// INDICATORS
//====================================================
 
rsi = ta.rsi(close, rsiLen)
atr = ta.atr(atrLen)
[diPlus, diMinus, adx] = ta.dmi(adxLen, adxLen)
 
//====================================================
// AUTO PIP CALCULATION
//====================================================
 
tickerU = str.upper(syminfo.ticker)
isForex = syminfo.type == "forex"
isMetal = str.contains(tickerU, "XAU") or str.contains(tickerU, "XAG")
isJPY = str.contains(tickerU, "JPY")
 
// JPY pairs: 3 digit (0.001) -> pip 0.01 | other forex: 5 digit (0.00001) -> pip 0.0001
forexPip = isJPY ? (syminfo.mintick <= 0.001 ? syminfo.mintick * 10 : syminfo.mintick) : (syminfo.mintick <= 0.00001 ? syminfo.mintick * 10 : syminfo.mintick)
 
autoPip = isMetal ? 0.1 : isForex ? forexPip : syminfo.mintick
pipSize = pipOverride > 0 ? pipOverride : (autoPip > 0 ? autoPip : syminfo.mintick)
 
priceToPips(diff) =>
    diff / pipSize
 
//====================================================
// TREND
//====================================================
 
bullTrend = emaFast > emaMid and emaMid > emaSlow
bearTrend = emaFast < emaMid and emaMid < emaSlow
 
trendText = bullTrend ? "BULL" : bearTrend ? "BEAR" : "NEUT"
trendColor = bullTrend ? color.lime : bearTrend ? color.red : color.yellow
 
//====================================================
// MOMENTUM
//====================================================
 
bullMomentum = close > emaFast and rsi > 50 and diPlus > diMinus
bearMomentum = close < emaFast and rsi < 50 and diMinus > diPlus
 
//====================================================
// CROSS (filtered)
//====================================================
 
bullCrossRaw = ta.crossover(emaFast, emaMid)
bearCrossRaw = ta.crossunder(emaFast, emaMid)
 
bullCross = bullCrossRaw and (not crossFilter or (close > emaSlow and adx >= adxMin))
bearCross = bearCrossRaw and (not crossFilter or (close < emaSlow and adx >= adxMin))
 
//====================================================
// CONTINUATION
//====================================================
 
bullContinuation = bullTrend and bullMomentum and adx >= adxMin
bearContinuation = bearTrend and bearMomentum and adx >= adxMin
 
//====================================================
// RAW SIGNAL
//====================================================
 
rawBuySignal = bullCross or (bullContinuation and not bullContinuation[1])
rawSellSignal = bearCross or (bearContinuation and not bearContinuation[1])
 
confBuy = useConfirmed ? (rawBuySignal and barstate.isconfirmed) : rawBuySignal
confSell = useConfirmed ? (rawSellSignal and barstate.isconfirmed) : rawSellSignal
 
// conflict: kalau buy & sell serentak, batalkan kedua-duanya
buySignal = confBuy and not confSell
sellSignal = confSell and not confBuy
 
//====================================================
// AI CONFIDENCE
//====================================================
 
float buyScore = 0.0
float sellScore = 0.0
 
buyScore += bullTrend ? 25 : 0
buyScore += emaFast > emaMid ? 15 : 0
buyScore += emaMid > emaSlow ? 15 : 0
buyScore += rsi > 50 ? 15 : 0
buyScore += diPlus > diMinus ? 10 : 0
buyScore += adx > adxMin ? 10 : 0
buyScore += close > emaFast ? 10 : 0
 
sellScore += bearTrend ? 25 : 0
sellScore += emaFast < emaMid ? 15 : 0
sellScore += emaMid < emaSlow ? 15 : 0
sellScore += rsi < 50 ? 15 : 0
sellScore += diMinus > diPlus ? 10 : 0
sellScore += adx > adxMin ? 10 : 0
sellScore += close < emaFast ? 10 : 0
 
confidence = bearTrend ? sellScore : bullTrend ? buyScore : math.max(buyScore, sellScore)
confidenceText = bearTrend ? "SELL" : bullTrend ? "BUY" : "WAIT"
confidenceColor = bearTrend ? color.red : bullTrend ? color.lime : color.yellow
 
//====================================================
// TRADE VARIABLES
//====================================================
 
var int tradeDirection = 0
var bool tradeActive = false
 
var float entryPrice = na
var float stopPrice = na
var float tp1Price = na
var float tp2Price = na
var float tp3Price = na
 
var bool tp1Hit = false
var bool tp2Hit = false
var bool tp3Hit = false
var bool slHit = false
 
var int tradeStartBar = na
 
var float dailyWinPips = 0.0
var float dailyLossPips = 0.0
 
isNewDay = ta.change(time("D")) != 0
 
if isNewDay
    dailyWinPips := 0.0
    dailyLossPips := 0.0
 
//====================================================
// NEW TRADE (abaikan signal arah sama selagi trade aktif)
//====================================================
 
newBuy = buySignal and not (tradeActive and tradeDirection == 1)
newSell = sellSignal and not (tradeActive and tradeDirection == -1)
 
if newSell
    tradeDirection := -1
    tradeActive := true
    entryPrice := close
    stopPrice := entryPrice + atr * slATR
    sellRisk = stopPrice - entryPrice
    tp1Price := entryPrice - sellRisk * tp1RR
    tp2Price := entryPrice - sellRisk * tp2RR
    tp3Price := entryPrice - sellRisk * tp3RR
    tp1Hit := false
    tp2Hit := false
    tp3Hit := false
    slHit := false
    tradeStartBar := bar_index
 
if newBuy
    tradeDirection := 1
    tradeActive := true
    entryPrice := close
    stopPrice := entryPrice - atr * slATR
    buyRisk = entryPrice - stopPrice
    tp1Price := entryPrice + buyRisk * tp1RR
    tp2Price := entryPrice + buyRisk * tp2RR
    tp3Price := entryPrice + buyRisk * tp3RR
    tp1Hit := false
    tp2Hit := false
    tp3Hit := false
    slHit := false
    tradeStartBar := bar_index
 
//====================================================
// HIT EVENTS & DAILY PIPS
// - bar signal sendiri dilangkau
// - SL diutamakan jika SL & TP kena dalam bar sama
// - trade tamat selepas SL atau TP3
//====================================================
 
bool tp1Event = false
bool tp2Event = false
bool tp3Event = false
bool slEvent = false
 
canCheck = tradeActive and not na(entryPrice) and bar_index > tradeStartBar
 
if canCheck and tradeDirection == -1
    if high >= stopPrice
        slHit := true
        slEvent := true
        tradeActive := false
        dailyLossPips += priceToPips(stopPrice - entryPrice)
    else
        if not tp1Hit and low <= tp1Price
            tp1Hit := true
            tp1Event := true
            dailyWinPips += priceToPips(entryPrice - tp1Price)
        if not tp2Hit and low <= tp2Price
            tp2Hit := true
            tp2Event := true
            dailyWinPips += priceToPips(tp1Price - tp2Price)
        if not tp3Hit and low <= tp3Price
            tp3Hit := true
            tp3Event := true
            tradeActive := false
            dailyWinPips += priceToPips(tp2Price - tp3Price)
 
if canCheck and tradeDirection == 1
    if low <= stopPrice
        slHit := true
        slEvent := true
        tradeActive := false
        dailyLossPips += priceToPips(entryPrice - stopPrice)
    else
        if not tp1Hit and high >= tp1Price
            tp1Hit := true
            tp1Event := true
            dailyWinPips += priceToPips(tp1Price - entryPrice)
        if not tp2Hit and high >= tp2Price
            tp2Hit := true
            tp2Event := true
            dailyWinPips += priceToPips(tp2Price - tp1Price)
        if not tp3Hit and high >= tp3Price
            tp3Hit := true
            tp3Event := true
            tradeActive := false
            dailyWinPips += priceToPips(tp3Price - tp2Price)
 
//====================================================
// TRADE STATE
//====================================================
 
tradeState = slHit ? "SL HIT" : tp3Hit ? "TP3 HIT" : tp2Hit ? "TP2 HIT" : tp1Hit ? "TP1 HIT" : tradeDirection == -1 ? "SELL" : tradeDirection == 1 ? "BUY" : "WAIT"
 
tradeStateColor = slHit ? color.red : tp1Hit ? color.lime : tradeDirection == -1 ? color.red : tradeDirection == 1 ? color.lime : color.yellow
 
//====================================================
// SIGNAL LABELS
//====================================================
 
if showSignalLabels and newBuy
    label.new(bar_index, low, "ZOW\n" + str.tostring(buyScore, "#") + "% BUY", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.tiny)
 
if showSignalLabels and newSell
    label.new(bar_index, high, "ZOW\n" + str.tostring(sellScore, "#") + "% SELL", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.tiny)
 
//====================================================
// TRADE LEVELS  (Entry kuning, SL merah, TP hijau)
//====================================================
 
var line entryLine = na
var line slLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na
 
var label entryLabel = na
var label slLabel = na
var label tp1Label = na
var label tp2Label = na
var label tp3Label = na
 
if showTradeLevels and (newBuy or newSell)
 
    line.delete(entryLine)
    line.delete(slLine)
    line.delete(tp1Line)
    line.delete(tp2Line)
    line.delete(tp3Line)
 
    label.delete(entryLabel)
    label.delete(slLabel)
    label.delete(tp1Label)
    label.delete(tp2Label)
    label.delete(tp3Label)
 
    entryLine := line.new(bar_index, entryPrice, bar_index + 35, entryPrice, color=color.yellow, style=line.style_dashed, width=1)
    slLine := line.new(bar_index, stopPrice, bar_index + 35, stopPrice, color=color.red, style=line.style_dotted, width=1)
    tp1Line := line.new(bar_index, tp1Price, bar_index + 35, tp1Price, color=color.green, style=line.style_dashed, width=1)
    tp2Line := line.new(bar_index, tp2Price, bar_index + 35, tp2Price, color=color.green, style=line.style_dashed, width=1)
    tp3Line := line.new(bar_index, tp3Price, bar_index + 35, tp3Price, color=color.green, style=line.style_dashed, width=1)
 
    entryLabel := label.new(bar_index + 35, entryPrice, "E " + str.tostring(entryPrice, format.mintick), style=label.style_label_left, color=color.rgb(210, 180, 0), textcolor=color.black, size=size.tiny)
    slLabel := label.new(bar_index + 35, stopPrice, "SL " + str.tostring(stopPrice, format.mintick), style=label.style_label_left, color=color.red, textcolor=color.white, size=size.tiny)
    tp1Label := label.new(bar_index + 35, tp1Price, "TP1 " + str.tostring(tp1Price, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.tiny)
    tp2Label := label.new(bar_index + 35, tp2Price, "TP2 " + str.tostring(tp2Price, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.tiny)
    tp3Label := label.new(bar_index + 35, tp3Price, "TP3 " + str.tostring(tp3Price, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.tiny)
 
//====================================================
// PREVIOUS DAILY CLOSE
//====================================================
 
dailyClose = request.security(syminfo.tickerid, "D", close[1], lookahead=barmerge.lookahead_on)
 
plot(dailyClose, title="Previous Daily Close", color=color.new(color.red, 30), linewidth=1, style=plot.style_line)
 
//====================================================
// COMPACT DASHBOARD
//====================================================
 
var table dash = table.new(position.top_right, 3, 13, border_width=1, frame_width=1, frame_color=color.gray)
 
dashBg = color.rgb(25, 25, 25)
hdrBg = color.rgb(60, 60, 60)
labelTxt = color.rgb(220, 220, 220)
 
f_cell(int c, int r, string t, color tc, color bg) =>
    table.cell(dash, c, r, t, text_color=tc, bgcolor=bg, text_size=size.tiny)
 
tp1Txt = str.tostring(tp1RR, "#.##") + "R"
tp2Txt = str.tostring(tp2RR, "#.##") + "R"
tp3Txt = str.tostring(tp3RR, "#.##") + "R"
 
if barstate.islast and showDashboard
 
    f_cell(0, 0, "ZOW PRO", color.yellow, color.rgb(10, 10, 10))
    f_cell(1, 0, syminfo.ticker, color.white, color.rgb(10, 10, 10))
    f_cell(2, 0, "● LIVE", color.lime, color.rgb(10, 10, 10))
 
    f_cell(0, 1, "METRIC", color.white, hdrBg)
    f_cell(1, 1, "VALUE", color.white, hdrBg)
    f_cell(2, 1, "INFO", color.white, hdrBg)
 
    f_cell(0, 2, "Symbol", labelTxt, dashBg)
    f_cell(1, 2, syminfo.ticker, color.rgb(230, 200, 0), dashBg)
    f_cell(2, 2, timeframe.period + " TF", color.silver, dashBg)
 
    f_cell(0, 3, "AI", labelTxt, dashBg)
    f_cell(1, 3, str.tostring(confidence, "#") + "%", confidenceColor, dashBg)
    f_cell(2, 3, confidenceText, confidenceColor, dashBg)
 
    f_cell(0, 4, "Trend", labelTxt, dashBg)
    f_cell(1, 4, trendText, trendColor, dashBg)
    f_cell(2, 4, "RSI " + str.tostring(rsi, "#.0"), labelTxt, dashBg)
 
    f_cell(0, 5, "State", labelTxt, dashBg)
    f_cell(1, 5, tradeState, tradeStateColor, dashBg)
    f_cell(2, 5, "ADX " + str.tostring(adx, "#.0"), labelTxt, dashBg)
 
    f_cell(0, 6, "Entry", labelTxt, dashBg)
    f_cell(1, 6, na(entryPrice) ? "-" : str.tostring(entryPrice, format.mintick), color.rgb(230, 200, 0), dashBg)
    f_cell(2, 6, tradeDirection == 1 ? "BUY" : tradeDirection == -1 ? "SELL" : "-", tradeDirection == 1 ? color.lime : tradeDirection == -1 ? color.red : color.silver, dashBg)
 
    f_cell(0, 7, "SL", labelTxt, dashBg)
    f_cell(1, 7, na(stopPrice) ? "-" : str.tostring(stopPrice, format.mintick), color.red, dashBg)
    f_cell(2, 7, na(entryPrice) ? "-" : str.tostring(priceToPips(math.abs(stopPrice - entryPrice)), "#.0") + "p", slHit ? color.red : color.silver, dashBg)
 
    f_cell(0, 8, "TP1", labelTxt, dashBg)
    f_cell(1, 8, na(tp1Price) ? "-" : str.tostring(tp1Price, format.mintick), color.lime, dashBg)
    f_cell(2, 8, tp1Hit ? "HIT" : tp1Txt, tp1Hit ? color.lime : color.silver, dashBg)
 
    f_cell(0, 9, "TP2", labelTxt, dashBg)
    f_cell(1, 9, na(tp2Price) ? "-" : str.tostring(tp2Price, format.mintick), color.lime, dashBg)
    f_cell(2, 9, tp2Hit ? "HIT" : tp2Txt, tp2Hit ? color.lime : color.silver, dashBg)
 
    f_cell(0, 10, "TP3", labelTxt, dashBg)
    f_cell(1, 10, na(tp3Price) ? "-" : str.tostring(tp3Price, format.mintick), color.lime, dashBg)
    f_cell(2, 10, tp3Hit ? "HIT" : tp3Txt, tp3Hit ? color.lime : color.silver, dashBg)
 
    f_cell(0, 11, "Day Win", labelTxt, dashBg)
    f_cell(1, 11, "+" + str.tostring(dailyWinPips, "#.0"), color.lime, dashBg)
    f_cell(2, 11, "Pips", color.silver, dashBg)
 
    f_cell(0, 12, "Day Loss", labelTxt, dashBg)
    f_cell(1, 12, "-" + str.tostring(dailyLossPips, "#.0"), color.red, dashBg)
    f_cell(2, 12, "Pips", color.silver, dashBg)
 
//====================================================
// ALERTS
//====================================================
 
alertcondition(enableAlerts and newBuy, title="Zow PRO BUY", message="Zow ScalPro AI PRO BUY | {{ticker}} | {{close}}")
alertcondition(enableAlerts and newSell, title="Zow PRO SELL", message="Zow ScalPro AI PRO SELL | {{ticker}} | {{close}}")
alertcondition(enableAlerts and tp1Event, title="Zow PRO TP1", message="Zow ScalPro AI PRO TP1 HIT | {{ticker}}")
alertcondition(enableAlerts and tp2Event, title="Zow PRO TP2", message="Zow ScalPro AI PRO TP2 HIT | {{ticker}}")
alertcondition(enableAlerts and tp3Event, title="Zow PRO TP3", message="Zow ScalPro AI PRO TP3 HIT | {{ticker}}")
alertcondition(enableAlerts and slEvent, title="Zow PRO SL", message="Zow ScalPro AI PRO SL HIT | {{ticker}}")

← 返回列表