The HTF Exhaustion Gold Scalper

Mendhaz · strategy · 96 行 · 点赞 9 · TradingView 原页

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

Pine Script

//@version=6
strategy("HTF WPR & RSI Momentum Scalper - V3", overlay = true, initial_capital = 3000, default_qty_type = strategy.cash, default_qty_value = 200)
 
// --- HTF Inputs ---
string i_htf1 = input.timeframe("60", "HTF 1 (1 Hour)", group = "Trend Bias")
string i_htf2 = input.timeframe("1D", "HTF 2 (1 Day)", group = "Trend Bias")
int i_emaLen  = input.int(21, "HTF EMA Length", group = "Trend Bias")
 
// --- Oscillator Inputs ---
int i_wprLen  = input.int(14, "WPR Length", group = "Momentum")
int i_wprOb   = input.int(-30, "WPR Overbought", group = "Momentum")
int i_wprOs   = input.int(-70, "WPR Oversold", group = "Momentum")
 
int i_rsiLen  = input.int(14, "RSI Length", group = "Momentum")
int i_rsiBull = input.int(50, "RSI Bullish Threshold", group = "Momentum")
int i_rsiBear = input.int(50, "RSI Bearish Threshold", group = "Momentum")
 
// --- Risk & Filters ---
float i_atrMult  = input.float(23.0, "ATR Stop Multiplier", group = "Risk")
float i_rr       = input.float(2.0, "Risk/Reward Ratio", group = "Risk")
bool  i_useVol   = input.bool(true, "Require Volume > SMA", group = "Filters")
 
// --- Session Inputs (UTC) ---
bool i_useAsian   = input.bool(true, "Trade Asian Session", group = "Sessions")
string i_asianSess = input.session("0000-0800", "Asian Session Hours (UTC)", group = "Sessions")
 
bool i_useLonNY   = input.bool(true, "Trade London/NY Overlap", group = "Sessions")
string i_lonNySess = input.session("1300-1700", "Lon/NY Overlap Hours (UTC)", group = "Sessions")
 
// --- Session Logic ---
bool inAsian      = not na(time(timeframe.period, i_asianSess, "UTC"))
bool inLonNY      = not na(time(timeframe.period, i_lonNySess, "UTC"))
bool sessionValid = (i_useAsian and inAsian) or (i_useLonNY and inLonNY)
 
// --- HTF Bias ---
float baseEma    = ta.ema(close, i_emaLen)
float htf1_ema   = request.security(syminfo.tickerid, i_htf1, baseEma)
float htf1_close = request.security(syminfo.tickerid, i_htf1, close)
float htf2_ema   = request.security(syminfo.tickerid, i_htf2, baseEma)
float htf2_close = request.security(syminfo.tickerid, i_htf2, close)
 
bool bullishBias = (htf1_close > htf1_ema) and (htf2_close > htf2_ema)
bool bearishBias = (htf1_close < htf1_ema) and (htf2_close < htf2_ema)
 
// --- Momentum & Volume Triggers ---
float wpr = ta.wpr(i_wprLen)
float rsi = ta.rsi(close, i_rsiLen)
float atr = ta.atr(14)
 
float volSma = ta.sma(volume, 20)
bool volValid = i_useVol ? (volume > volSma) : true
 
bool wprLongHook  = ta.crossover(wpr, i_wprOs)
bool wprShortHook = ta.crossunder(wpr, i_wprOb)
 
bool longSignal  = sessionValid and bullishBias and wprLongHook and (rsi > i_rsiBull) and volValid
bool shortSignal = sessionValid and bearishBias and wprShortHook and (rsi < i_rsiBear) and volValid
 
// --- Execution ---
var float slLevel = na
var float tpLevel = na
 
if longSignal and strategy.position_size == 0
    slLevel := close - (atr * i_atrMult)
    tpLevel := close + (atr * i_atrMult * i_rr)
    strategy.entry("Long", strategy.long)
 
if shortSignal and strategy.position_size == 0
    slLevel := close + (atr * i_atrMult)
    tpLevel := close - (atr * i_atrMult * i_rr)
    strategy.entry("Short", strategy.short)
 
if strategy.position_size > 0
    strategy.exit("Exit Long", "Long", stop = slLevel, limit = tpLevel)
 
if strategy.position_size < 0
    strategy.exit("Exit Short", "Short", stop = slLevel, limit = tpLevel)
 
// --- Visuals & Dashboard ---
plot(htf1_ema, "1H EMA", color = color.blue)
plot(htf2_ema, "1D EMA", color = color.purple)
 
bgcolor(i_useAsian and inAsian ? color.new(color.blue, 90) : na, title = "Asian Session")
bgcolor(i_useLonNY and inLonNY ? color.new(color.purple, 90) : na, title = "Lon/NY Session")
 
// Statistics Dashboard
var table statsTable = table.new(position.top_right, 2, 2, border_width = 1)
if barstate.islastconfirmedhistory
    table.cell(statsTable, 0, 0, "Total Trades", bgcolor = color.gray, text_color = color.white)
    table.cell(statsTable, 1, 0, str.tostring(strategy.closedtrades), bgcolor = color.white, text_color = color.black)
    
    float grossProfit = strategy.grossprofit
    float grossLoss = strategy.grossloss
    float pf = grossLoss > 0 ? grossProfit / grossLoss : grossProfit
    table.cell(statsTable, 0, 1, "Profit Factor", bgcolor = color.gray, text_color = color.white)
    table.cell(statsTable, 1, 1, str.tostring(pf, "#.###"), bgcolor = color.white, text_color = color.black)

← 返回列表