KhodamGBP/USDOANDA:GBPUSDmehranmarufzad// @version=5 strategy("Asian Liquidity Hunt + SMT (EURUSD main) - Demo", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1) // ---------------------- INPUTS ---------------------- asiaStartNY = input.int(title="Asia session start (NY hour, 24h)", defval=20, minval=0, maxval=23) asiaEndNY = input.int(title="Asia session end (NY hour, 24h)", defval=0, minval=0, maxval=23) execStartNY = input.int(title="Execution start (NY hour)", defval=14, minval=0, maxval=23) execEndNY = input.int(title="Execution end (NY hour)", defval=16, minval=0, maxval=23) sym_gbpusd = input.symbol("FX:GBPUSD", "GBPUSD symbol (for SMT)") sym_dxy = input.symbol("TVC:DXY", "DXY symbol (for SMT)") lookback_piv = input.int(5, "Pivot lookback (bars)", minval=2) sweep_wick_perc = input.float(0.002, "Sweep wick min % of range (0.002 = 0.2%)", step=0.0001) sl_pips = input.float(20, "Stop Loss (pips)") rr = input.float(2.0, "Reward/Risk ratio (TP = RR * SL)") useOnlyExecutionWindow = input.bool(true, "Only trade inside Exec window (NY)") // For time conversion ny_tz = "America/New_York" // Convert pips to price for current symbol (assumes 1 pip = 0.0001 for FX major; for JPY pairs adjust) pip_mult = input.float(0.0001, "Pip size (use 0.01 for JPY pairs)") sl_price = sl_pips * pip_mult tp_price = sl_price * rr // ---------------------- ASIAN RANGE (previous day) ---------------------- // We'll compute Asia high/low for the previous calendar day using NY timezone hours. var float asiaHigh = na var float asiaLow = na var int asiaDay = na hNY = hour(time, ny_tz) dNY = dayofmonth(time, ny_tz) // Reset at new day if na(asiaDay) or dNY != asiaDay asiaHigh := na asiaLow := na asiaDay := dNY // Consider bars that fall into Asia session (if asiaEnd < asiaStart, it crosses midnight) inAsiaSession = false if asiaStartNY = asiaStartNY and hNY < asiaEndNY) else // wraps midnight inAsiaSession := (hNY >= asiaStartNY) or (hNY < asiaEndNY) if inAsiaSession asiaHigh := nz(asiaHigh, high) asiaLow := nz(asiaLow, low) asiaHigh := math.max(asiaHigh, high) asiaLow := math.min(asiaLow, low) // Plot Asian box (for current day's Asia) — only when defined plot_asia = input.bool(true, "Plot Asia range") if plot_asia and not na(asiaHigh) boxColor = color.new(color.blue, 90) var box b = na // draw box per day (simple: one persistent rect) // remove/replace old box if any if na(b) b := box.new(left=bar_index, top=asiaHigh, right=bar_index+1, bottom=asiaLow, border_color=color.new(color.blue, 80), bgcolor=boxColor) else box.set_top(b, asiaHigh) box.set_bottom(b, asiaLow) box.set_right(b, bar_index+1) // ---------------------- LIQUIDITY SWEEP DETECTION ---------------------- // Sweep above (short-hunt): high > asiaHigh and close back inside (close asiaHigh) and (close = rng * sweep_wick_perc sweep_up_price := high // Sweep below (long-hunt): low < asiaLow and close back inside sweep_dn = false sweep_dn_price = na if not na(asiaLow) if (low < asiaLow) and (close >= asiaLow - (asiaHigh - asiaLow) * 0.02) wick = math.min(open, close) - low rng = asiaHigh - asiaLow sweep_dn := wick >= rng * sweep_wick_perc sweep_dn_price := low plotshape(sweep_up, title="Sweep Up", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sweep↑") plotshape(sweep_dn, title="Sweep Down", location=location.belowbar, color=color.green, style=shape.labelup, text="Sweep↓") // ---------------------- SMT / DIVERGENCE (Cross-symbol swing compare) ---------------------- // We'll detect recent pivot highs/lows on EUR (chart), GBP and DXY and compare last two pivots to infer SMT. // Function to get latest pivot values using ta.pivothigh / pivotlow f_get_last_piv_high(_src, _left, _right) => ph = ta.pivothigh(_src, _left, _right) // find latest non-na pivot value var float last = na if not na(ph) last := ph last f_get_last_piv_low(_src, _left, _right) => pl = ta.pivotlow(_src, _left, _right) var float last = na if not na(pl) last := pl last // Using close series for pivot detection eur_ph = ta.pivothigh(close, lookback_piv, lookback_piv) eur_pl = ta.pivotlow(close, lookback_piv, lookback_piv) // For GBP and DXY use security/request.security gbp_close = request.security(sym_gbpusd, timeframe.period, close, lookahead=barmerge.lookahead_on) dxy_close = request.security(sym_dxy, timeframe.period, close, lookahead=barmerge.lookahead_on) gbp_ph = request.security(sym_gbpusd, timeframe.period, ta.pivothigh(close, lookback_piv, lookback_piv), lookahead=barmerge.lookahead_on) gbp_pl = request.security(sym_gbpusd, timeframe.period, ta.pivotlow(close, lookback_piv, lookback_piv), lookahead=barmerge.lookahead_on) dxy_ph = request.security(sym_dxy, timeframe.period, ta.pivothigh(close, lookback_piv, lookback_piv), lookahead=barmerge.lookahead_on) dxy_pl = request.security(sym_dxy, timeframe.period, ta.pivotlow(close, lookback_piv, lookback_piv), lookahead=barmerge.lookahead_on) // Evaluate SMT conditions conservatively: // For bullish SMT (supporting a BUY after sweep_dn): // - EUR made a new lower low (swing low value smaller than previous), but GBP did NOT make lower low (i.e., GBP_pl >= prev GBP_pl) // - and DXY did NOT make higher high (i.e., DXY_ph USD not strengthening // Because detecting "previous" pivot values robustly is complex in a single script, we'll use a simpler proxy: // - Compare most recent pivot low on EUR vs previous pivot low (shifted) using arrays of recent pivot lows // Collect pivot lows for EUR (store last two) var float eur_pl_last = na var float eur_pl_prev = na if not na(eur_pl) eur_pl_prev := eur_pl_last eur_pl_last := eur_pl // For GBP var float gbp_pl_last = na var float gbp_pl_prev = na gbp_pl_cur = request.security(sym_gbpusd, timeframe.period, ta.pivotlow(close, lookback_piv, lookback_piv), lookahead=barmerge.lookahead_on) if not na(gbp_pl_cur) gbp_pl_prev := gbp_pl_last gbp_pl_last := gbp_pl_cur // For DXY pivot highs (collect last two) var float dxy_ph_last = na var float dxy_ph_prev = na dxy_ph_cur = request.security(sym_dxy, timeframe.period, ta.pivothigh(close, lookback_piv, lookback_piv), lookahead=barmerge.lookahead_on) if not na(dxy_ph_cur) dxy_ph_prev := dxy_ph_last dxy_ph_last := dxy_ph_cur // Bullish SMT condition (approx) bull_smt = false if not na(eur_pl_last) and not na(eur_pl_prev) if not na(gbp_pl_last) gbp_no_new_low = na(gbp_pl_prev) or (gbp_pl_last >= gbp_pl_prev) dxy_no_new_high = na(dxy_ph_prev) or (dxy_ph_last eur_ph_prev) and gbp_no_new_high and dxy_no_new_low // Plot simple SMT signals plotchar(bull_smt ? 1 : 0, title="Bull SMT", char='▲', location=location.bottom, color=color.green, size=size.tiny) plotchar(bear_smt ? 1 : 0, title="Bear SMT", char='▼', location=location.top, color=color.red, size=size.tiny) // ---------------------- EXECUTION WINDOW (NY) ---------------------- inExecWindow = false if execStartNY = execStartNY and hNY < execEndNY) else inExecWindow := (hNY >= execStartNY) or (hNY < execEndNY) // Optionally enforce exec window canTradeNow = useOnlyExecutionWindow ? inExecWindow : true // ---------------------- ENTRY / EXIT RULES ---------------------- longCondition = canTradeNow and sweep_dn and bull_smt shortCondition = canTradeNow and sweep_up and bear_smt // Avoid duplicate entries quickly: require no open position allowLong = (strategy.position_size == 0) or (strategy.position_size < 0) allowShort = (strategy.position_size == 0) or (strategy.position_size > 0) // place entries if (longCondition) and allowLong sl = close - sl_price tp = close + tp_price strategy.entry("Long_SWEEP", strategy.long) strategy.exit("ExitLong","Long_SWEEP", stop=sl, limit=tp) if (shortCondition) and allowShort sl = close + sl_price tp = close - tp_price strategy.entry("Short_SWEEP", strategy.short) strategy.exit("ExitShort","Short_SWEEP", stop=sl, limit=tp) // Plot SL/TP lines for last entry if strategy.position_size > 0 plot(strategy.position_avg_price - sl_price, title="SL Long", style=plot.style_line, color=color.red) plot(strategy.position_avg_price + tp_price, title="TP Long", style=plot.style_line, color=color.green) else if strategy.position_size < 0 plot(strategy.position_avg_price + sl_price, title="SL Short", style=plot.style_line, color=color.red) plot(strategy.position_avg_price - tp_price, title="TP Short", style=plot.style_line, color=color.green) // ---------------------- NOTES / INFO ---------------------- var label info = na if barstate.islast txt = "Asian H:" + (na(asiaHigh) ? "n/a" : str.tostring(asiaHigh, format.mintick)) + " L:" + (na(asiaLow) ? "n/a" : str.tostring(asiaLow, format.mintick)) + "\nExec window: " + str.tostring(execStartNY) + "-" + str.tostring(execEndNY) + " NY" label.delete(info) info := label.new(bar_index, high, txt, xloc=xloc.bar_index, yloc=yloc.abovebar, style=label.style_label_left, color=color.new(color.gray, 85))