Home / Expert Advisors / Trend

Trend

Draws its own trend lines through swing highs and lows, takes the bias from a long average on a higher timeframe, and enters when price touches a valid line in the direction of the bias. Test it on a demo account first.

DRF_Trend_EA · version 1.00 · Trend following

Risk. Trading carries a high level of risk and you can lose more than you expected. No result is promised. Read the Risk Disclosure.

Test it on a demo account first. When everything works as you expect, use it on a real account.

Used by the author on XAUUSD (gold). It works on any symbol.

The problem it addresses

Trend lines are drawn by eye, differently by every trader, and a line that looks valid today may not be tomorrow. A written rule for what counts as a valid line makes the method repeatable.

What it does

Finds swing highs and lows on the timeframe you choose (1 hour by default, looking back 48 hours) and draws trend lines through them. A line counts only after price has touched it a number of times (3 by default). It also finds up to three support and three resistance levels.

The bias comes from a 200-period average on a higher timeframe (4 hours by default). A trade is taken when price touches a valid line in the direction of the bias.

The stop and the target sit at the nearest support or resistance level plus a small buffer when one exists, otherwise at ATR multiples (1.5 and 3.0). A break-even moves the stop once the trade is in profit (on by default).

You can switch any weekday off. It opens and closes its own trades, one position at a time, with the magic number 26110005.

Who it is for: Traders who like entries at a trend line, in the direction of the larger trend, and who will test it on a demo account first.

Symbols and timeframes: Written to run on any symbol that allows trading; stops and lots adapt through the ATR. It needs the history of the line timeframe and the symbol's own tick data to be accurate on the touch.

Real accounts: on a demo account it trades at once; on any other account it sends no order until you tick the input "I confirm this is a real account I want to trade". Test the EA on a demo account first. When everything works as you expect, use it on a real account.

The idea behind it

Trade the touch of a trend line that has held several times, in the direction of the larger trend.

History

Version 1.00 is the first public version, built from the specification of the earlier Gold Trend tool on the shared DRF strategy base. It is NOT behaviour-identical to that earlier tool: the line detection is a port, and the entry is reduced to the touch. Mechanics were checked on a demo account and in the Strategy Tester. This page makes no claim about results.

Indicators used

What is included

What is not included

How it works

  1. On every new bar of the line timeframe, while no position is open, it rebuilds the swing points, the trend lines and the support and resistance levels.
  2. The bias is read on every new bar of the higher timeframe from the 200-period average.
  3. When price touches a valid line in the direction of the bias and the filters allow it, it works out the lot from your risk percent and the stop distance, and sends the order.
  4. The stop and the target go to the nearest level plus the buffer, or to the ATR distances when no level exists. The break-even moves the stop once the profit reaches your distance.

What you need

How to install and test it

  1. Download the ZIP below and unzip it. It holds the Expert Advisor file (.ex5), a settings preset (.set) with an empty DRF Key, and INSTALL.txt with these steps.
  2. In MetaTrader 5 choose File > Open Data Folder, open MQL5 > Experts, and copy the .ex5 file there. Back in MetaTrader, right-click Expert Advisors in the Navigator and choose Refresh.
  3. Tools > Options > Expert Advisors: tick "Allow algorithmic trading" and "Allow WebRequest for listed URL", then add https://sync.donaldsonrf.com to the list. Nothing else is needed. Press OK.
  4. Press the Algo Trading button in the top toolbar so it turns green.
  5. Drag the Expert Advisor from the Navigator onto a chart. On the Common tab tick "Allow Algo Trading". On the Inputs tab type your DRF Key in the first input (optionally load the .set preset first).
  6. Within about a minute the chart panel shows the state of your licence. If it says PAUSED, the panel tells you why. Test the EA on a demo account first. When everything works as you expect, use it on a real account.
  7. The first time, attach it to a chart of a DEMO account. Orders are sent without any extra tick on a demo account.
  8. Watch the panel on the chart. It shows the licence state, the account type, how many positions this EA has open and why it is not trading, if it is not.
  9. When everything works as you expect on the demo account, you can use it on a real account: on the Inputs tab, tick "I confirm this is a real account I want to trade". Without the tick the EA sends no order on a real account.

The key: every DRF Expert Advisor needs a DRF Key, with a 7-day free trial. Every plan, and the trial, unlocks the whole Expert Advisor.

Safety behaviour

What can go wrong

The panel says PAUSED: no DRF Key entered.
Type your DRF Key in the first input (Inputs tab). The key looks like DRF-XXXXX-XXXXX-XXXXX.
The panel says the key could not be checked.
Check that https://sync.donaldsonrf.com is in Tools > Options > Expert Advisors > "Allow WebRequest for listed URL", that the terminal is online and that the key has not expired. Error 4014 in the Experts log means the address is missing from the list.
The panel says "REAL account: orders are blocked".
This is the safety lock. On any account that is not a demo, tick "I confirm this is a real account I want to trade" on the Inputs tab, after you have tested the EA on a demo account.
The EA does not trade and I do not know why.
Read the status line on the panel. The usual reasons are: outside the trading hours, important news close by, a wide spread, a position already open, the daily loss stop reached, or no setup yet. The rules only act on closed candles, so a setup can take hours or days to appear.
The panel says the chart is refused.
The reason is written on the panel and in the Experts log. Common causes: trading is disabled for the symbol, the symbol has too little history for the indicators (open the chart, scroll back or press Home to load history), a period input is nonsense, or two timeframes do not make sense together.
The panel says the magic number is outside the registered block.
Set "Magic number" back to its default or to a number between 26110001 and 26119999.
It says the smallest lot would risk too much.
The account is too small for the stop distance on this symbol, or the risk percent is too low for the smallest lot. Lower the stop distance, choose another symbol, or raise the risk percent only if you accept that risk.
I do not see any panel or object on the chart.
Press the Algo Trading button so it turns green, tick "Allow Algo Trading" on the Common tab, and look for the smiling face in the top right corner of the chart. Check the Experts tab of the Toolbox for messages.
The Strategy Tester behaves differently from a live chart.
The tester has no economic calendar, so the news filter is not applied there; the EA writes one line in the log to say so. Use the Tester build only in the tester, and do not read a tester run as a promise of any result.

Manual: every setting in plain language

Allow https://sync.donaldsonrf.com in MetaTrader's WebRequest list and enter your DRF Key in the first input.

DRF Key

DRF Key (default: empty)
Your DRF Key (it looks like DRF-XXXXX-XXXXX-XXXXX). Leave it empty and the EA stays paused and says so on the chart. A paused or lapsed key stops NEW orders only.

Strategy

Timeframe of the trend lines (default: 1 hour)
The candle size on which the swing points and trend lines are drawn.
Price used for the lines (default: Wicks (highs and lows))
Draw the lines through the wicks (highs and lows) or through the closing prices.
Look back this many hours for the swing points (default: 48)
How far back the EA searches for the swing highs and lows that form the lines. The lines are rebuilt when a new bar forms and no position is open.
Touches needed before a line (or a level) counts (default: 3)
A line or support/resistance level is used only after price has touched it this many times.
Only trade with the higher-timeframe trend (default: on)
When on, a trade must agree with the direction of the trend on the higher timeframe below.
Higher timeframe (default: 4 hours)
The larger candle size on which the bias is read.
Higher-timeframe average period (default: 200)
The period of the exponential average on the higher timeframe. The last closed candle of the higher timeframe is compared with it.
Smallest distance between two levels (ATR multiples) (default: 0.5)
Two support or resistance levels closer than this are treated as one.
Trade on Monday (default: on)
Allow new trades on Mondays.
Trade on Tuesday (default: on)
Allow new trades on Tuesdays.
Trade on Wednesday (default: on)
Allow new trades on Wednesdays.
Trade on Thursday (default: on)
Allow new trades on Thursdays.
Trade on Friday (default: on)
Allow new trades on Fridays.

Risk

Risk per trade (percent of the balance) (default: 1.0)
How much of the account balance one trade may lose if its stop is hit. The lot size is worked out from this and from the stop distance. If even the smallest lot would risk more than 1.5 times this wish, the EA does not trade and says so on the chart.
Put the stop and the target at the nearest support and resistance level (default: on)
When on, the stop and the target sit at the nearest level (plus the buffer below). If no usable level exists, the ATR distances below are used.
Stop distance when no level is available (ATR multiples) (default: 1.5)
The stop distance used when there is no usable level.
Target distance when no level is available (ATR multiples) (default: 3.0)
The target distance used when there is no usable level.
Extra distance beyond the level (ATR multiples) (default: 0.1)
A small buffer placed beyond the level so the stop is not sitting exactly on it.
ATR period (on the line timeframe) (default: 14)
The number of candles of the ATR, measured on the timeframe of the lines.
Break-even (default: on)
When on, the stop is moved to the entry price once the trade is in profit by the amount below.
Break-even: move the stop when the profit reaches (ATR multiples) (default: 1.0)
The profit, in ATR multiples, at which the stop is moved. On by default in this EA.
Break-even: the stop goes to the entry plus this much (ATR multiples) (default: 0.1)
Where the stop goes at break-even: the entry price plus this small distance.

Filters

Wait while the spread is wider than this many times its usual size (0 = off) (default: 4.0)
New trades wait while the spread is unusually wide. "Usual" is the symbol's own typical spread, so there is no fixed number to adjust per symbol. 0 switches the check off.
Pause new trades around high-importance news for the symbol's currencies (default: on)
No new trade shortly before and after important news for the currencies of the symbol (it uses the MetaTrader economic calendar). The Strategy Tester has no calendar, so in the tester this filter is not applied and the EA says so.
News: stay out this many minutes before (default: 20)
Minutes before an important news event during which no new trade is opened.
News: stay out this many minutes after (default: 20)
Minutes after an important news event during which no new trade is opened.
Open new trades only inside the hours below (server time) (default: on)
When on, new trades open only between the two hours below. Trades already open are not closed by this.
Trading hours start at (hour, 0 to 23, server time) (default: 8)
First hour of the trading window, in your broker's server time (not your local time).
Trading hours end at (hour, 0 to 23, server time) (default: 20)
The hour at which the trading window ends, in your broker's server time.
Stop opening new trades after a daily loss of this many percent (0 = off) (default: 0.0)
If the losses of today reach this percentage of the balance, no new trade is opened until the next server day. 0 switches it off (the default).
Most positions open at the same time (this EA, this symbol) (default: 1)
How many positions this EA may keep open on this symbol at once. The default is 1.

Account

I confirm this is a real account I want to trade (default: off)
Safety lock. On a demo account the EA trades without it. On any other account the EA does NOT send orders until you tick this box; the chart says "REAL account: orders are blocked". Tick it only after you have tested on a demo account and everything works as you expect.
Magic number (unique for each EA; change it only to run two copies on one symbol) (default: 26110005)
The number written on every order of this EA; the EA recognises its own positions by it. Keep the default unless you run two copies on one symbol. It must stay inside the block 26110001 to 26119999, otherwise the EA refuses to trade and says so on the chart.

Download

DRF_Trend_EA_v1-00.zip (93 KB) ↓

The file runs only with a valid DRF Key.

Brokers and hosting I use

I recommend only what I use. I have been a client of IC Markets, IC Trading, FTMO and IONOS for many years.

These are affiliate links. If you open an account or buy through them I may be paid a commission, at no extra cost to you. Read the Affiliate Disclosure and the full page. Trading carries a high level of risk; check that a company is authorised in your country before you use it.

Frequently Asked Questions

Why do the lines change?
The lines are rebuilt when a new bar forms and no position is open. A line that is valid today may disappear tomorrow. That is how the rule works.
What if there is no support or resistance level near?
Then the stop and the target use the ATR distances you set (1.5 and 3.0 by default).
Is it the same as the earlier Gold Trend EA?
No. The detection is a port of the same idea but the entry is reduced to the touch, and the money rules are ATR distances and a risk-based lot.
Does it trade on a real account straight away?
No. On a real account it sends no order until you tick the confirmation input.
Will it make a profit?
No result is promised. Read the Risk Disclosure.
Do I need a key to run it?
Yes. Every DRF Expert Advisor needs a DRF Key, with a 7-day free trial. See the DRF Key page.
Does it promise a result?
No. Read the Risk Disclosure. Test on a demo account first; when everything works as you expect, use it on a real account.
Running into a technical issue or something that doesn't work right on this page? Please let us know straight away via our Contact page — that's how we find out what's broken and get it fixed.