Strategies

What a Trading Algorithm Is and How It Works

The term trading algorithm usually sounds more complicated than it really is. At its core, an algorithm is just a sequence of logical rules that decides when to buy, when to sell, and how much to risk, without relying on the intuition of the moment. It can be as simple as a moving-average crossover rule or as complex as a statistical model with dozens of variables.

In this article, you'll understand what a trading algorithm is, the main types used by individual traders, and how to assess whether it's worth building or using one.

The difference between algorithm, strategy, and bot

It's common to confuse these three terms, but they aren't synonyms. The strategy is the general idea, for example, buying assets that are in an uptrend and have broken a resistance. The algorithm is that idea turned into precise, testable rules, with exact numbers: which moving average period, which breakout percentage, which stop size. The bot, in turn, is the computer program that executes that algorithm automatically, with no manual intervention.

You can have a strategy and execute it manually, applying the algorithm in your head on every trade, without ever programming a bot. Many experienced traders do exactly that: they use an algorithm's logic, but press the buy and sell button with their own hand.

Common types of trading algorithms

Trend followers

Buy when the price is rising consistently and sell when the uptrend loses strength, usually using moving averages or trend-strength indicators as a reference.

Mean reversion

Start from the premise that the price tends to return to a historical average after an exaggerated move, buying when the asset falls too fast and selling when it rises beyond what the algorithm considers reasonable.

Arbitrage

Look for small price differences of the same asset between different brokers or markets, buying where it's cheaper and selling where it's more expensive almost simultaneously. This type of algorithm usually requires larger capital and very fast execution to be viable.

How to evaluate an algorithm before using it

The first criterion is the clarity of the rules: a good algorithm can be described in a few sentences, with no room for subjective interpretation. The second is the testing history, done with data spanning a period long enough to include both good and bad market moments.

A numerical example helps illustrate the importance of an algorithm's risk-reward ratio. Suppose an algorithm with a 45% win rate, risking R$ 100 per losing trade and gaining, on average, R$ 180 per winning trade. The expected result per trade would be (0.45 x R$ 180) − (0.55 x R$ 100) = R$ 81 − R$ 55 = R$ 26 positive, even being wrong more than half the time. This shows why the win rate alone says nothing about an algorithm's quality: the ratio between average gains and losses matters just as much.

  • Clear rules, with no ambiguity on entry and exit.
  • Testing history over a long period, covering both bull and bear markets.
  • Defined risk-reward ratio, not just the win rate.
  • Trading costs included in the expected-result calculation.

Precautions when adopting ready-made algorithms

There are algorithms sold ready-made, promising consistent results. Before adopting any of them, ask for the full trade history, not just a summary of winning months, and check whether the testing period includes difficult market moments, like sharp drops or high volatility.

Regardless of whether the algorithm is executed manually or by a bot, the platform used to place the orders, like Astron, doesn't affect the quality of the rules behind the strategy. A poorly designed algorithm generates losses on any platform.

How to start building your own algorithm

Write your trading idea into simple numerical rules, test it manually on a historical chart before programming anything, and only consider automating it after confirming, with real data, that the logic makes sense. It's also worth reviewing the algorithm periodically: a set of rules that worked well six months ago can lose effectiveness if market behavior changes, so tracking real results against expectations is part of the work, not an optional step.

Remember that no algorithm, no matter how well built, eliminates the risk of loss — it only organizes how that risk is taken on. Discipline to follow the rules, even through losing streaks that fall within statistical expectations, usually weighs more on the final result than the algorithm's technical sophistication itself.

Practice before you risk. Open your Astron account and test your ideas on the demo account with R$ 10,000 in virtual funds.

Create free account