The anatomy of a trading system
Every automated strategy — Python bot or MQL5 EA — is the same five components wired together. Learn the blueprint once.
It is tempting to think of a trading bot as "the strategy". In reality the strategy (the signal) is one small box in a larger machine. Miss the other boxes and you have a signal, not a system.
The five components
- Data feed — clean, time-aligned prices (and anything else you trade on). Garbage in, garbage out.
- Signal generator — the strategy logic: turns data into "long / short / flat".
- Risk & position sizing — how big? Where is the stop? This is what keeps you alive (Part 7).
- Execution — turning a decision into actual orders, handling partial fills and errors.
- Portfolio / state — what do I currently hold, what is my P&L, what is my exposure? The system reads this back into the signal.
A minimal skeleton in code
Here is the whole machine, stripped to its bones. Every real system in this course grows from this shape:
def run(strategy, broker, risk):
while market_is_open():
data = broker.get_latest_data() class="c"># class="n">1. data
signal = strategy.generate(data) class="c"># class="n">2. signal
if signal and not broker.in_position():
size = risk.position_size(broker.equity, data) class="c"># class="n">3. risk
broker.submit_order(signal, size) class="c"># class="n">4. execution
broker.sync_portfolio() class="c"># class="n">5. state
sleep(strategy.interval)Notice the strategy is four words: strategy.generate(data). Beginners spend 90% of their time there and 10% on the rest. Professionals do the opposite — because the other four boxes are what survive contact with a live market.