OPEN-SOURCE SCRIPT
Session King - ALMA with Session Filter

A session-gated trend strategy that restricts entries to high-liquidity
session windows using ALMA direction bias, with standardised ATR exits
(3 ATR stop, 6 ATR take profit — 2R fixed).
WHAT MAKES THIS ORIGINAL
Most trend strategies fire entries continuously throughout the trading day.
This strategy gates every entry through two independent filters before a
signal is accepted: a directional bias filter (ALMA) and a session timing
filter. Neither filter alone is the edge — the combination is. ALMA without
the session gate fires too many signals in low-liquidity periods. The session
gate without a directional filter trades noise in both directions. Together
they restrict entries to directional moves inside high-liquidity windows
where volume and participation are highest.
COMPONENTS
ALMA (Arnaud Legoux Moving Average, length 9): Direction baseline. Price
above ALMA = long bias; price below = short bias. ALMA applies Gaussian
weighting to reduce lag compared to EMAs of equivalent length, producing
fewer whipsaws at signal transitions.
Session Filter (toggleable): Entries are only permitted during defined
high-liquidity windows. London open (05:45-09:45 GMT), NY AM (12:00-16:00
GMT), and NY PM (19:00-21:00 GMT) can each be toggled independently.
Outside these windows the strategy does nothing. Most false signals in
forex and gold occur during low-volume inter-session periods.
TTM Squeeze (optional, off by default): Based on John Carter's published
TTM Squeeze concept. Compression detection (BB inside KC) is an independent
implementation using Pine built-ins only; Keltner Channel uses ATR via
Wilder's method. No momentum histogram is included — only the compression
gate is used. When Bollinger Bands contract inside the Keltner Channel the
market is in compression and entries are blocked. When BB expands back
outside the KC entries are permitted again. Enables lower-frequency,
post-compression entries when toggled on.
Exits: Fixed 3 ATR stop-loss and 6 ATR take-profit (2R) on every trade.
Position size is calculated so that 1% of equity is risked per trade at
the 3 ATR stop distance.
WHY THIS COMBINATION
ALMA provides direction bias with reduced lag. The session gate ensures
entries only occur when volume and institutional participation are highest.
Fixed ATR exits keep risk consistent across instruments and timeframes and
allow meaningful comparison of strategy performance across different market
conditions.
HOW TO USE
Enable the sessions that match your instrument. London + NY AM is the
default for forex and gold. Enable TTM Squeeze for lower-frequency,
higher-conviction setups. Best suited to 4H and 1H timeframes on XAUUSD,
GBPUSD, EURUSD, and major indices.
DEFAULT PROPERTIES
ATR Length: 14 | Stop: 3x ATR | Take Profit: 6x ATR (2R) | Risk: 1%
Commission: 0.01% per side | Slippage: 1 tick | Initial capital: 10,000
LIMITATIONS
Session filtering significantly reduces trade count. On 4H timeframes
expect 15-40 trades per year. To reach 100+ trades for a statistically
meaningful sample, backtest a minimum of 3-5 years on 1H or 8-10 years
on 4H. Past results do not guarantee future performance.
session windows using ALMA direction bias, with standardised ATR exits
(3 ATR stop, 6 ATR take profit — 2R fixed).
WHAT MAKES THIS ORIGINAL
Most trend strategies fire entries continuously throughout the trading day.
This strategy gates every entry through two independent filters before a
signal is accepted: a directional bias filter (ALMA) and a session timing
filter. Neither filter alone is the edge — the combination is. ALMA without
the session gate fires too many signals in low-liquidity periods. The session
gate without a directional filter trades noise in both directions. Together
they restrict entries to directional moves inside high-liquidity windows
where volume and participation are highest.
COMPONENTS
ALMA (Arnaud Legoux Moving Average, length 9): Direction baseline. Price
above ALMA = long bias; price below = short bias. ALMA applies Gaussian
weighting to reduce lag compared to EMAs of equivalent length, producing
fewer whipsaws at signal transitions.
Session Filter (toggleable): Entries are only permitted during defined
high-liquidity windows. London open (05:45-09:45 GMT), NY AM (12:00-16:00
GMT), and NY PM (19:00-21:00 GMT) can each be toggled independently.
Outside these windows the strategy does nothing. Most false signals in
forex and gold occur during low-volume inter-session periods.
TTM Squeeze (optional, off by default): Based on John Carter's published
TTM Squeeze concept. Compression detection (BB inside KC) is an independent
implementation using Pine built-ins only; Keltner Channel uses ATR via
Wilder's method. No momentum histogram is included — only the compression
gate is used. When Bollinger Bands contract inside the Keltner Channel the
market is in compression and entries are blocked. When BB expands back
outside the KC entries are permitted again. Enables lower-frequency,
post-compression entries when toggled on.
Exits: Fixed 3 ATR stop-loss and 6 ATR take-profit (2R) on every trade.
Position size is calculated so that 1% of equity is risked per trade at
the 3 ATR stop distance.
WHY THIS COMBINATION
ALMA provides direction bias with reduced lag. The session gate ensures
entries only occur when volume and institutional participation are highest.
Fixed ATR exits keep risk consistent across instruments and timeframes and
allow meaningful comparison of strategy performance across different market
conditions.
HOW TO USE
Enable the sessions that match your instrument. London + NY AM is the
default for forex and gold. Enable TTM Squeeze for lower-frequency,
higher-conviction setups. Best suited to 4H and 1H timeframes on XAUUSD,
GBPUSD, EURUSD, and major indices.
DEFAULT PROPERTIES
ATR Length: 14 | Stop: 3x ATR | Take Profit: 6x ATR (2R) | Risk: 1%
Commission: 0.01% per side | Slippage: 1 tick | Initial capital: 10,000
LIMITATIONS
Session filtering significantly reduces trade count. On 4H timeframes
expect 15-40 trades per year. To reach 100+ trades for a statistically
meaningful sample, backtest a minimum of 3-5 years on 1H or 8-10 years
on 4H. Past results do not guarantee future performance.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
We test strategies so you don't have to. Research: @backtestbay · Tools: backtestbay.gumroad.com
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
We test strategies so you don't have to. Research: @backtestbay · Tools: backtestbay.gumroad.com
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.