本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("XAUUSD 30S V43 QUALITY LIVE - 600 TP / 800 SL", overlay=true, max_boxes_count=500, max_lines_count=500, max_labels_count=500)
//=============================================================================
// XAUUSD 30S V43 QUALITY LIVE
//
// HIGH-QUALITY V42/V43 BRANCH
//
// ACTIVE SETUPS:
// - A SHORT
// - L LONG
// - B LONG
//
// REMOVED FROM THIS VERSION:
// - A LONG
// - L SHORT
// - B SHORT
//
// SIGNAL PRIORITY:
// A SHORT -> L LONG -> B LONG
//
// TIMEFRAME:
// 30 SECOND
//
// HIGHER-TIMEFRAME CONFIRMATION:
// Confirmed 5-minute data
// Confirmed 15-minute data
//
// TRADE MODEL:
// Entry = confirmed signal candle close
// TP = 600 Gold points
// SL = 800 Gold points
// Gold point default = 0.01
//
// LIVE ENGINE:
// - One virtual trade at a time
// - TP/SL tracking begins after entry candle
// - BUY/SELL triangles
// - Entry/TP/SL lines
// - TP/SL boxes
// - Live alerts
//
// IMPORTANT:
// This indicator creates TradingView signals and alerts.
// Actual broker execution requires a supported broker integration
// or an external alert/webhook execution system.
//=============================================================================
//=============================================================================
// LIVE TRADE SETTINGS
//=============================================================================
pointSize = input.float(0.01, "Gold Point Size", minval=0.001, step=0.001)
stopLossPoints = input.int(800, "Stop Loss Points", minval=1)
takeProfitPoints = input.int(600, "Take Profit Points", minval=1)
stopDistance = stopLossPoints * pointSize
targetDistance = takeProfitPoints * pointSize
is30Sec = timeframe.isseconds and timeframe.multiplier == 30
//=============================================================================
// VISUAL SETTINGS
//=============================================================================
showTradeBoxes = input.bool(true, "Show TP / SL Boxes")
showEntryLine = input.bool(true, "Show Entry Line")
showTPLine = input.bool(true, "Show TP Line")
showSLLine = input.bool(true, "Show SL Line")
showTradeLabels = input.bool(true, "Show Trade Information Label")
keepCompletedTradeDrawings = input.bool(true, "Keep Completed Trade Drawings")
//=============================================================================
// SETUP ENABLES
//=============================================================================
enableAShort = input.bool(true, "Enable A Short")
enableLLong = input.bool(true, "Enable L Long")
enableBLong = input.bool(true, "Enable B Long")
//=============================================================================
// V42/V43 SESSION QUALITY FILTERS
//=============================================================================
useSessionQualityFilter = input.bool(true, "Use Session Quality Filters")
blockBLong2100 = not na(time(timeframe.period, "2100-2130", "America/New_York"))
blockLLong0100 = not na(time(timeframe.period, "0100-0130", "America/New_York"))
blockLLong0400 = not na(time(timeframe.period, "0400-0430", "America/New_York"))
blockLLong2130 = not na(time(timeframe.period, "2130-2200", "America/New_York"))
blockAShort0230 = not na(time(timeframe.period, "0230-0300", "America/New_York"))
bLongSessionQualityOK = not useSessionQualityFilter or not blockBLong2100
lLongSessionQualityOK = not useSessionQualityFilter or not (blockLLong0100 or blockLLong0400 or blockLLong2130)
aShortSessionQualityOK = not useSessionQualityFilter or not blockAShort0230
//=============================================================================
// A SHORT SESSIONS
//=============================================================================
aShortSession1 = input.session("0130-0200", "A Short Session 1")
aShortSession2 = input.session("0215-0245", "A Short Session 2")
aShortSession3 = input.session("0300-0400", "A Short Session 3")
inAShortSession1 = not na(time(timeframe.period, aShortSession1, "America/New_York"))
inAShortSession2 = not na(time(timeframe.period, aShortSession2, "America/New_York"))
inAShortSession3 = not na(time(timeframe.period, aShortSession3, "America/New_York"))
inAShortSession = inAShortSession1 or inAShortSession2 or inAShortSession3
//=============================================================================
// L LONG SESSIONS
//=============================================================================
lLongMorning1 = input.session("0100-0330", "L Long Morning 1")
lLongMorning2 = input.session("0400-0500", "L Long Morning 2")
lLongEvening = input.session("2030-2200", "L Long Evening")
inLLongMorning1 = not na(time(timeframe.period, lLongMorning1, "America/New_York"))
inLLongMorning2 = not na(time(timeframe.period, lLongMorning2, "America/New_York"))
inLLongEvening = not na(time(timeframe.period, lLongEvening, "America/New_York"))
inLLongSession = inLLongMorning1 or inLLongMorning2 or inLLongEvening
//=============================================================================
// B LONG SESSIONS
//=============================================================================
bLongMorningSession = input.session("0430-0500", "B Long Morning")
bLongEveningSession = input.session("2000-2200", "B Long Evening")
inBLongMorning = not na(time(timeframe.period, bLongMorningSession, "America/New_York"))
inBLongEvening = not na(time(timeframe.period, bLongEveningSession, "America/New_York"))
inBLongSession = inBLongMorning or inBLongEvening
//=============================================================================
// CORE SETTINGS
//=============================================================================
atrLength = input.int(14, "ATR Length", minval=5)
minimum15MSeparation = input.float(0.04, "15M Minimum EMA Separation ATR", minval=0.00, maxval=0.50, step=0.01)
minimum5MSeparation = input.float(0.03, "5M Minimum EMA Separation ATR", minval=0.00, maxval=0.50, step=0.01)
minimum30SSeparationATR = input.float(0.02, "30S Minimum EMA Separation ATR", minval=0.00, maxval=0.50, step=0.01)
minimumVolatilityRatio = input.float(0.50, "Minimum ATR / Average ATR", minval=0.20, maxval=1.50, step=0.05)
maximumVolatilityRatio = input.float(2.00, "Maximum ATR / Average ATR", minval=1.00, maxval=4.00, step=0.05)
//=============================================================================
// A SHORT SETTINGS
//=============================================================================
aPullbackLookback = input.int(8, "A Pullback Lookback", minval=1, maxval=20)
aCooldownBars = input.int(4, "A Cooldown Bars", minval=1, maxval=60)
aMaximumPullbackDepthATR = input.float(0.50, "A Maximum Pullback ATR", minval=0.10, maxval=1.50, step=0.05)
aMinimumBodyRatio = input.float(0.40, "A Minimum Body Ratio", minval=0.20, maxval=0.90, step=0.05)
aMinimumClosePosition = input.float(0.62, "A Minimum Close Position", minval=0.50, maxval=0.95, step=0.01)
aMaximumEntryDistanceATR = input.float(1.00, "A Maximum Entry Distance ATR", minval=0.20, maxval=2.00, step=0.05)
//=============================================================================
// L LONG SETTINGS
//=============================================================================
liquidityLookback = input.int(10, "L Liquidity Lookback", minval=3, maxval=50)
minimumSweepATR = input.float(0.03, "L Minimum Sweep ATR", minval=0.00, maxval=1.00, step=0.01)
maximumSweepATR = input.float(0.75, "L Maximum Sweep ATR", minval=0.10, maxval=2.00, step=0.05)
liquidityMinimumBodyRatio = input.float(0.30, "L Minimum Body Ratio", minval=0.10, maxval=0.90, step=0.01)
liquidityMinimumClosePosition = input.float(0.60, "L Minimum Close Position", minval=0.50, maxval=0.95, step=0.01)
liquidityMinimumWickATR = input.float(0.05, "L Minimum Wick ATR", minval=0.00, maxval=1.00, step=0.01)
liquidityMaximumDistanceATR = input.float(1.40, "L Maximum EMA21 Distance ATR", minval=0.20, maxval=3.00, step=0.05)
liquidityMaximumEMA50PenetrationATR = input.float(0.40, "L Maximum EMA50 Penetration ATR", minval=0.00, maxval=1.50, step=0.05)
liquidityCooldownBars = input.int(4, "L Cooldown Bars", minval=1, maxval=100)
//=============================================================================
// B LONG SETTINGS
//=============================================================================
bPullbackLookback = input.int(12, "B Pullback Lookback", minval=2, maxval=30)
bMaximumEMA21PenetrationATR = input.float(0.70, "B Maximum EMA21 Penetration ATR", minval=0.10, maxval=2.00, step=0.05)
bMinimumBodyRatio = input.float(0.38, "B Minimum Body Ratio", minval=0.20, maxval=0.90, step=0.05)
bMinimumClosePosition = input.float(0.58, "B Minimum Close Position", minval=0.50, maxval=0.95, step=0.01)
bMaximumDistanceATR = input.float(1.30, "B Maximum EMA21 Distance ATR", minval=0.20, maxval=3.00, step=0.05)
bCooldownBars = input.int(5, "B Cooldown Bars", minval=1, maxval=60)
bMinimumQualityScore = input.int(1, "B Minimum Quality Score", minval=0, maxval=4)
bQualitySeparationATR = input.float(0.05, "B Quality Separation ATR", minval=0.00, maxval=0.50, step=0.01)
bQualitySlopeATR = input.float(0.010, "B Quality Slope ATR", minval=0.000, maxval=0.200, step=0.005)
bQualityMaxPullbackATR = input.float(0.55, "B Quality Maximum Pullback ATR", minval=0.05, maxval=1.50, step=0.05)
bQualityBodyRatio = input.float(0.45, "B Quality Body Ratio", minval=0.20, maxval=0.90, step=0.05)
bQualityClosePosition = input.float(0.62, "B Quality Close Position", minval=0.50, maxval=0.95, step=0.01)
//=============================================================================
// 30 SECOND DATA
//=============================================================================
ema8 = ta.ema(close, 8)
ema21 = ta.ema(close, 21)
ema50 = ta.ema(close, 50)
atr = ta.atr(atrLength)
atrAverage = ta.sma(atr, 50)
candleRange = high - low
candleBody = math.abs(close - open)
bodyRatio = candleRange > 0 ? candleBody / candleRange : 0.0
closePosition = candleRange > 0 ? (close - low) / candleRange : 0.5
lowerWick = math.min(open, close) - low
volatilityRatio = atrAverage > 0 ? atr / atrAverage : 0.0
volatilityOK = volatilityRatio >= minimumVolatilityRatio and volatilityRatio <= maximumVolatilityRatio
//=============================================================================
// CONFIRMED 15 MINUTE DATA
//=============================================================================
close15 = request.security(syminfo.tickerid, "15", close[1], lookahead=barmerge.lookahead_on)
ema8_15 = request.security(syminfo.tickerid, "15", ta.ema(close, 8)[1], lookahead=barmerge.lookahead_on)
ema21_15 = request.security(syminfo.tickerid, "15", ta.ema(close, 21)[1], lookahead=barmerge.lookahead_on)
ema21_15_prev = request.security(syminfo.tickerid, "15", ta.ema(close, 21)[2], lookahead=barmerge.lookahead_on)
ema50_15 = request.security(syminfo.tickerid, "15", ta.ema(close, 50)[1], lookahead=barmerge.lookahead_on)
atr15 = request.security(syminfo.tickerid, "15", ta.atr(14)[1], lookahead=barmerge.lookahead_on)
bull15Structure = close15 > ema8_15 and ema8_15 > ema21_15 and ema21_15 > ema50_15
bear15Structure = close15 < ema8_15 and ema8_15 < ema21_15 and ema21_15 < ema50_15
bull15Slope = ema21_15 > ema21_15_prev
bear15Slope = ema21_15 < ema21_15_prev
bull15Separation = ema8_15 - ema21_15
bear15Separation = ema21_15 - ema8_15
bull15Strength = bull15Separation >= atr15 * minimum15MSeparation
bear15Strength = bear15Separation >= atr15 * minimum15MSeparation
bull15Trend = bull15Structure and bull15Slope and bull15Strength
bear15Trend = bear15Structure and bear15Slope and bear15Strength
//=============================================================================
// CONFIRMED 5 MINUTE DATA
//=============================================================================
close5 = request.security(syminfo.tickerid, "5", close[1], lookahead=barmerge.lookahead_on)
ema8_5 = request.security(syminfo.tickerid, "5", ta.ema(close, 8)[1], lookahead=barmerge.lookahead_on)
ema21_5 = request.security(syminfo.tickerid, "5", ta.ema(close, 21)[1], lookahead=barmerge.lookahead_on)
ema21_5_prev = request.security(syminfo.tickerid, "5", ta.ema(close, 21)[2], lookahead=barmerge.lookahead_on)
ema50_5 = request.security(syminfo.tickerid, "5", ta.ema(close, 50)[1], lookahead=barmerge.lookahead_on)
atr5 = request.security(syminfo.tickerid, "5", ta.atr(14)[1], lookahead=barmerge.lookahead_on)
bull5Structure = close5 > ema21_5 and ema8_5 > ema21_5 and ema21_5 > ema50_5
bear5Structure = close5 < ema21_5 and ema8_5 < ema21_5 and ema21_5 < ema50_5
bull5Slope = ema21_5 > ema21_5_prev
bear5Slope = ema21_5 < ema21_5_prev
bull5Separation = ema8_5 - ema21_5
bear5Separation = ema21_5 - ema8_5
bull5Strength = bull5Separation >= atr5 * minimum5MSeparation
bear5Strength = bear5Separation >= atr5 * minimum5MSeparation
bull5Trend = bull5Structure and bull5Slope and bull5Strength
bear5Trend = bear5Structure and bear5Slope and bear5Strength
//=============================================================================
// 30 SECOND TREND
//=============================================================================
bull30Structure = ema8 > ema21 and ema21 > ema50
bear30Structure = ema8 < ema21 and ema21 < ema50
bull30Slope = ema8 > ema8[1] and ema21 > ema21[1]
bear30Slope = ema8 < ema8[1] and ema21 < ema21[1]
bull30Separation = ema8 - ema21
bear30Separation = ema21 - ema8
bull30SeparationOK = bull30Separation >= atr * minimum30SSeparationATR
bear30SeparationOK = bear30Separation >= atr * minimum30SSeparationATR
bullTrendAligned = bull15Trend and bull5Trend and bull30Structure and bull30Slope and bull30SeparationOK
bearTrendAligned = bear15Trend and bear5Trend and bear30Structure and bear30Slope and bear30SeparationOK
//=============================================================================
// A SHORT
//=============================================================================
aShortPullbackTouch = bear15Trend and bear5Trend and high >= ema8 and high <= ema21 + atr * aMaximumPullbackDepthATR
aShortBarsSincePullback = ta.barssince(aShortPullbackTouch)
aShortFreshPullback = not na(aShortBarsSincePullback) and aShortBarsSincePullback <= aPullbackLookback
aBearCandleQuality = close < open and bodyRatio >= aMinimumBodyRatio and closePosition <= 1.0 - aMinimumClosePosition
aBearConfirmation = aBearCandleQuality and aShortFreshPullback and close < ema8 and close < low[1]
aShortDistance = ema21 - close
aShortDistanceOK = aShortDistance >= 0 and aShortDistance <= atr * aMaximumEntryDistanceATR
var int aLastEntryBar = na
var int aLastShortUsedPullbackBar = na
aCooldownOK = na(aLastEntryBar) or bar_index - aLastEntryBar >= aCooldownBars
aCurrentShortPullbackBar = not na(aShortBarsSincePullback) ? bar_index - aShortBarsSincePullback : na
aShortNewPullbackOK = na(aLastShortUsedPullbackBar) or (not na(aCurrentShortPullbackBar) and aCurrentShortPullbackBar > aLastShortUsedPullbackBar)
aShortSignal = enableAShort and barstate.isconfirmed and is30Sec and inAShortSession and aShortSessionQualityOK and bearTrendAligned and aShortFreshPullback and aShortNewPullbackOK and aBearConfirmation and volatilityOK and aShortDistanceOK and aCooldownOK
//=============================================================================
// L LONG
//=============================================================================
priorLiquidityLow = ta.lowest(low, liquidityLookback)[1]
longSweepDepth = not na(priorLiquidityLow) ? priorLiquidityLow - low : na
longSweepDepthATR = not na(longSweepDepth) and atr > 0 ? longSweepDepth / atr : 0.0
longSweepDepthOK = longSweepDepthATR >= minimumSweepATR and longSweepDepthATR <= maximumSweepATR
longLiquiditySweep = not na(priorLiquidityLow) and low < priorLiquidityLow and close > priorLiquidityLow and longSweepDepthOK
liquidityBullBody = close > open and bodyRatio >= liquidityMinimumBodyRatio
liquidityBullClose = closePosition >= liquidityMinimumClosePosition
liquidityBullWick = lowerWick >= atr * liquidityMinimumWickATR
bullLiquidityRejection = liquidityBullBody and liquidityBullClose and liquidityBullWick
liquidityBullTrend = bull15Trend and bull5Trend
longEMA50Penetration = math.max(ema50 - low, 0.0)
longEMA50StructureOK = longEMA50Penetration <= atr * liquidityMaximumEMA50PenetrationATR
liquidityLongDistanceATR = atr > 0 ? math.abs(close - ema21) / atr : 999.0
liquidityLongDistanceOK = liquidityLongDistanceATR <= liquidityMaximumDistanceATR
var int liquidityLastEntryBar = na
var float lastSweptLongLevel = na
liquidityCooldownOK = na(liquidityLastEntryBar) or bar_index - liquidityLastEntryBar >= liquidityCooldownBars
newLongLiquidityLevel = na(lastSweptLongLevel) or priorLiquidityLow != lastSweptLongLevel
liquidityLongSignal = enableLLong and barstate.isconfirmed and is30Sec and inLLongSession and lLongSessionQualityOK and liquidityBullTrend and longLiquiditySweep and bullLiquidityRejection and longEMA50StructureOK and liquidityLongDistanceOK and volatilityOK and liquidityCooldownOK and newLongLiquidityLevel
//=============================================================================
// B LONG
//=============================================================================
bLongPullbackTouch = bull15Trend and bull5Trend and low <= ema21 and low >= ema21 - atr * bMaximumEMA21PenetrationATR
bLongBarsSincePullback = ta.barssince(bLongPullbackTouch)
bLongFreshPullback = not na(bLongBarsSincePullback) and bLongBarsSincePullback <= bPullbackLookback
bLongStructureHeld = ta.lowest(low, bPullbackLookback) > ema50
bBullCandle = close > open and bodyRatio >= bMinimumBodyRatio and closePosition >= bMinimumClosePosition
bBullResume = bBullCandle and close > ema8 and close > high[1]
bLongDistance = close - ema21
bLongDistanceATR = atr > 0 ? bLongDistance / atr : 999.0
bLongDistanceOK = bLongDistanceATR >= 0 and bLongDistanceATR <= bMaximumDistanceATR
bLongExpansionQuality = bull30Separation >= atr * bQualitySeparationATR
bLongSlopeNormalized = atr > 0 ? (ema21 - ema21[1]) / atr : 0.0
bLongSlopeQuality = bLongSlopeNormalized >= bQualitySlopeATR
bLongPullbackLow = not na(bLongBarsSincePullback) ? low[bLongBarsSincePullback] : na
bLongPullbackPenetration = not na(bLongPullbackLow) and atr > 0 ? math.max(ema21 - bLongPullbackLow, 0.0) / atr : 999.0
bLongDepthQuality = bLongPullbackPenetration <= bQualityMaxPullbackATR
bLongCandleQuality = bodyRatio >= bQualityBodyRatio and closePosition >= bQualityClosePosition
bLongQualityScore = (bLongExpansionQuality ? 1 : 0) + (bLongSlopeQuality ? 1 : 0) + (bLongDepthQuality ? 1 : 0) + (bLongCandleQuality ? 1 : 0)
bLongQualityOK = bLongQualityScore >= bMinimumQualityScore
var int bLastEntryBar = na
var int bLastLongUsedPullbackBar = na
bCooldownOK = na(bLastEntryBar) or bar_index - bLastEntryBar >= bCooldownBars
bCurrentLongPullbackBar = not na(bLongBarsSincePullback) ? bar_index - bLongBarsSincePullback : na
bLongNewPullback = na(bLastLongUsedPullbackBar) or (not na(bCurrentLongPullbackBar) and bCurrentLongPullbackBar > bLastLongUsedPullbackBar)
bLongSignal = enableBLong and barstate.isconfirmed and is30Sec and inBLongSession and bLongSessionQualityOK and bullTrendAligned and bLongFreshPullback and bLongStructureHeld and bBullResume and bLongDistanceOK and bLongNewPullback and bCooldownOK and volatilityOK and bLongQualityOK
//=============================================================================
// LIVE VIRTUAL TRADE ENGINE
//
// tradeState:
// 0 = flat
// 1 = long
// -1 = short
//=============================================================================
var int tradeState = 0
var float tradeEntry = na
var float tradeTarget = na
var float tradeStop = na
var int tradeEntryBar = na
var string tradeSetup = ""
var box activeTPBox = na
var box activeSLBox = na
var line activeEntryLine = na
var line activeTPLine = na
var line activeSLLine = na
var label activeTradeLabel = na
bool tradeClosedThisBar = false
bool tpHitThisBar = false
bool slHitThisBar = false
//=============================================================================
// CHECK ACTIVE TRADE
//
// TP/SL evaluation begins AFTER entry candle.
//=============================================================================
if barstate.isconfirmed and tradeState != 0 and bar_index > tradeEntryBar
if tradeState == 1
tpHitThisBar := high >= tradeTarget
slHitThisBar := low <= tradeStop
else if tradeState == -1
tpHitThisBar := low <= tradeTarget
slHitThisBar := high >= tradeStop
if tpHitThisBar or slHitThisBar
tradeClosedThisBar := true
if not na(activeTPBox)
box.set_right(activeTPBox, bar_index)
if not na(activeSLBox)
box.set_right(activeSLBox, bar_index)
if not na(activeEntryLine)
line.set_x2(activeEntryLine, bar_index)
if not na(activeTPLine)
line.set_x2(activeTPLine, bar_index)
if not na(activeSLLine)
line.set_x2(activeSLLine, bar_index)
if not keepCompletedTradeDrawings
if not na(activeTPBox)
box.delete(activeTPBox)
if not na(activeSLBox)
box.delete(activeSLBox)
if not na(activeEntryLine)
line.delete(activeEntryLine)
if not na(activeTPLine)
line.delete(activeTPLine)
if not na(activeSLLine)
line.delete(activeSLLine)
if not na(activeTradeLabel)
label.delete(activeTradeLabel)
tradeState := 0
tradeEntry := na
tradeTarget := na
tradeStop := na
tradeEntryBar := na
tradeSetup := ""
activeTPBox := na
activeSLBox := na
activeEntryLine := na
activeTPLine := na
activeSLLine := na
activeTradeLabel := na
//=============================================================================
// EXTEND ACTIVE TRADE DRAWINGS
//=============================================================================
if tradeState != 0
if not na(activeTPBox)
box.set_right(activeTPBox, bar_index)
if not na(activeSLBox)
box.set_right(activeSLBox, bar_index)
if not na(activeEntryLine)
line.set_x2(activeEntryLine, bar_index)
if not na(activeTPLine)
line.set_x2(activeTPLine, bar_index)
if not na(activeSLLine)
line.set_x2(activeSLLine, bar_index)
//=============================================================================
// ENTRY PRIORITY
//
// A SHORT -> L LONG -> B LONG
//=============================================================================
flat = tradeState == 0 and not tradeClosedThisBar
aShortEntry = aShortSignal and flat
lLongEntry = liquidityLongSignal and flat and not aShortEntry
bLongEntry = bLongSignal and flat and not aShortEntry and not lLongEntry
buySignal = lLongEntry or bLongEntry
sellSignal = aShortEntry
//=============================================================================
// IDENTIFY SETUP
//=============================================================================
string currentSetup = ""
if aShortEntry
currentSetup := "A SHORT"
else if lLongEntry
currentSetup := "L LONG"
else if bLongEntry
currentSetup := "B LONG"
//=============================================================================
// REGISTER LONG TRADE
//=============================================================================
if buySignal
tradeState := 1
tradeEntry := close
tradeTarget := tradeEntry + targetDistance
tradeStop := tradeEntry - stopDistance
tradeEntryBar := bar_index
tradeSetup := currentSetup
if lLongEntry
liquidityLastEntryBar := bar_index
lastSweptLongLevel := priorLiquidityLow
if bLongEntry
bLastEntryBar := bar_index
bLastLongUsedPullbackBar := bCurrentLongPullbackBar
if showTradeBoxes
activeTPBox := box.new(left=bar_index, top=tradeTarget, right=bar_index + 1, bottom=tradeEntry, border_color=color.new(color.lime, 20), bgcolor=color.new(color.lime, 88))
activeSLBox := box.new(left=bar_index, top=tradeEntry, right=bar_index + 1, bottom=tradeStop, border_color=color.new(color.red, 20), bgcolor=color.new(color.red, 88))
if showEntryLine
activeEntryLine := line.new(x1=bar_index, y1=tradeEntry, x2=bar_index + 1, y2=tradeEntry, color=color.white, width=2)
if showTPLine
activeTPLine := line.new(x1=bar_index, y1=tradeTarget, x2=bar_index + 1, y2=tradeTarget, color=color.lime, width=2)
if showSLLine
activeSLLine := line.new(x1=bar_index, y1=tradeStop, x2=bar_index + 1, y2=tradeStop, color=color.red, width=2)
if showTradeLabels
activeTradeLabel := label.new(bar_index, low, tradeSetup + "\nBUY\nEntry: " + str.tostring(tradeEntry, format.mintick) + "\nTP: " + str.tostring(tradeTarget, format.mintick) + "\nSL: " + str.tostring(tradeStop, format.mintick), style=label.style_label_up, textcolor=color.white, color=color.new(color.green, 15), size=size.small)
//=============================================================================
// REGISTER SHORT TRADE
//=============================================================================
if sellSignal
tradeState := -1
tradeEntry := close
tradeTarget := tradeEntry - targetDistance
tradeStop := tradeEntry + stopDistance
tradeEntryBar := bar_index
tradeSetup := currentSetup
aLastEntryBar := bar_index
aLastShortUsedPullbackBar := aCurrentShortPullbackBar
if showTradeBoxes
activeTPBox := box.new(left=bar_index, top=tradeEntry, right=bar_index + 1, bottom=tradeTarget, border_color=color.new(color.lime, 20), bgcolor=color.new(color.lime, 88))
activeSLBox := box.new(left=bar_index, top=tradeStop, right=bar_index + 1, bottom=tradeEntry, border_color=color.new(color.red, 20), bgcolor=color.new(color.red, 88))
if showEntryLine
activeEntryLine := line.new(x1=bar_index, y1=tradeEntry, x2=bar_index + 1, y2=tradeEntry, color=color.white, width=2)
if showTPLine
activeTPLine := line.new(x1=bar_index, y1=tradeTarget, x2=bar_index + 1, y2=tradeTarget, color=color.lime, width=2)
if showSLLine
activeSLLine := line.new(x1=bar_index, y1=tradeStop, x2=bar_index + 1, y2=tradeStop, color=color.red, width=2)
if showTradeLabels
activeTradeLabel := label.new(bar_index, high, tradeSetup + "\nSELL\nEntry: " + str.tostring(tradeEntry, format.mintick) + "\nTP: " + str.tostring(tradeTarget, format.mintick) + "\nSL: " + str.tostring(tradeStop, format.mintick), style=label.style_label_down, textcolor=color.white, color=color.new(color.red, 15), size=size.small)
//=============================================================================
// SIGNAL TRIANGLES
//=============================================================================
plotshape(buySignal, title="V43 BUY", style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.small)
plotshape(sellSignal, title="V43 SELL", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
//=============================================================================
// ALERT CONDITIONS
//=============================================================================
alertcondition(buySignal, title="V43 BUY", message="XAUUSD V43 QUALITY LIVE BUY")
alertcondition(sellSignal, title="V43 SELL", message="XAUUSD V43 QUALITY LIVE SELL")
alertcondition(buySignal or sellSignal, title="V43 BUY OR SELL", message="XAUUSD V43 QUALITY LIVE new signal")
//=============================================================================
// DYNAMIC ALERTS
//
// TradingView alert:
// Condition -> Any alert() function call
//
// Dynamic message includes:
// Setup
// Direction
// Entry
// TP
// SL
//=============================================================================
if buySignal
alert("XAUUSD V43 | " + tradeSetup + " | BUY | Entry: " + str.tostring(tradeEntry, format.mintick) + " | TP: " + str.tostring(tradeTarget, format.mintick) + " | SL: " + str.tostring(tradeStop, format.mintick), alert.freq_once_per_bar_close)
if sellSignal
alert("XAUUSD V43 | " + tradeSetup + " | SELL | Entry: " + str.tostring(tradeEntry, format.mintick) + " | TP: " + str.tostring(tradeTarget, format.mintick) + " | SL: " + str.tostring(tradeStop, format.mintick), alert.freq_once_per_bar_close)