TradingSignalBot Get early access

Blog · Strategy

How to automate a trading strategy

What writing 12 well-known strategies as code for our signal bot taught us: the questions every rule has to answer before a program can run it.

The opening range breakout template's most recent signal on XAUUSD: the opening range, the break, the entry, the stop and three targets
The opening range breakout template's own signal on real 5 min gold candles, 23 October 2026, drawn by the bot's renderer.

In brief

  • Every word a trader understands without thinking, such as "the open" or "a break", has to become a number.
  • A signal exists at the close of the candle that triggered it, never earlier, or the code is reading the future.
  • The stop, the targets and how many times a setup may fire are part of the rule, not afterthoughts.
  • Test the code on candles made by hand, then run it on real ones and look at every chart.
  • Automation makes a strategy consistent. It does not make it work.

We have written 12 well-known trading strategies as code for our signal bot: the strategy templates. Each was easy to describe and hard to write down. This is what the writing taught us, with the rules each template settled on.

Turn every word into a number

Take the opening range breakout as it is usually taught: trade the break of the range a market sets after its open. A trader reads that and knows what to do. A program has to be told which open, how long the range lasts, what a break is, and what happens on a day with two. The template settled on these:

  • The range is the high and low of the 15 minutes from 09:30 New York, built from 3 5-minute candles.
  • Buy on the first 5-minute close above the range's high; sell on the first close below its low. The first break of the day only.
  • No signal after 12:00 New York, and none on a day the range is incomplete.
  • Stop at the other side of the range. Targets at 1, 2, 3 times the stop distance.

Each number is a setting a buyer can change: the range can start at another open, last longer, or put the stop in its middle. What cannot be left out is the decision. A rule with a gap in it does nothing, or does something nobody chose.

Decide when a signal is known

On a finished chart the eye sees the turn at the low. Code running live sees it later, and the difference is the whole game. A signal exists at the close of the candle that triggered it, and the entry is that close. The rsi divergence template shows what that costs:

  • Swing points are candles whose low (high) is beaten by none of the 3 before and 3 after; a swing is used only once those 3 candles have closed.

A swing low is only a swing low once the 3 candles after it are higher, so the signal comes on the close of the last of them, never at the low itself. That delay is the price of a signal that stays where it was drawn. Indicators that redraw their past signals look perfect on old charts for this reason: they use candles that had not happened yet. Where a template reads swings, its tests check that no signal depends on a candle that came after it.

Say what counts as the event

A touch, a wick or a close? Most versions of most strategies mean a close and never say so. Our templates wait for a candle to close beyond a level: a wick through the opening range and straight back is common at the open, and it is not a break. The break and retest goes further, because a close that only just clears a level is not much of a break either:

  • The break is a 15-minute close beyond the level by at least 0.75 × ATR(14), so a close that only just clears it is not a break.
  • The retest is a candle within 12 candles after the break that comes back to the level (a buy: its low at or under the level plus 0.1 × ATR(14)) and closes on the broken side. The bot signals at that close. A close back through the level first voids the setup.

"Back to the level" needed a number too. Without the buffer, a retest that stops a hair short of the level would not count, though every trader watching would call it one.

Price the stop before it goes out

A signal without a stop cannot be sized, so every template works its stop out by rule at the moment it fires. Three of them:

  • Opening range breakout: Stop at the other side of the range. Targets at 1, 2, 3 times the stop distance.
  • EMA crossover: Stop beyond the lowest low (sell: highest high) of the last 10 candles; if that is closer than 0.5 × ATR(14), 0.5 × ATR(14) is used.
  • RSI divergence: Stop 0.1 × ATR(14) beyond the second swing, and at least 0.5 × ATR(14) from the entry. Targets at 1, 2, 3 times the stop distance. Each pair of swings once.

A stop measured off the last few candles can come out absurdly tight in a quiet market, which is why two of those have a floor measured in the market's own average range (ATR). And if a stop ever comes out on the wrong side of the entry, there is no signal: the bot does not send a trade it cannot price.

Say how many times

Price that crosses a line, falls back and crosses again would fire three signals under a rule that says only "buy the cross". Each template says how often: the first break of the day only, one signal a cross, each level once, each pair of swings once.

Even with that settled, the same market gives very different counts. From 23 October 2025 to 23 October 2026 on gold, the ema crossover template found about 47 signals a month, the opening range breakout about 21 and the RSI divergence template about 13. A free channel that posts six a month cannot carry every one of the ema crossover's signals, and a paid one may not want them all either. How often a strategy fires is part of choosing it.

Fix the clock

"The New York open" is 09:30 in New York, which is 13:30 or 14:30 UTC depending on the time of year. Stored in UTC, it is an hour out for months at a time. Stored in London time, it is an hour out for the weeks between the two countries' clock changes, which fall on different weekends. Our templates read every session on its own city's clock, New York's or London's, so the open stays the open.

Decide what missing data does

Price feeds miss candles. A range built from two candles when it should have three is a different range, and a signal from it is a guess. The opening range breakout says so in its rules: no signal on a day the range is incomplete. The london breakout skips a day whose overnight range is missing a candle too. Doing nothing is a rule; it has to be written like the others.

Test it on candles you made

Before a template sees a real price, it runs on candles we wrote by hand: a day built to fire, and days built to look nearly right and not fire. A wick through the range. A break after the last entry time. A retest that comes too late, or a close back through the level before it. A swing used before it is confirmed. A flat market. Each template has its own file of these tests.

Run it on real candles and look

Tests prove the code does what the rules say. They cannot prove the rules say what you meant. For that, run it over real candles and look at the signals one by one, on a chart. Our build runs every template over a year of real candles, draws its most recent signal with the same renderer the live bot uses, and puts it on the template's page. The chart at the top of this post is the opening range breakout's, on gold, 23 October 2026. This is the break and retest's, 19 October 2026, and the message the bot would post with it:

The break and retest template's most recent signal on XAUUSD: the swing level, the break, the retest, the entry, the stop and three targets
The template's own signal on real 15 min candles, drawn by the bot's renderer.

🔴 SELL XAUUSD · Break and retest Entry: 4165.33 (market) Stop: 4173.18 (8 pips) TP1: 4157.47 (+8 pips) TP2: 4149.62 (+16 pips) TP3: 4141.77 (+24 pips) Swing low broken, retested and held. Stop beyond the retest; targets at 1, 2, 3 times the stop. Not financial advice. Trade at your own risk.

When a chart looks wrong, the rule usually is, and a test written from the same misunderstanding passes anyway. That is why every template's page shows its chart beside its rules: the two have to agree.

What a test can and cannot say

We publish no results for these templates, and that is a decision. A template is automation: it runs a strategy exactly as written, every day, without missing the open. Whether that strategy makes money on your market is a separate question. The honest answer comes from a test on that market's past candles with every loss in it, then from running it forward, the one test the future cannot be fitted to. When we build a strategy for a channel, that test comes with it, privately, losses included.

Bring your own strategy

If your channel runs on rules of your own, we write them as code the same way, test them on past candles and run them in the bot, with your logo on the charts and each signal followed to its end. It is early access: what the bot does for channel owners, or every template with its rules.

Questions

Can any trading strategy be automated?

Any part of it that can be written as a rule. A step that is a judgement ("the trend looks strong") has to become a measurement, such as a moving average or a slope, or stay with the trader. Working out which is which is most of the job.

Do I need to code to automate my strategy?

Not with us: you describe the rules and we write and test the code. To do it yourself you need a language and a source of candles, and the questions in this post are the same either way.

Will automating my strategy make it work better?

It makes it consistent: it never misses the open or bends a rule after a loss. It does not change what the rules do on the market. Only a test on past candles and a run forward show that, losses included.