London Breakout Strategy: TradingView to OANDA
Build a London breakout strategy in Pine Script v6: the pre-London range, session timezones, bracket alerts for OANDA, and a step-by-step testing path.
Marketing
Bottom Line
- Build the range in one session and look for breakouts in a later one, both in a named timezone.
- Allow one entry per day and skip OANDA's daily break from 16:59 to 17:05 New York time.
- Send the stop and target with the entry as one bracket alert.
- Test in order: Strategy Tester, a test signal, Manual Submit, then automatic submission.
A London breakout strategy marks the high and low of a quiet pre-London window, then enters once price closes outside that range during the London morning. To automate it you need explicit session times in a named timezone, a stop, a target, one trade per day, and a cutoff for late entries.
This walkthrough builds that strategy in Pine Script v6, sends its orders from TradingView alerts to your own OANDA account, and tests each piece in order. It is an example for learning the workflow, not a recommendation of a pair or a claim that the rules make money.
How a London Breakout Strategy Works
The Basic Idea
The strategy records the highest high and lowest low during one window, the range session, then watches a later window, the entry session, for a bar that closes beyond either side. A close above the range high is a long entry; a close below the range low is a short entry. Pine Script lets you define these windows as custom sessions on top of the symbol's own trading hours.1
The same idea applied to a stock market open is an opening range breakout. For how the forex day divides into sessions, see forex market hours and sessions.
Every Rule Is an Input
Range hours, entry hours, timezone, stop method, pip buffer and reward multiple are all inputs in the script below. The defaults are placeholders to test, not suggested settings. Forex trading on margin is high risk and not suitable for everyone, because leverage magnifies losses as well as gains and you can lose money quickly.
Define the Pre-London Range
Session Strings
A Pine session string has the form HHmm-HHmm:days. Days run from 1 for Sunday to 7 for Saturday, so 0000-0000:23456 means Monday to Friday, and a string with no days applies every day.1 The time() function returns the bar's opening time when the bar is inside the session and na when it is not, which makes a simple in-session test.1
Pin the Timezone
Without a timezone argument, time() reads the session in the exchange's timezone, which can differ from your chart's.1 Pass a named timezone such as Europe/London so the window follows London's clock through daylight saving changes. input.session() lets you change the start and end times from the Inputs tab, but not the days of the week.1
Skip OANDA's Daily Break
OANDA takes forex instruments offline from 16:59 to 17:05 New York time each day. While the market is closed you cannot open or close positions, although you can still place or modify entry, stop loss, take profit and trailing stop orders.2 The script checks a separate New York session for that window and refuses entries inside it. With the default London hours the break never overlaps, but the check matters if you move the windows.
Entry, Stop and Target Rules
The Entry Trigger
After the range session ends, the script waits for a confirmed bar inside the entry session that closes beyond the range. These conditions must all be true:
- The range for today is complete.
- The bar is inside the entry session and outside the daily break.
- No trade has been taken since the range started.
- The strategy is flat, so an entry never reverses an open position.
The flat check matters because strategy.entry() adds the size of an open opposite position to its order, which reverses the position.3
Two Stop Methods
The opposite-range stop puts a long's stop at the range low and a short's at the range high, so its distance grows and shrinks with the range. The fixed stop sits a set number of pips from the entry price. A wider stop means fewer units for the same risk, and a narrower stop means more. The forex position sizing guide walks through that calculation.
Target as a Multiple
The target is the entry price plus or minus the stop distance times the reward multiple. A long at 1.0850 with a stop at 1.0825 risks 0.0025, so a multiple of 2 puts the target at 1.0900. That is the shape of the order, not an expected outcome.
The Pine Script v6 Strategy
The full script is below. Paste it into the Pine Editor, add it to a standard candlestick chart of the pair, and adjust the inputs.
//@version=6
strategy("London Breakout Example", overlay = true, pyramiding = 0)
string rangeSession = input.session("0000-0700", "Range session")
string entrySession = input.session("0700-1000", "Entry session")
string sessionTz = input.string("Europe/London", "Session timezone",
options = ["Europe/London", "America/New_York", "UTC"])
string stopMethod = input.string("Opposite range", "Stop method",
options = ["Opposite range", "Fixed pips"])
float pipSize = input.float(0.0001, "Pip size", step = 0.00001)
float stopPips = input.float(20.0, "Fixed stop (pips)", minval = 0.1)
float rewardMultiple = input.float(2.0, "Target (multiple of risk)", minval = 0.1)
bool inRange = not na(time(timeframe.period, rangeSession, sessionTz))
bool inEntry = not na(time(timeframe.period, entrySession, sessionTz))
bool inDailyBreak = not na(time(timeframe.period, "1659-1705:23456", "America/New_York"))
var float rangeHigh = na
var float rangeLow = na
var bool rangeReady = false
var bool tradedToday = false
if inRange and not inRange[1]
rangeHigh := high
rangeLow := low
rangeReady := false
tradedToday := false
else if inRange
rangeHigh := math.max(rangeHigh, high)
rangeLow := math.min(rangeLow, low)
if not inRange and inRange[1]
rangeReady := true
bool canEnter = rangeReady and inEntry and not inDailyBreak and not tradedToday
and strategy.position_size == 0 and barstate.isconfirmed
bool longBreak = canEnter and close > rangeHigh
bool shortBreak = canEnter and close < rangeLow
payload(string side, float entryPrice, float stopPrice, float targetPrice) =>
string px = str.tostring(entryPrice, format.mintick)
string tp = str.tostring(targetPrice, format.mintick)
string sl = str.tostring(stopPrice, format.mintick)
'{"ticker":"' + syminfo.ticker + '","action":"' + side + '","orderType":"market","price":' + px + ',"takeProfit":{"limitPrice":' + tp + '},"stopLoss":{"type":"stop","stopPrice":' + sl + '}}'
if longBreak
float stopPrice = stopMethod == "Opposite range" ? rangeLow : close - stopPips * pipSize
float risk = close - stopPrice
if risk > 0
float targetPrice = close + risk * rewardMultiple
strategy.entry("Long", strategy.long, alert_message = payload("buy", close, stopPrice, targetPrice))
strategy.exit("Long exit", from_entry = "Long", stop = stopPrice, limit = targetPrice, disable_alert = true)
tradedToday := true
if shortBreak
float stopPrice = stopMethod == "Opposite range" ? rangeHigh : close + stopPips * pipSize
float risk = stopPrice - close
if risk > 0
float targetPrice = close - risk * rewardMultiple
strategy.entry("Short", strategy.short, alert_message = payload("sell", close, stopPrice, targetPrice))
strategy.exit("Short exit", from_entry = "Short", stop = stopPrice, limit = targetPrice, disable_alert = true)
tradedToday := true
plot(rangeReady ? rangeHigh : na, "Range high", color.green, style = plot.style_linebr)
plot(rangeReady ? rangeLow : na, "Range low", color.red, style = plot.style_linebr)
What Each Part Does
- Sessions:
inRange,inEntryandinDailyBreakare true when the bar opens inside each window. - Range: the first bar of the range session resets the high, low and daily trade flag; later bars widen the range; the first bar after it marks the range ready.
- Entry:
canEntercombines every condition from the rules above, including a confirmed bar. - Orders: each entry builds its stop and target, sends the entry with a bracket payload, and adds a matching
strategy.exit()so the backtest also exits at those prices.
Why the Payload Is Built in Code
The alert_message parameter of strategy.entry() carries a custom message for each simulated order, and it can be a string built at runtime.4 TradingView does not substitute placeholders such as {{ticker}} inside alert_message, so the script writes the symbol with syminfo.ticker and the side as plain buy or sell.4 The exits pass disable_alert = true because the stop and target already travel with the entry. An AI assistant can help you draft or review this kind of string building, but you still create the alert and review every order yourself.
The Alert JSON for OANDA
One Bracket Payload
Create a TradingView alert on the strategy, put {{strategy.order.alert_message}} in the Message field, and set the webhook URL to your own TradersPost strategy's URL.4 A long entry produces a message like this one, shown with "test": true added for the first round of checks:
{
"ticker": "EURUSD",
"action": "buy",
"orderType": "market",
"price": 1.0850,
"takeProfit": { "limitPrice": 1.0900 },
"stopLoss": { "type": "stop", "stopPrice": 1.0825 },
"test": true
}
A take profit and a stop loss attached to the entry make it a bracket order. A forex strategy accepts EURUSD as TradingView sends it, as well as EUR/USD and EUR_USD; other shapes are rejected with invalid-forex-ticker-format. Market orders go to OANDA as fill or kill unless you send "timeInForce": "ioc" to accept a partial fill.
Sizing From the Stop
The payload sends no quantity, so the size comes from your subscription settings. With Risk per position set, TradersPost divides the amount you are willing to lose by the distance from entry to stop, in your OANDA account's currency, and rounds down to whole units. Check the units on each test order rather than assuming they match the Strategy Tester's simulated size.
Backtest and Its Limits
Read the Strategy Report
The strategy report has a Metrics tab with summary figures and a Trades tab listing each simulated trade in order.3 Use the Trades tab to check the code: entry times inside the entry session, one trade per day, and stops and targets where the rules put them. Historical results describe the simulation only and do not predict live trading.
What the Backtest Cannot Show
Heikin Ashi, Renko and similar charts simulate trades on synthetic prices that do not represent real market prices, so test on standard candles.3 By default an order fills at the open of the next bar, not at the signal bar's close.3 Alerts also fire only on realtime bars, and a running alert keeps a copy of the script, inputs, symbol and timeframe from when you created it, so recreate the alert after any change.4
Check Webhook Delivery
TradingView sends the alert message in the body of an HTTP POST, with an application/json content type when the message is valid JSON. Webhook alerts need two-factor authentication on your TradingView account, deliveries can occasionally fail, and the alert log has a Webhook status column for each attempt.5 Never put passwords or credentials in the message. For the full setup, read the TradingView webhook alerts guide.
Test Signal First, Then Manual Submit
Send a Test Signal
Start with "test": true, which checks each signal without sending an order. The OANDA connection guide covers the token and setup, and the OANDA beta announcement lists what the connection supports.
Approve Each Trade by Hand
When you move to a live subscription, turn auto submit off. Each trade then waits for you to approve or reject it before it reaches OANDA. Compare every one with the chart: side, units, stop, target and whether it was the day's first trade.
Turn On Automatic Submission
Once a run of realtime orders matches your rules, you can turn auto submit on to remove the approval step. The script's own checks still decide when a signal is sent: the completed range, the one-trade flag, the entry window, the flat check and the daily break filter.
Conclusion
A London breakout strategy is simple once its timing is explicit: a range session and an entry session in a named timezone, a filter for OANDA's daily break, one stop rule, a target built from it, and one trade per day. Test the code, the payload and the delivery as separate steps, and keep Manual Submit on until the orders you receive match the rules you wrote.
Frequently Asked Questions
What Is a London Breakout Strategy?
It records the range of a pre-London window and enters when price closes beyond that range during the London morning, with a stop, a target, a cutoff and one trade per day. It is a mechanical pattern to test, not evidence that it suits any particular trader.
Which Timezone Should the Sessions Use?
Use a named timezone such as Europe/London so the windows follow daylight saving changes. Without one, time() uses the exchange's timezone, which may not match your chart.1
Why Not Use Ticker Placeholders?
TradingView does not replace placeholders inside a strategy's alert_message, so the script builds the symbol with syminfo.ticker instead.4
What Happens During OANDA's Daily Break?
From 16:59 to 17:05 New York time you cannot open or close positions, though you can still place or modify entry and protective orders.2 The script skips entries in that window.
References
1 TradingView Pine Script User Manual: Sessions
2 OANDA: Hours of Operation
3 TradingView Pine Script User Manual: Strategies
4 TradingView Pine Script User Manual: Alerts
5 TradingView Help: How to Configure Webhook Alerts