OPEN-SOURCE SCRIPT
Swing IA Cockpit [v2]

//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")
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")
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.