algorithmic-trading · Lesson 2

The Anatomy of a Trading Algorithm

The six parts every automated trading system shares — from raw data in to a placed order out, and the feedback loop that ties it together.

6 min readBeginnerSean ShaReviewed by Sean ShaUpdated: July 2026
The Anatomy of a Trading Algorithm — illustration of a cozy kitchen counter showing a modular recipe workflow

Educational purposes only. This content does not constitute investment advice. Read our disclaimer

StockCram is not a broker-dealer, investment adviser, or financial institution. All content is for educational and informational purposes only and should not be construed as personalized investment advice. Consult a qualified financial professional before making investment decisions. Past performance does not guarantee future results.

TL;DR

Almost every trading algorithm — from a hobby script to a hedge-fund system — is built from the same six parts: data comes in, a signal is computed, rules turn the signal into an intended order, risk checks can veto it, the order is executed, and the results feed back to inform the next decision. In the simplified architecture we use throughout this course, any AI or machine-learning model most commonly lives inside one part: the signal engine — though more advanced systems may also apply machine learning to execution, routing, risk, and monitoring. The risk checks are the brake that keeps a bad signal from becoming a disaster.

Different Systems, Same Skeleton

In the last lesson we said an algorithm is a recipe. Now let's open it up. Whether it's a ten-line script on a laptop or a system trading millions of times a day, almost every automated strategy is built from the same six parts, wired in the same order. Learn the skeleton once and you can make sense of any trading system you meet — including the AI-powered ones, because in the simplified architecture we use throughout this course the AI most commonly lives in just one of these six parts.

Here's the whole machine on one page. Follow the arrows left to right, then notice the dashed line looping back underneath:

A six-part trading-system diagram — five processing stages plus a feedback loop — for an AI-assisted trading system. Stage 1, Market Data (prices, volume, fundamentals, news), feeds Stage 2, the Signal Engine, which contains an optional AI/ML model that turns data into a score. That feeds Stage 3, Strategy Rules, where a signal crossing a threshold becomes an intended order. Stage 4, Risk Checks (position limit, max drawdown, kill switch), can veto any order. Stage 5, Execution, sends the order through a broker API to the Market. A dashed feedback loop runs from the Market back through a Monitoring node to Stage 1, carrying fills, prices, and profit-and-loss to inform the next decision.
The six parts of a trading algorithm. The AI/ML model, if there is one, most commonly lives in stage 2 — stage 4, risk checks, is the brake that stops a bad signal becoming a disaster.

That single picture is the map for the whole course. Every later lesson zooms into one of these boxes — backtesting tests the rules, the AI lesson lives inside the signal engine, the execution lesson unpacks stage five. Let's walk each part once, in order.

1. Data — The Raw Inputs

Everything starts with data: prices and volume, company fundamentals, economic figures, even news headlines. A system is only as good as what it's fed — feed it wrong or delayed data and every decision downstream inherits the error. That's why the whole next lesson is about data quality. Garbage in, garbage out is not a slogan here; it's the first way systems fail.

2. Signal Engine — Where AI Lives

The signal engine boils that flood of data down to something simple: a score, or a signal. "This stock looks cheap relative to its average" might become the number +0.8; "this one looks stretched" might become −0.5. In the simplified architecture used throughout this course, this is the box where machine learning most commonly fits: instead of a person writing the formula, an AI model can learn one from examples. (More advanced systems may also apply machine learning to execution, routing, risk, and monitoring — but the signal engine is where it shows up first.) Crucially, the model doesn't place trades — it just produces a number. Everything after it is still plain rules.

The most important sentence in this course

AI in trading is a signal generator, not an autopilot. It can help answer 'is there a pattern here?' — but the rules, the risk limits, and the execution around it are ordinary software a human designed. When a headline says 'AI is trading the market,' this box is what it means.

3. Strategy Rules — Turning a Signal Into an Order

A signal on its own does nothing. The strategy rules translate it into an intended order: "if the signal is above +0.5, buy 10 shares; if it drops below −0.5, sell." This is where a raw score becomes a concrete decision — what to trade, which direction, and how much. We spend the next lesson on exactly this translation, because vague ideas make untestable rules.

4. Risk Checks — The Brake

Before any intended order becomes a real one, it passes through risk checks — and this is the part beginners skip and professionals obsess over. A risk layer asks: Is this position too large? Have we lost more than our daily limit? Has something clearly broken? If the answer is bad, it vetoes the order, no matter how strong the signal was. The drawdown limit and the "kill switch" — a master off-button — both live here. In the diagram, this is the amber box for a reason: it's the brake, and a system without brakes is the classic way automation turns a small mistake into a catastrophe.

5. Execution — Reaching the Market

An approved order still has to reach the market. The execution layer connects to a broker — usually through a broker API, a programmatic doorway we cover later — and sends the order to be filled, handling the same order types a human uses: market, limit, and stop. This stage is where speed, latency, and slippage show up, because the price you wanted and the price you get can differ in the moments an order travels.

6. The Feedback Loop — Closing the Circle

Finally, the dashed line. Once an order fills, the result — the price paid, the new position, the profit or loss — flows back to the start, so the next decision is made with fresh information. A monitoring layer sits on this loop, logging every fill and watching for trouble. Without the loop, a system is flying blind between trades; with it, the machine is always reacting to what just happened. That's the full skeleton: six parts, one circle.

Educational use only

Educational content only. StockCram isn't a broker or adviser, and we have no affiliation with any institution or tool we mention. Nothing here is a recommendation to trade in any particular way.

Key Takeaways

  • Six parts, one circle - Data → signal → rules → risk checks → execution → feedback. Nearly every trading system, big or small, follows this same skeleton in this same order.
  • AI usually lives in one box - In the simplified architecture, machine learning most commonly fits inside the signal engine — it produces a score, not a trade. More advanced systems may also apply ML to execution, routing, risk, and monitoring, but the rules, risk limits, and execution around it are otherwise ordinary human-designed software.
  • Risk checks are the brake - A risk layer can veto any order regardless of how strong the signal is. Skipping it is the classic way automation turns a small error into a disaster.
  • The feedback loop keeps it honest - Results flow back so each new decision uses fresh information, while a monitoring layer logs fills and watches for trouble.

Continue Learning

Frequently Asked Questions

Six: (1) data — the raw inputs like prices and news; (2) a signal engine that turns data into a score; (3) strategy rules that turn the score into an intended order; (4) risk checks that can veto the order; (5) execution that sends it to the market through a broker; and (6) a feedback loop that carries results back to inform the next decision. Nearly every system, from a hobby script to an institutional one, follows this skeleton.

Most commonly in the signal engine — part two. A machine-learning model can learn a formula that turns data into a score, instead of a human writing that formula by hand. But the model just produces a number. In the simplified architecture used throughout this course, the rules that act on it, the risk checks that can veto it, and the execution that places the order are all ordinary software a person designed. More advanced systems may also use machine learning elsewhere — for smart order routing, optimal execution, transaction-cost estimation, risk monitoring, and anomaly detection.

They sit between the intended order and the real one, asking whether the trade is too large, whether losses have hit a limit, or whether something has clearly broken. If so, they veto the order no matter how strong the signal was. The daily drawdown limit and the kill switch — a master off-button — live here. Skipping this layer is a common way automation turns a small mistake into a catastrophe.

Without it, the system makes each decision blind to what just happened. The feedback loop carries the results of every filled order — the price, the new position, the profit or loss — back to the start, so the next decision uses current information. A monitoring layer on this loop logs fills and watches for problems in real time.

Not quite. The signal engine measures — it produces a score like 'this looks cheap: +0.8.' The strategy rules decide — they turn that score into 'buy 10 shares.' Keeping them separate is useful: you can improve how you measure without touching how you act, and test each independently.

Share