The "Slow Asia" Risk Filter (Pine Script v5)
You can apply this to your chart to act as both a visual cue (gray background for observe-only, blue for London) and a mechanical backtesting template.
Code: Select all
//@version=5
strategy("Asia Playbook & Risk Filter", overlay=true, initial_capital=10000, margin_long=100, margin_short=100)
// =========================================================================
// 1. INPUTS & SESSION TIMES
// =========================================================================
grp_sessions = "Session Times (Exchange Time)"
asiaSession = input.session("1800-0300", title="Asia Session (Observe/Rest)", group=grp_sessions)
londonSession = input.session("0300-1200", title="London/NY Session (Action)", group=grp_sessions)
// =========================================================================
// 2. PLAYBOOK RULES
// =========================================================================
grp_rules = "Asia Strict Rules"
maxAsiaTickets = input.int(1, title="Max Asia Tickets", group=grp_rules, tooltip="Hard cap on trades during Asia. Often zero.")
asiaTimeStop = input.int(5, title="Asia Time Stop (Bars)", group=grp_rules, tooltip="If trade doesn't move, thin books punish hope. Cut after X bars.")
reqSpreadPass = input.bool(true, title="Require Strict Spread Filter", group=grp_rules)
maxSpread = input.float(1.5, title="Max Spread Allowed (Pips)", group=grp_rules)
// =========================================================================
// 3. VISUAL CUES & SESSION STATE
// =========================================================================
inAsia = not na(time(timeframe.period, asiaSession))
inLondon = not na(time(timeframe.period, londonSession))
// Friction visual: Gray for Asia (research/rest), Blue for London action.
bgcolor(inAsia ? color.new(color.gray, 92) : na, title="Asia Zone")
bgcolor(inLondon ? color.new(color.blue, 95) : na, title="London Zone")
// =========================================================================
// 4. TICKETING & SPREAD TRACKING
// =========================================================================
var int currentAsiaTickets = 0
// Reset ticket cap at the start of every new Asia session
if ta.change(time(timeframe.period, asiaSession))
currentAsiaTickets := 0
// Spread logic (Using a volatility proxy for historical data, or true spread for live)
// To use actual spread in live markets: spread = (ask - bid) / syminfo.mintick
currentSpreadProxy = (high - low) / syminfo.mintick
spreadPasses = reqSpreadPass ? (currentSpreadProxy > maxSpread) : true
// =========================================================================
// 5. A+ SETUP LOGIC (USER DEFINED)
// =========================================================================
// Replace this block with your actual A+ trigger conditions
aPlusLong = ta.crossover(ta.sma(close, 9), ta.sma(close, 21))
aPlusShort = ta.crossunder(ta.sma(close, 9), ta.sma(close, 21))
// =========================================================================
// 6. POSITION SIZING & ENTRY
// =========================================================================
// Rule: Size is half in Asia. (e.g., 1 contract in Asia, 2 in London)
tradeSize = inAsia ? 1 : 2
// Rule: No new risk unless A+ level and spread filter pass. Max tickets hard-capped.
canTradeAsia = inAsia and (currentAsiaTickets < maxAsiaTickets) and spreadPasses
canTradeLondon = inLondon
if aPlusLong
if canTradeAsia
strategy.entry("Asia_Long", strategy.long, qty=tradeSize)
currentAsiaTickets += 1
else if canTradeLondon
strategy.entry("London_Long", strategy.long, qty=tradeSize)
if aPlusShort
if canTradeAsia
strategy.entry("Asia_Short", strategy.short, qty=tradeSize)
currentAsiaTickets += 1
else if canTradeLondon
strategy.entry("London_Short", strategy.short, qty=tradeSize)
// =========================================================================
// 7. ASIA TIME STOP (THIN BOOKS PUNISH HOPE)
// =========================================================================
inTrade = strategy.position_size != 0
barsInTrade = ta.barssince(strategy.position_size[1] == 0 and inTrade)
// If in an Asia trade and it stalls, cut it.
if inAsia and inTrade and barsInTrade >= asiaTimeStop
strategy.close_all(comment="Asia Time Stop - Thin Books")
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.