Gold Breakout 15M Strategy [WillyAlgoTrader] by WillyAlgoTrader

By WillyAlgoTrader

Performance Metrics

Description

πŸ₯‡ Gold Breakout 15M Strategy is an overlay strategy for gold that builds the overnight price range, places stop orders on both of its boundaries, sizes the position from the distance to the stop, and closes everything at a fixed hour β€” with every order carrying a fully editable alert message, so the same logic can be executed by any trading bot that accepts webhooks or text alerts.The core insight: gold spends the quiet overnight hours inside a range, and the first move out of that range during the active session often sets the direction for the day. The strategy does not try to predict that direction. It waits on both sides, takes whichever side breaks first, risks a fixed share of equity on it, and is flat again by the evening.It is built for gold on the 15-minute chart. The script runs on any symbol and timeframe, but the default hours, stop and exit were chosen for gold.🧩 WHY THESE COMPONENTS WORK TOGETHERA range breakout rule on its own is one line of logic. What makes it tradable β€” and what usually goes wrong when it is automated β€” is everything around it: whose clock defines the range, how large the position is, what happens when both sides are touched, and what exactly the bot receives.This strategy connects those parts into one chain:Broker clock β†’ Daily range β†’ Dual stop entries (one cancels the other) β†’ Stop-loss from entry β†’ Risk-based size with leverage cap β†’ Time exit β†’ Order-level alert templates β†’ On-chart mathThe broker clock decides which candles belong to the range, so the range on the chart matches the range on your broker's chart. The range defines both entry levels. The stop distance defines the position size, so every trade risks the same share of equity whether the stop is wide or tight. The leverage cap and quantity step keep that size inside what an account can actually open. Each order then carries its own message with the real levels and size, so a bot receives the same numbers the tester used. The dashboard recomputes the plan and the statistics from those same values.Without the broker clock, the range is built from the wrong hours. Without risk-based sizing, a narrow range produces an oversized position. Without the one-cancels-other link, a single volatile candle can open both sides. Without order-level messages, the bot and the backtest drift apart.πŸ” WHAT MAKES IT ORIGINAL1️⃣ Broker-time range engine β€” the range follows your broker's server clock.All session hours are defined in broker time, not exchange time. Two modes are available: β€” Fixed timezone (default GMT+3): any timezone string, used all year round. β€” New York + 7h: New York local time plus 7 hours. This is the clock most FX/CFD brokers use β€” GMT+2 in winter, GMT+3 in summer, switching on the US daylight-saving calendar.Range High = highest high and Range Low = lowest low of all bars whose opening hour is at or after Range Start Hour (default 0) and before Range End Hour (default 7). The range resets every broker day. The first day of loaded history is skipped, because its range may be incomplete.Why this matters: a one-hour error in the clock moves the range by four 15-minute candles and changes the entry levels.2️⃣ Dual stop entries with one-cancels-other.From the first bar of the trading window, two stop orders are placed: β€” Buy stop at Range High β€” Sell stop at Range LowBoth belong to one OCA group: the first fill cancels the other immediately. Each entry has its stop-loss attached from the moment it is placed. Only one trade per day is taken, including the case when entry and exit happen inside the same candle. New entries are allowed only while the next bar opens before Close Hour.3️⃣ Two stop-loss modes, with the percent stop re-anchored to the real fill. β€” % of entry (default 1.0%): long stop = entry Γ— (1 βˆ’ SL% / 100), short stop = entry Γ— (1 + SL% / 100). The stop is first placed from the breakout level; at the close of the entry candle it is re-set once from the actual fill price and then stays fixed. β€” Range boundary: the stop is the opposite side of the range.There is no take-profit. A trade ends at the stop-loss or at Close Hour (default 20:00 broker time), whichever comes first.4️⃣ Risk-based position sizing with a leverage cap and step rounding.The size is calculated before the orders are placed:risk budget = equity Γ— Risk% / 100qty by risk = risk budget / (|entry βˆ’ stop| Γ— point value)qty by leverage = equity Γ— Max Leverage / (entry Γ— point value)qty = floor(min(qty by risk, qty by leverage) / step) Γ— stepDefaults: Risk 1.0%, Max Leverage 10, step = the minimum contract size of the symbol. Rounding is always down, so rounding never increases the planned risk. If the result is smaller than one step, that side is skipped and the dashboard says why. When the account currency differs from the symbol currency, equity is converted before the calculation.With the default 1% risk and 1% stop the position is roughly equal to equity (leverage about Γ—1). The cap matters in Range boundary mode, where a narrow range would otherwise produce a very large position.5️⃣ Equity guard β€” optional daily drawdown stop.When enabled, the strategy tracks the equity peak of the current broker day. On every candle it estimates the worst point:worst equity = equity at close βˆ’ adverse move Γ— position size Γ— point valueday drawdown = (day peak before this candle βˆ’ worst equity) / day peak Γ— 100where the adverse move is close βˆ’ low for a long and high βˆ’ close for a short. If the drawdown reaches the limit (default 4.0%), pending orders are cancelled, the position is closed and trading stops until the next day. The guard reacts at candle close; it is an estimate, not a tick-level stop.6️⃣ Alert template engine β€” one strategy, any bot.Every order carries its own alert message, sent at the moment the order is filled. The message is built from a template that you edit in the settings. There are eight templates: Long Entry, Short Entry, Long Exit and Short Exit, each in a JSON version and a plain-text version. One switch selects which set is sent.Templates accept placeholders that the strategy fills with real values: β€” Instrument: {{ticker}}, {{tickerid}}, {{exchange}}, {{interval}} β€” Event: {{event}} (entry / exit), {{side}} (long / short), {{action}} (buy / sell), {{reason}} (breakout / sl / time / equity_guard) β€” Levels: {{price}}, {{entry}}, {{sl}}, {{sl_pct}}, {{range_high}}, {{range_low}} β€” Size and risk: {{qty}}, {{oz}}, {{lots}}, {{risk_usd}}, {{risk_pct}}, {{equity}} β€” Integration: {{trade_id}} (the same in the entry and exit message of one trade), {{secret}} (your bot password)Because the whole message is yours, you can paste the exact JSON your bot expects and put placeholders where the values go. A preview option writes all four messages to Pine Logs with the secret masked, so a template can be checked without waiting for a signal.7️⃣ Position plan and strategy math on the chart.The dashboard shows the plan for the next trade β€” stop price, stop distance, risk amount, size in ounces and lots, notional and leverage β€” for both sides at once. A second block computes statistics from closed trades: β€” Win rate = wins / trades β€” Payoff = average win / average loss β€” Breakeven win rate = 100 / (1 + payoff) β€” Profit factor = gross profit / gross loss β€” Expectancy = (gross profit βˆ’ gross loss) / trades, also in R β€” R of a trade = result / (|entry βˆ’ stop| Γ— size Γ— point value)8️⃣ Performance chart drawn on screen.An optional panel shows the cumulative PnL curve of closed trades with four key stats: total PnL, maximum drawdown, profitable trades and profit factor. The X axis is the trade number, and each column spans the lowest and highest value of the trades it covers, so a drawdown between two columns stays visible. The panel is fixed to a screen corner and does not move when you scroll.βš™οΈ HOW IT WORKS β€” CALCULATION FLOWStep 1 β€” Broker time: The bar time is converted to the broker clock. The broker day and hour are derived from it.Step 2 β€” Range: While the bar hour is inside the range window, Range High and Range Low are updated. A new broker day resets them.Step 3 β€” Position state: The script checks whether a position was opened or closed on this bar, counts the trade for the day and, in % mode, re-sets the stop from the fill price.Step 4 β€” Statistics: Trades closed on this bar are added to the statistics and to the PnL curve. The drawdown estimate is updated.Step 5 β€” Stop and size: The planned stop is calculated for both sides, then the quantity by risk, the leverage cap and the step rounding.Step 6 β€” Guard: If the equity guard is enabled and the daily drawdown limit is reached, everything is cancelled and closed.Step 7 β€” Orders: If the range is complete, the next bar opens inside the trading window, there is no position and no trade was taken today, both stop entries are placed with their stops and alert messages. Otherwise pending entries are cancelled.Step 8 β€” Exit: For an open position the stop is maintained. If the next bar opens at or after Close Hour, the position is closed.Step 9 β€” Drawing: Range box, boundaries, entry and exit labels, trade boxes, dashboard and performance chart are updated.πŸ“– HOW TO USE🎯 Quick start: 1. Open a gold chart on the 15-minute timeframe with regular candles. 2. Add the strategy and open its settings. 3. Set Broker Time Mode and Broker Timezone to your broker's server time. 4. Check Risk per Trade and Max Leverage against your own account rules. 5. Open the Strategy Tester and review the trade list before going any further.πŸ‘οΈ Reading the chart: β€” 🟦 Blue box = the range while it is being built β€” 🟦 Blue lines with Range High / Range Low labels = the entry levels for today β€” 🟒 Green label below a candle = long entry: entry price, stop, size, risk β€” πŸ”΄ Red label above a candle = short entry β€” 🟒 Green / πŸ”΄ red label at the exit = trade result in money and in R, price move, exit price and reason β€” Green / red box = the trade from entry to exit β€” Blue and red lines with a shaded zone = entry price and stop-loss of the open position β€” 🟑 Yellow note on the last bar = a warning about settings or range accuracyπŸ“Š Dashboard fields: β€” Trend: price above, below or inside the range β€” Signal: building range, wait breakout, long, short, done for today, halted β€” Timeframe / Session: chart timeframe, broker clock and trading hours β€” Range / Range width: today's levels and their distance β€” Open P&L: result of the open position in money and in R β€” Day drawdown (est.): the value the equity guard watches β€” Position Plan: stop, stop distance, risk amount, size, lots, notional, leverage and size limits for long and short β€” Strategy Math: trades, win rate, breakeven win rate, profit factor, average win and loss, payoff, expectancy, net profit, maximum drawdown, losing streak, last tradeπŸ”§ Tuning guide: β€” The range does not match your broker's chart: change Broker Time Mode or Broker Timezone β€” Dashboard shows "Below min step": the calculated size is smaller than one contract β€” raise the risk, the capital, or use a smaller contract β€” Dashboard shows "Capped by max leverage": the range is very narrow; the size was reduced and the real risk is below the target β€” Too many stop-outs: widen SL % or switch SL Mode β€” Yellow accuracy note: use a timeframe that divides an hour evenly and regular candlesπŸ€– TRADE IT WITH ANY BOTThe strategy does not depend on a specific bot, exchange or broker. Anything that can receive a TradingView alert can execute it. 1. Create an alert on the strategy. 2. In the alert's Message field leave only {{strategy.order.alert_message}}. 3. Add your bot's webhook address in the alert's notification settings. 4. In the strategy settings turn on Webhook JSON Format and paste your bot's JSON into the four JSON templates, replacing fixed values with placeholders. 5. Turn on Preview Messages in Pine Logs and check the result before the first live signal.Notes for bot builders: β€” Messages are sent when an order is filled, not at bar close. β€” {{price}} is the order level (or the bar close for time and guard exits), not the fill price of your broker. β€” In % mode the stop is re-set from the fill and no separate message is sent for that. A bot that places its own stop should calculate it as {{sl_pct}} from its own fill price. β€” {{trade_id}} is identical in the entry and exit message of a trade and can be used to ignore duplicates. β€” TradingView's own placeholders are not processed inside the templates; add them in the alert's Message field if you need them. β€” Always run a new template on a demo account first.πŸ“ˆ BACKTEST β€” REPRODUCE IT YOURSELFYou do not have to take any numbers on trust. Run the test with the default settings and compare: β€” Symbol: gold spot (XAUUSD) on the OANDA feed β€” Timeframe: 15 minutes β€” Period: January 1, 2011 β€” October 12, 2026 (Deep Backtesting) β€” Initial capital: 10,000 USD β€” Risk per trade: 1% of equity, stop 1% of entry β€” Commission: 0.4 per order, slippage: 0 β€” Broker Timezone: GMT+3, range 00:00–07:00, close at 20:00In the author's run this produced a net result of approximately +800% over the period, on roughly 4,000 trades, with a profit factor of about 1.27 and a maximum drawdown of about 14%.How to read this number: β€” The position size is a share of current equity, so the result is compounded over almost 16 years. β€” The test uses a fixed commission per order and no slippage. Spread is not modeled by the tester. Real trading costs are higher, especially as the position grows, and the real result will be lower. β€” Results depend on the data feed, the broker clock and the tester settings. A different feed or timezone gives different trades. β€” Past performance does not guarantee future results.βš™οΈ KEY SETTINGS REFERENCEβš™οΈ Main Settings: β€” Broker Time Mode (default Fixed timezone): Fixed timezone or New York + 7h β€” Broker Timezone (default GMT+3): used in Fixed mode β€” Range Start Hour (default 0): start of the range β€” Range End / Trading Start Hour (default 7): the range is fixed, entries begin β€” Close All Positions Hour (default 20): forced exitπŸ›‘οΈ Risk Management: β€” SL Mode (default % of entry): % of entry or Range boundary β€” SL, % of Entry Price (default 1.0) β€” Position Size Mode (default % equity at risk): or Fixed quantity β€” Risk per Trade, % of Equity (default 1.0) β€” Fixed Quantity (default 1) β€” Ounces per Lot (default 0 = auto): only for showing size in lots β€” Max Leverage (default 10): cap for position notional β€” Quantity Step (default 0 = auto): rounding step for the size β€” Prop Firm Guard (default off) and Max Drawdown from Daily Equity Peak (default 4.0%) β€” Show Entry / SL Levels (default on)🎨 Visual Settings: β€” Theme (default Auto): Auto, Dark, Light β€” Show Range Box & Boundaries, Show Entry Labels, Show Exit Labels, Show Trade Box (all on) β€” Label Size (default Small) β€” Show Accuracy Warnings, Show Watermark (on)πŸ“Š Dashboard: β€” Show Dashboard, Show Strategy Math (on) β€” Dashboard Position (default Top Right), Dashboard Text Size (default Small)πŸ“ˆ Performance Chart: β€” Show Performance Chart (default off) β€” Chart Position (default Bottom Left) β€” Chart Columns (default 80), Chart Rows (default 30) β€” Chart Width (default 50% of screen), Chart Height (default 35%)πŸ”” Alerts: β€” Enable Alert Messages (default on) β€” Webhook JSON Format (default off = text templates) β€” Bot Secret: replaces {{secret}} β€” JSON templates: Long Entry, Short Entry, Long Exit, Short Exit β€” Text templates: Long Entry, Short Entry, Long Exit, Short Exit β€” Preview Messages in Pine Logs (default off)🎨 Colors: β€” Bull, Bear, RangeπŸ”” Alerts β€” 🟒 LONG ENTRY β€” ticker, timeframe, entry level, stop, size, lots, risk β€” πŸ”΄ SHORT ENTRY β€” the same for the short side β€” βšͺ LONG EXIT β€” ticker, timeframe, exit level, reason (stop-loss, time, equity guard), size β€” βšͺ SHORT EXIT β€” the same for the short sideAll four exist as plain text and as JSON for webhooks, and all four are fully editable. Messages are sent on order fill.⚠️ IMPORTANT NOTES β€” 🚫 No look-ahead. The strategy is calculated on bar close and orders are filled on the following bars. It does not request other timeframes or symbols and does not read future bars. Results can still change with the amount of loaded history, the chart type or the tester's bar magnifier, because the order of prices inside a candle is not known from one candle alone. β€” πŸ“ The range is exact when the timeframe divides an hour evenly (1 to 60 minutes) and the chart uses regular candles. On other charts the strategy still runs and shows a note. β€” πŸ“ If one candle touches both range boundaries, the tester decides which side was reached first. Enable the bar magnifier or test on a lower timeframe to see how many trades depend on this. β€” βš–οΈ Risk per trade is a target. Commission, spread, slippage and gaps add to the actual loss. β€” βš–οΈ The equity guard and the drawdown figures in the dashboard are estimates made at candle close. They are not a guarantee of staying within a prop firm's limit. β€” βš–οΈ The performance chart and dashboard statistics cover the bars loaded on the chart, not the Deep Backtesting range. Use the Strategy Tester for the full period. β€” πŸ› οΈ The script does not place live orders. It simulates orders in the Strategy Tester and sends alert messages; execution through a bot and all trade decisions remain yours. β€” 🌐 Built and tuned for gold on 15 minutes. It can be applied to other symbols and timeframes, but the default hours, stop and exit were not chosen for them. β€” ⚠️ This publication is for educational purposes and is not financial advice. Past performance does not guarantee future results.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView