//@version=5 strategy("BTST and STBT Gap Momentum Strategy", overlay=true, initial_capital=100000, default_qty_type=strategy.fixed, default_qty_value=1) // --- Input Parameters --- trend_ema_len = input.int(20, title="Trend Filter EMA Length") entry_hour = input.int(15, title="Entry Hour (24h format)", minval=0, maxval=23) entry_minute = input.int(15, title="Entry Minute", minval=0, maxval=59) exit_hour = input.int(9, title="Exit Hour (24h format)", minval=0, maxval=23) exit_minute = input.int(15, title="Exit Minute", minval=0, maxval=59) // --- Indicator Setup --- ema_val = ta.ema(close, trend_ema_len) plot(ema_val, color=color.blue, title="Trend Filter EMA", linewidth=2) // --- Session Verification --- is_entry_time = (hour == entry_hour and minute == entry_minute) is_exit_time = (hour == exit_hour and minute == exit_minute) // --- Strategy Entry Conditions --- // BTST (Buy Today, Sell Tomorrow) - Long setup if price is above EMA at entry time btst_long_cond = is_entry_time and (close > ema_val) // STBT (Sell Today, Buy Tomorrow) - Short setup if price is below EMA at entry time stbt_short_cond = is_entry_time and (close < ema_val) // --- Execution --- if (btst_long_cond) strategy.entry("BTST_Long", strategy.long, comment="BTST Entry") if (stbt_short_cond) strategy.entry("STBT_Short", strategy.short, comment="STBT Entry") // Clear positions on market open (Gap realization target) if (is_exit_time) strategy.close("BTST_Long", comment="BTST Open Exit") strategy.close("STBT_Short", comment="STBT Open Exit")