OPEN-SOURCE SCRIPT

Swing IA Cockpit [v2]

85
//version=5
indicator("Swing IA Cockpit [v2]", overlay=true, max_bars_back=500)

// === INPUTS ===
mode = input.string("Pullback", title="Entry Mode", options=["Breakout", "Pullback"])
corrLen = input.int(60, "Correlation Window Length")
scoreWeightBias = input.float(0.6, title="Weight: Bias", minval=0, maxval=1)
scoreWeightTiming = 1.0 - scoreWeightBias

// === INDICATEURS H1 ===
ema200_H1 = ta.ema(close, 200)
ema50_H1 = ta.ema(close, 50)
rsi_H1 = ta.rsi(close, 14)
donchianHigh = ta.highest(high, 20)
donchianLow = ta.lowest(low, 20)
atr_H1 = ta.atr(14)
avgATR_H1 = ta.sma(atr_H1, 50)
body = math.abs(close - open)
avgBody = ta.sma(body, 20)

// === H4 / D1 ===
close_H4 = request.security(syminfo.tickerid, "240", close)
ema200_H4 = request.security(syminfo.tickerid, "240", ta.ema(close, 200))
rsi_H4 = request.security(syminfo.tickerid, "240", ta.rsi(close, 14))
atr_H4 = request.security(syminfo.tickerid, "240", ta.atr(14))
avgATR_H4 = request.security(syminfo.tickerid, "240", ta.sma(ta.atr(14), 50))
close_D1 = request.security(syminfo.tickerid, "D", close)
ema200_D1 = request.security(syminfo.tickerid, "D", ta.ema(close, 200))

// === CORRÉLATIONS ===
dxy = request.security("TVC:DXY", "60", close)
spx = request.security("SP:SPX", "60", close)
gold = request.security("OANDA:XAUUSD", "60", close)
corrDXY = ta.correlation(close, dxy, corrLen)
corrSPX = ta.correlation(close, spx, corrLen)
corrGold = ta.correlation(close, gold, corrLen)

// === LOGIQUE BIAIS ===
biasLong = close_D1 > ema200_D1 and close_H4 > ema200_H4 and rsi_H4 >= 55
biasShort = close_D1 < ema200_D1 and close_H4 < ema200_H4 and rsi_H4 <= 45
bias = biasLong ? "LONG" : biasShort ? "SHORT" : "NEUTRAL"

// === LOGIQUE TIMING ===
isBreakoutLong = mode == "Breakout" and high > donchianHigh and close > ema200_H1 and rsi_H1 > 50
isBreakoutShort = mode == "Breakout" and low < donchianLow and close < ema200_H1 and rsi_H1 < 50

var float breakoutPrice = na
var int breakoutBar = na
if isBreakoutLong or isBreakoutShort
breakoutPrice := close
breakoutBar := bar_index

validPullbackLong = mode == "Pullback" and not na(breakoutBar) and bar_index <= breakoutBar + 3 and close > ema50_H1 and low <= ema50_H1
validPullbackShort = mode == "Pullback" and not na(breakoutBar) and bar_index <= breakoutBar + 3 and close < ema50_H1 and high >= ema50_H1

timingLong = isBreakoutLong or validPullbackLong
timingShort = isBreakoutShort or validPullbackShort

// === SCORES ===
scoreTrend = (close_D1 > ema200_D1 ? 20 : 0) + (close_H4 > ema200_H4 ? 20 : 0)
scoreMomentumBias = (rsi_H4 >= 55 or rsi_H4 <= 45) ? 20 : 10
scoreCorr = 0
scoreCorr += biasLong and corrDXY < 0 ? 10 : 0
scoreCorr += biasLong and corrSPX > 0 ? 10 : 0
scoreCorr += biasLong and corrGold >= 0 ? 10 : 0
scoreCorr += biasShort and corrDXY > 0 ? 10 : 0
scoreCorr += biasShort and corrSPX < 0 ? 10 : 0
scoreCorr += biasShort and corrGold <= 0 ? 10 : 0
scoreCorr := math.min(scoreCorr, 30)
scoreVolBias = atr_H4 > avgATR_H4 ? 10 : 0
scoreBias = scoreTrend + scoreMomentumBias + scoreCorr + scoreVolBias

scoreStruct = (timingLong or timingShort) ? 40 : 0
scoreMomentumTiming = rsi_H1 > 50 or rsi_H1 < 50 ? 25 : 10
scoreTrendH1 = (close > ema50_H1 and ema50_H1 > ema200_H1) or (close < ema50_H1 and ema50_H1 < ema200_H1) ? 20 : 10
scoreVolTiming = atr_H1 > avgATR_H1 ? 15 : 5
scoreTiming = scoreStruct + scoreMomentumTiming + scoreTrendH1 + scoreVolTiming

scoreTotal = scoreBias * scoreWeightBias + scoreTiming * scoreWeightTiming

scoreLong = biasLong ? scoreTotal : 0
scoreShort = biasShort ? scoreTotal : 0
delta = scoreLong - scoreShort

scoreExtMomentum = (rsi_H4 > 55 ? 10 : 0)
scoreExtVol = atr_H4 > avgATR_H4 ? 10 : 0
scoreExtStructure = body > avgBody ? 10 : 5
scoreExtCorr = (scoreCorr > 15 ? 10 : 5)
scoreExtension = scoreExtMomentum + scoreExtVol + scoreExtStructure + scoreExtCorr

// === VERDICT FINAL ===
verdict = "NO TRADE"
verdict := bias == "NEUTRAL" or math.abs(delta) < 10 or scoreTotal < 70 ? "NO TRADE" :
scoreTotal < 80 ? "WAIT" :
scoreTotal >= 85 and math.abs(delta) >= 20 and scoreExtension >= 60 ? "TRADE A+" :
"TRADE"

// === TABLE COCKPIT ===
var table cockpit = table.new(position.top_right, 2, 9, border_width=1)
if bar_index % 5 == 0
table.cell(cockpit, 0, 0, "Bias", bgcolor=color.gray)
table.cell(cockpit, 1, 0, bias)
table.cell(cockpit, 0, 1, "ScoreBias", bgcolor=color.gray)
table.cell(cockpit, 1, 1, str.tostring(scoreBias))
table.cell(cockpit, 0, 2, "ScoreTiming", bgcolor=color.gray)
table.cell(cockpit, 1, 2, str.tostring(scoreTiming))
table.cell(cockpit, 0, 3, "ScoreTotal", bgcolor=color.gray)
table.cell(cockpit, 1, 3, str.tostring(scoreTotal))
table.cell(cockpit, 0, 4, "ScoreLong", bgcolor=color.gray)
table.cell(cockpit, 1, 4, str.tostring(scoreLong))
table.cell(cockpit, 0, 5, "ScoreShort", bgcolor=color.gray)
table.cell(cockpit, 1, 5, str.tostring(scoreShort))
table.cell(cockpit, 0, 6, "Delta", bgcolor=color.gray)
table.cell(cockpit, 1, 6, str.tostring(delta))
table.cell(cockpit, 0, 7, "Extension", bgcolor=color.gray)
table.cell(cockpit, 1, 7, str.tostring(scoreExtension))
table.cell(cockpit, 0, 8, "Verdict", bgcolor=color.gray)
table.cell(cockpit, 1, 8, verdict, bgcolor=verdict == "TRADE A+" ? color.green : verdict == "TRADE" ? color.lime : verdict == "WAIT" ? color.orange : color.red)

// === ALERTS ===
alertcondition(verdict == "TRADE A+" and bias == "LONG", title="TRADE A+ LONG", message="TRADE A+ signal long")
alertcondition(verdict == "TRADE A+" and bias == "SHORT", title="TRADE A+ SHORT", message="TRADE A+ signal short")
alertcondition(verdict == "NO TRADE", title="NO TRADE / RANGE", message="Marché confus ou neutre — pas de trade")

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.