← Documentation

Code Builder (Python)

Write custom strategies in Python with full control — same engine, tick-level data.

When forms aren't enough, the Code Builder lets you write a Python strategy class that runs identically in backtest and live.

The shape of a strategy

from algoforge import Strategy, Indicator

class MyStrategy(Strategy):
    def on_start(self):
        self.ema_fast = Indicator.EMA(period=9)
        self.ema_slow = Indicator.EMA(period=21)

    def on_bar(self, bar):
        if self.ema_fast.crossed_above(self.ema_slow):
            self.buy()
        elif self.ema_fast.crossed_below(self.ema_slow):
            self.sell()
  • on_start() — set up indicators and state.
  • on_bar(bar) — called for each candle; bar carries OHLCV and history.
  • Indicator.* — EMA, SMA, RSI, MACD, ATR, Supertrend, and more — auto-updated each bar.
  • self.buy()/self.sell() — place orders (qty, order type, SL/target supported).

Safety

All code passes a security gate (validate_code_safety) before execution — no file, network or system access. Use Code Preview to inspect, Backtest to validate, then Deploy.

Code Builder is available to all users.

Was this page helpful?