Algorithms › Metals & Oil Trend
BetaNew · test on demoversion 1.0
Metals & Oil Trend
Follows long trends in gold, silver and crude oil with a 55-day channel breakout and a 20-day exit. Daily bars, long and short.
How it works
Once a day, after the broker's daily close, the algorithm checks each market you picked: gold, silver, WTI and/or Brent crude oil.
- Long when the close is above the highest high of the previous 55 daily bars.
- Short when the close is below the lowest low of the previous 55 daily bars.
It opens shortly after the daily rollover, once the spread is normal. One position per market; it never adds to a position.
Exits
- Initial stop 2 x ATR(20, daily) from the entry (the "2N" stop of the Turtle rules), sent with the order so it sits on the broker's server.
- Exit channel: the lowest low of the last 20 daily bars for a long, the highest high for a short. Every day the stop moves to that level when it is tighter, and it never moves back.
- No profit target: a trend can run for months and the exit only follows it.
Risk limits
- Risk per trade from your risk profile, measured to the initial stop (Standard: 0.5% of equity). The position size adapts to each market's volatility, so a calm and a wild market risk about the same amount.
- At most 3 positions open at once and one per market. With 3 open, three times your risk per trade is at stake.
- Daily loss limit: no new entries for the rest of the UTC day. Open positions keep their stops, unless you switch on closing them too.
How it typically behaves
- Trades rarely and holds for weeks, sometimes months.
- Most trades are small losses; the result depends on a few long trends.
- Long flat or losing stretches are normal. In sideways, choppy markets it gets stopped out again and again. Trend following as a whole had weak years for much of the 2010s and a strong 2022.
- Gold, silver and oil often move together, and WTI and Brent almost always do, so positions can lose together.
Markets
You choose them per account in the account settings: gold (XAUUSD), silver (XAGUSD), WTI (USOUSD) and Brent (UKOUSD). The default is gold, silver and WTI.
Where the rules come from
Donchian channel breakouts, made famous by the Turtle traders of the 1980s; their rules were published by Curtis Faith ("Way of the Turtle", 2007). This is our own implementation of System 2 (55-day entry, 20-day exit) without adding units: the Turtles added up to four, we never add to a position. Long-run research on trend following: Hurst, Ooi and Pedersen, "A Century of Evidence on Trend-Following Investing" (2017).
Costs
Positions stay open for weeks, so overnight financing (swap) adds up. Check your broker's swap long and short for each market in MT5: Market Watch, right-click, Specification. Oil CFDs can also get a price adjustment when the underlying futures contract rolls.
New · test on demo
New in the library and not live-proven. The rules are fixed and public; there is no track record yet, so we show no performance figures. Backtest it in the MT5 Strategy Tester on your broker's data and run it on a demo account first.
Parameters
Defaults the EA receives; risk comes from your risk profile.| Parameter | Default | Range |
|---|---|---|
| MarketsYou choose this per account in the account settings.Chosen per account in the account settings. WTI and Brent move almost together: both roughly doubles the oil exposure.symbols | XAUUSD, XAGUSD, USOUSD | XAUUSD · XAGUSD · USOUSD · UKOUSD |
| Risk per trade (% of equity, to the initial stop)Position size is calculated so a hit of the initial 2 x ATR stop loses about this much.risk_percent | 0.5 | 0.05 – 5 |
| Max loss per day (% of start-of-day equity)No new entries for the rest of the UTC day once reached.max_daily_loss_pct | 2 | 0.5 – 10 |
| Max trades per daymax_trades_per_day | 4 | 1 – 6 |
| Max open positions (all markets)One per market at most. Each one risks your risk per trade.max_open_positions | 3 | 1 – 6 |
| Daily loss limit also closes open positionsOff: positions keep their stops and normal exits.close_on_daily_loss | Off | on / off |
| Skip if the minimum lot risks more than plannedskip_if_min_lot_too_big | On | on / off |
| Entry: close beyond the high/low of (daily bars)55 = Turtle System 2; 20 = System 1 (without its filter).entry_period | 55 | 20 – 100 |
| Directiondirection | both | both · long_only |
| Exit channel: low/high of (daily bars)Longs exit below the lowest low, shorts above the highest high.exit_period | 20 | 10 – 55 |
| ATR period (daily bars, the Turtle N)atr_period | 20 | 10 – 50 |
| Initial stop (x daily ATR)Sent with the order, so it sits on the broker's server.stop_atr_mult | 2 | 1 – 4 |
| Max spread (x daily ATR, 0 = off)Waits while the spread is wider, e.g. right after the daily rollover.max_spread_atr | 0.1 | 0 – 0.5 |
| Wait after the daily rollover (minutes)entry_delay_min | 15 | 0 – 120 |
| Entry window after the daily bar opens (hours)An entry not filled by then is skipped.entry_window_hours | 8 | 1 – 20 |