European currency pairs often trade in a narrow range through the Asian hours and move when London opens. This template takes the high and the low from 00:00 to 07:00 on the London clock, and from 07:00 rests a buy stop 2 pips above the high and a sell stop 2 pips below the low, one cancelling the other, so there is at most one trade a day. The stop is the other side's entry level, the target a multiple of the stop distance (1R by default). Orders that have not filled by 12:00 London are cancelled, and an open position is closed at 16:00 New York.
The range and the last entry are on the London clock, the exit on the New York clock. The two cities change to summer time on different Sundays, so for a few weeks a year the gap between them is four hours instead of five. The template turns each time into UTC for every day, so 07:00 London and 16:00 New York stay where they belong through those weeks.
All four times are run parameters, written HHMM (700 is 07:00), so the backtest form and the optimiser set them and they go along into an export for MetaTrader 5, cTrader, TradingView or Rust. Times that are not clock times, or a range that does not end after it starts and before the last entry, place nothing. Optional filters skip a day whose range is smaller or larger than a number of pips.
Parameters
Name
Type
Default
Range or options
Description
bufferPips
float
2
min 0, max 100
Pips beyond the Asian high and low the stop orders rest at.
targetR
float
1
min 0, max 10
The target as a multiple of the stop distance. 0 sets no target; the position is closed at the New York time.
minRangePips
float
0
min 0, max 1000
Skip a day whose Asian range is smaller than this many pips. 0 is off.
maxRangePips
float
0
min 0, max 1000
Skip a day whose Asian range is larger than this many pips. 0 is off.
riskPercent
float
1
min 0, max 10
Per cent of the balance lost if the stop is hit. 0 trades the run's lot size.
allowShort
int
1
min 0, max 1
1 trades breaks in both directions, 0 long only.
rangeStart
int
0
min 0, max 2359
Start of the Asian range, HHMM on the London clock.
rangeEnd
int
700
min 0, max 2359
End of the Asian range, HHMM on the London clock, later the same day. The two orders rest from here.
lastEntry
int
1200
min 0, max 2359
From this time, HHMM on the London clock, orders that have not filled are cancelled. An open position stays.
exitNewYork
int
1600
min 0, max 2359
When an open position is closed, HHMM on the New York clock. The exit is sent on the close of the bar that ends at this time and fills at the next bar's open.
Use it in a strategy
python# The entry rule in your own strategy, on the close of the 06:45 London M15 bar
# (28 bars of 15 minutes from 00:00), with a 2 pip buffer:
bars = ctx.bars(28)
high = max(b.high for b in bars)
low = min(b.low for b in bars)
buffer = 2 * ctx.pip()
dist = (high - low + 2 * buffer) / ctx.pip()
ctx.order("LONG", stop=high + buffer, sl_pips=dist, tp_pips=dist, oco="london", risk_percent=1.0)
ctx.order("SHORT", stop=low - buffer, sl_pips=dist, tp_pips=dist, oco="london", risk_percent=1.0)
To run the whole template, install it, switch it on and pick London breakout under Plugins in the strategy list. Run it on M5, M15 or M30. In a strategy of your own, finding the 06:45 London bar through the clock changes is the part to write yourself; the template writes the UK and US clock rules out as arithmetic, which is what lets it export.
What it provides
london_breakout/londonStrategy
The strategy, with its parameters: entry buffer in pips, target in R, the range size filters in pips, the risk per trade and the short side.
When values are known
The range is known on the close of its last bar (06:45 to 07:00 London on M15), and the two orders rest from the next bar on. Every decision uses that bar and the ones before it.
Limits
Built for currency pairs that are active in London (EURUSD, GBPUSD, EURGBP and the like). Pips are the instrument's own price step, so the buffer and the filters mean something else on an index or a coin.
The range lies within one London day; a range that starts the evening before (for example 22:00 to 07:00) needs a change in the code.
Spreads are wider in the Asian hours and around the London open; on bars with bid and ask the fills pay that, on bars without them the run's spread assumption does.
Bank holidays and thin days are not known to the template. A news release at the London open can fill a stop order well past its price.
False breaks are common: price leaves the range, takes the order and returns. No result is promised.