StratixAlgo | Gold Scalper Pro V2

stratixalgoofficial · strategy · 328 行 · 点赞 20 · TradingView 原页

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

Pine Script

//@version=6
strategy("StratixAlgo | Gold Scalper Pro V2",
     shorttitle="GSP V2",
     overlay=true,
     pyramiding=0,
     calc_on_every_tick=false,
     process_orders_on_close=true,
     max_labels_count=500,
     max_lines_count=500)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// GOLD SCALPER PRO V2
// XAUUSD | 5 MINUTE | HIGH ACCURACY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
//──────────────────────────────────────
// INPUTS
//──────────────────────────────────────
 
// Trend Settings
fastEmaLen = input.int(20, "Fast EMA", group="Trend Settings")
slowEmaLen = input.int(50, "Slow EMA", group="Trend Settings")
htfEmaLen  = input.int(50, "15M EMA", group="Trend Settings")
 
// Momentum Settings
rsiLen     = input.int(14, "RSI Length", group="Momentum")
buyRsi     = input.int(55, "BUY RSI Minimum", group="Momentum")
sellRsi    = input.int(45, "SELL RSI Maximum", group="Momentum")
 
// Volatility Settings
atrLen     = input.int(14, "ATR Length", group="Volatility")
atrAvgLen  = input.int(50, "ATR Average Length", group="Volatility")
minAtrMult = input.float(0.85, "Minimum ATR Multiplier", step=0.05, group="Volatility")
 
// Structure Settings
structureLookback = input.int(10, "Structure Lookback", minval=3, group="Market Structure")
sweepLookback     = input.int(10, "Liquidity Sweep Lookback", minval=3, group="Liquidity")
 
// Risk Management
slAtrBuffer  = input.float(0.50, "SL ATR Buffer", step=0.1, group="Risk Management")
rrTP1        = input.float(1.0, "TP1 RR", step=0.25, group="Risk Management")
rrTP2        = input.float(2.0, "TP2 RR", step=0.25, group="Risk Management")
rrTP3        = input.float(3.0, "TP3 RR", step=0.25, group="Risk Management")
useBreakEven = input.bool(true, "Enable Breakeven Logic", group="Risk Management")
 
// Signal Quality
minimumScore = input.int(80, "Minimum Signal Score", minval=50, maxval=100, group="Signal Quality")
 
// Session Settings
useSessionFilter = input.bool(true, "Enable Session Filter", group="Trading Sessions")
useLondon     = input.bool(true, "London Session", group="Trading Sessions")
londonSession = input.session("0700-1100", "London Hours (UTC)", group="Trading Sessions")
useNewYork    = input.bool(true, "New York Session", group="Trading Sessions")
nySession     = input.session("1300-1700", "New York Hours (UTC)", group="Trading Sessions")
 
// Visual Settings
showStructure = input.bool(true, "Show BOS / CHoCH", group="Visuals")
showLevels    = input.bool(true, "Show SL / TP Levels", group="Visuals")
showDashboard = input.bool(true, "Show Signal Dashboard", group="Visuals")
 
//──────────────────────────────────────
// CORE INDICATORS
//──────────────────────────────────────
 
emaFast    = ta.ema(close, fastEmaLen)
emaSlow    = ta.ema(close, slowEmaLen)
vwapValue  = ta.vwap(hlc3)
 
rsiValue   = ta.rsi(close, rsiLen)
atrValue   = ta.atr(atrLen)
atrAverage = ta.sma(atrValue, atrAvgLen)
 
//──────────────────────────────────────
// HIGHER TIMEFRAME TREND
//──────────────────────────────────────
 
htfClose = request.security(syminfo.tickerid, "15", close, lookahead=barmerge.lookahead_off)
htfEMA   = request.security(syminfo.tickerid, "15", ta.ema(close, htfEmaLen), lookahead=barmerge.lookahead_off)
 
htfBull = htfClose > htfEMA
htfBear = htfClose < htfEMA
 
//──────────────────────────────────────
// SESSION FILTER
//──────────────────────────────────────
 
inLondon  = not na(time(timeframe.period, londonSession, "UTC"))
inNewYork = not na(time(timeframe.period, nySession, "UTC"))
 
validSession = not useSessionFilter or (useLondon and inLondon) or (useNewYork and inNewYork)
 
//──────────────────────────────────────
// VOLATILITY + NO TRADE ZONE
//──────────────────────────────────────
 
volatilityOK   = atrValue >= atrAverage * minAtrMult
emaDistance    = math.abs(emaFast - emaSlow)
emaCompression = emaDistance < atrValue * 0.20
noTradeZone    = not volatilityOK or emaCompression
 
//──────────────────────────────────────
// MARKET STRUCTURE
//──────────────────────────────────────
 
previousHigh = ta.highest(high, structureLookback)[1]
previousLow  = ta.lowest(low, structureLookback)[1]
 
bullBOS = close > previousHigh
bearBOS = close < previousLow
 
bullCHoCH = bullBOS and emaFast > emaSlow
bearCHoCH = bearBOS and emaFast < emaSlow
 
//──────────────────────────────────────
// LIQUIDITY SWEEP DETECTION
//──────────────────────────────────────
 
sweepHigh = ta.highest(high, sweepLookback)[1]
sweepLow  = ta.lowest(low, sweepLookback)[1]
 
bullSweep = low < sweepLow and close > sweepLow
bearSweep = high > sweepHigh and close < sweepHigh
 
//──────────────────────────────────────
// TREND CONDITIONS
//──────────────────────────────────────
 
bullTrend = htfBull and emaFast > emaSlow and close > vwapValue
bearTrend = htfBear and emaFast < emaSlow and close < vwapValue
 
//──────────────────────────────────────
// PULLBACK DETECTION
//──────────────────────────────────────
 
bullPullback = low <= emaFast and close > emaFast and close > open
bearPullback = high >= emaFast and close < emaFast and close < open
 
//──────────────────────────────────────
// MOMENTUM
//──────────────────────────────────────
 
bullMomentum = rsiValue >= buyRsi
bearMomentum = rsiValue <= sellRsi
 
//──────────────────────────────────────
// CANDLE CONFIRMATION
//──────────────────────────────────────
 
bullCandle = close > open and close > close[1]
bearCandle = close < open and close < close[1]
 
//──────────────────────────────────────
// SIGNAL QUALITY SCORE
//──────────────────────────────────────
 
int buyScore = 0
buyScore += htfBull ? 20 : 0
buyScore += emaFast > emaSlow ? 15 : 0
buyScore += close > vwapValue ? 15 : 0
buyScore += bullMomentum ? 10 : 0
buyScore += bullSweep ? 15 : 0
buyScore += bullBOS ? 15 : 0
buyScore += validSession ? 10 : 0
 
int sellScore = 0
sellScore += htfBear ? 20 : 0
sellScore += emaFast < emaSlow ? 15 : 0
sellScore += close < vwapValue ? 15 : 0
sellScore += bearMomentum ? 10 : 0
sellScore += bearSweep ? 15 : 0
sellScore += bearBOS ? 15 : 0
sellScore += validSession ? 10 : 0
 
//──────────────────────────────────────
// HIGH ACCURACY ENTRY ENGINE
//──────────────────────────────────────
 
bullStructureConfirm = bullBOS or bullSweep
bearStructureConfirm = bearBOS or bearSweep
 
buySetup = bullTrend and bullPullback and bullMomentum and bullCandle and bullStructureConfirm and validSession and not noTradeZone and buyScore >= minimumScore
 
sellSetup = bearTrend and bearPullback and bearMomentum and bearCandle and bearStructureConfirm and validSession and not noTradeZone and sellScore >= minimumScore
 
buySignal  = buySetup and not buySetup[1]
sellSignal = sellSetup and not sellSetup[1]
 
//──────────────────────────────────────
// DYNAMIC STOP LOSS / TAKE PROFIT
//──────────────────────────────────────
 
longSwingLow   = ta.lowest(low, structureLookback)
shortSwingHigh = ta.highest(high, structureLookback)
 
longSL  = longSwingLow - atrValue * slAtrBuffer
shortSL = shortSwingHigh + atrValue * slAtrBuffer
 
longRisk  = close - longSL
shortRisk = shortSL - close
 
longTP1 = close + longRisk * rrTP1
longTP2 = close + longRisk * rrTP2
longTP3 = close + longRisk * rrTP3
 
shortTP1 = close - shortRisk * rrTP1
shortTP2 = close - shortRisk * rrTP2
shortTP3 = close - shortRisk * rrTP3
 
//──────────────────────────────────────
// ACTIVE TRADE STATE
//──────────────────────────────────────
 
var float activeSL    = na
var float activeTP1   = na
var float activeTP2   = na
var float activeTP3   = na
var float activeEntry = na
var bool  beActive    = false
 
//──────────────────────────────────────
// STRATEGY EXECUTION
//──────────────────────────────────────
 
if buySignal and strategy.position_size <= 0 and longRisk > syminfo.mintick
    activeEntry := close
    activeSL    := longSL
    activeTP1   := longTP1
    activeTP2   := longTP2
    activeTP3   := longTP3
    beActive    := false
 
    strategy.entry("BUY", strategy.long)
 
    strategy.exit("BUY TP1", from_entry="BUY", qty_percent=33, stop=activeSL, limit=activeTP1)
    strategy.exit("BUY TP2", from_entry="BUY", qty_percent=33, stop=activeSL, limit=activeTP2)
    strategy.exit("BUY TP3", from_entry="BUY", qty_percent=34, stop=activeSL, limit=activeTP3)
 
if sellSignal and strategy.position_size >= 0 and shortRisk > syminfo.mintick
    activeEntry := close
    activeSL    := shortSL
    activeTP1   := shortTP1
    activeTP2   := shortTP2
    activeTP3   := shortTP3
    beActive    := false
 
    strategy.entry("SELL", strategy.short)
 
    strategy.exit("SELL TP1", from_entry="SELL", qty_percent=33, stop=activeSL, limit=activeTP1)
    strategy.exit("SELL TP2", from_entry="SELL", qty_percent=33, stop=activeSL, limit=activeTP2)
    strategy.exit("SELL TP3", from_entry="SELL", qty_percent=34, stop=activeSL, limit=activeTP3)
 
//──────────────────────────────────────
// BREAKEVEN MANAGEMENT
//──────────────────────────────────────
 
if strategy.position_size > 0
    if useBreakEven and not beActive and high >= activeTP1
        beActive := true
    stopLevelL = beActive ? activeEntry : activeSL
    strategy.exit("BUY TP1", from_entry="BUY", qty_percent=33, stop=stopLevelL, limit=activeTP1)
    strategy.exit("BUY TP2", from_entry="BUY", qty_percent=33, stop=stopLevelL, limit=activeTP2)
    strategy.exit("BUY TP3", from_entry="BUY", qty_percent=34, stop=stopLevelL, limit=activeTP3)
 
if strategy.position_size < 0
    if useBreakEven and not beActive and low <= activeTP1
        beActive := true
    stopLevelS = beActive ? activeEntry : activeSL
    strategy.exit("SELL TP1", from_entry="SELL", qty_percent=33, stop=stopLevelS, limit=activeTP1)
    strategy.exit("SELL TP2", from_entry="SELL", qty_percent=33, stop=stopLevelS, limit=activeTP2)
    strategy.exit("SELL TP3", from_entry="SELL", qty_percent=34, stop=stopLevelS, limit=activeTP3)
 
if strategy.position_size == 0 and not (buySignal or sellSignal)
    beActive := false
 
//──────────────────────────────────────
// VISUALS
//──────────────────────────────────────
 
plot(emaFast, "Fast EMA", color=color.new(color.aqua, 0), linewidth=1)
plot(emaSlow, "Slow EMA", color=color.new(color.orange, 0), linewidth=1)
plot(vwapValue, "VWAP", color=color.new(color.purple, 20), linewidth=1)
 
plotshape(buySignal,  "BUY",  shape.labelup,   location.belowbar, color=color.new(color.green, 0), textcolor=color.white, text="BUY",  size=size.small)
plotshape(sellSignal, "SELL", shape.labeldown, location.abovebar, color=color.new(color.red, 0),   textcolor=color.white, text="SELL", size=size.small)
 
plotshape(showStructure and bullCHoCH and not bullCHoCH[1], "Bull BOS", shape.triangleup,   location.belowbar, color=color.new(color.teal, 30), size=size.tiny, text="BOS")
plotshape(showStructure and bearCHoCH and not bearCHoCH[1], "Bear BOS", shape.triangledown, location.abovebar, color=color.new(color.maroon, 30), size=size.tiny, text="BOS")
 
inTrade = strategy.position_size != 0
plot(showLevels and inTrade ? activeEntry : na, "Entry", color=color.gray,   style=plot.style_linebr)
plot(showLevels and inTrade ? (beActive ? activeEntry : activeSL) : na, "SL", color=color.red, style=plot.style_linebr)
plot(showLevels and inTrade ? activeTP1 : na, "TP1", color=color.new(color.green, 20), style=plot.style_linebr)
plot(showLevels and inTrade ? activeTP2 : na, "TP2", color=color.new(color.green, 40), style=plot.style_linebr)
plot(showLevels and inTrade ? activeTP3 : na, "TP3", color=color.new(color.green, 60), style=plot.style_linebr)
 
bgcolor(noTradeZone ? color.new(color.gray, 92) : na)
 
//──────────────────────────────────────
// DASHBOARD
//──────────────────────────────────────
 
var table dash = table.new(position.top_right, 2, 6, border_width=1)
 
if showDashboard and barstate.islast
    table.cell(dash, 0, 0, "GSP V2", text_color=color.white, bgcolor=color.new(color.blue, 20))
    table.cell(dash, 1, 0, syminfo.ticker, text_color=color.white, bgcolor=color.new(color.blue, 20))
 
    table.cell(dash, 0, 1, "HTF Trend", text_color=color.white, bgcolor=color.new(color.gray, 30))
    table.cell(dash, 1, 1, htfBull ? "BULL" : htfBear ? "BEAR" : "-", text_color=color.white, bgcolor=htfBull ? color.green : htfBear ? color.red : color.gray)
 
    table.cell(dash, 0, 2, "Session", text_color=color.white, bgcolor=color.new(color.gray, 30))
    table.cell(dash, 1, 2, validSession ? "ACTIVE" : "CLOSED", text_color=color.white, bgcolor=validSession ? color.green : color.red)
 
    table.cell(dash, 0, 3, "Volatility", text_color=color.white, bgcolor=color.new(color.gray, 30))
    table.cell(dash, 1, 3, noTradeZone ? "NO TRADE" : "OK", text_color=color.white, bgcolor=noTradeZone ? color.red : color.green)
 
    table.cell(dash, 0, 4, "Buy Score", text_color=color.white, bgcolor=color.new(color.gray, 30))
    table.cell(dash, 1, 4, str.tostring(buyScore), text_color=color.white, bgcolor=buyScore >= minimumScore ? color.green : color.gray)
 
    table.cell(dash, 0, 5, "Sell Score", text_color=color.white, bgcolor=color.new(color.gray, 30))
    table.cell(dash, 1, 5, str.tostring(sellScore), text_color=color.white, bgcolor=sellScore >= minimumScore ? color.red : color.gray)
 
//──────────────────────────────────────
// ALERTS
//──────────────────────────────────────
 
alertcondition(buySignal,  "GSP V2 BUY",  "Gold Scalper Pro V2: BUY signal")
alertcondition(sellSignal, "GSP V2 SELL", "Gold Scalper Pro V2: SELL signal")

← 返回列表