Docs/Building Algorithms

Building Algorithms

App

What is an algorithm?

On MongoTrader, an algorithm is a rules-based strategy that watches one or more symbols and places orders automatically when its rules fire. You don't have to write code to build one — the Algo Builder offers a menu of ready-made templates that you parameterize and attach to a portfolio.

For users who do want to write code, the external REST API lets you run your own bot anywhere and still see it tracked inside MongoTrader as a named algorithm.

Strategy templates

The Algo Builder ships with a curated library of classic and modern strategies. The catalogue grows over time, but the current starter kit includes:

  • Moving Average Crossover — buys when a short MA crosses above a long MA, sells on the opposite cross.
  • Dollar-Cost Averaging (DCA) — buys a fixed dollar amount on a fixed schedule regardless of price.
  • RSI Mean Reversion — buys oversold conditions (RSI < 30) and sells overbought (RSI > 70).
  • Bollinger Band Breakout — enters when price pierces the upper or lower band, exits on reversion to the mean.
  • Breakout/Pullback — enters on new highs or lows and trails with a stop.
  • Custom rules — combine indicators, price levels, and position sizing rules into your own strategy.

Configure a strategy

  1. Open the Algo Builder. Navigate to Trading → Algo Builder.
  2. Pick a template. Each template page explains what the strategy does, when it historically works, and when it breaks down.
  3. Parameterize. Enter the symbol (or symbols), indicator periods, position size, and any filters like market-hours-only. All parameters have sensible defaults you can tune.
  4. (Optional) Set leverage. If your tier permits it, you can configure the strategy to trade at a leverage above 1x. Every order placed by the algorithm will carry that leverage.
  5. (Optional) Risk limits. Cap the strategy to a max number of open positions, a max dollar exposure, or a cooldown between trades.

Backtest against history

Before committing a strategy to live paper trading, run it against historical data. Each backtest produces:

  • Equity curve — portfolio value over the backtest window.
  • Total return, CAGR, and benchmark comparison.
  • Drawdown statistics — max drawdown and recovery time.
  • Sharpe and Sortino ratios — risk-adjusted return.
  • Win rate, average winner vs. loser, and trade count.
  • Trade log — every simulated entry and exit with P&L.

Don't over-fit

If you tune parameters until the backtest is spectacular, you're probably fitting to noise. Rule of thumb: if the strategy requires very specific indicator periods to work, it's fragile. Robust strategies perform acceptably across a range of parameter values.

Attach to a portfolio

When you're satisfied with the backtest, attach the algorithm to one or more portfolios. Choose an execution mode:

  • Auto Execute — the algorithm places orders directly as its rules trigger. Fastest, but trades happen without your review.
  • Queue Approval — the algorithm generates proposed trades for you to approve or reject. Slower, but you stay in the loop.
  • Signal Only — the algorithm produces signals (buy/sell notifications) but never submits orders. Useful for discretionary traders.

Monitoring and approvals

Every attached algorithm has a status page showing:

  • Current state (running, paused, error)
  • Live P&L since attach
  • Trades placed by this algorithm only
  • Pending approvals (if queue-approval mode)
  • A log of rule firings, including rules that fired but didn't trade (e.g., risk limit blocked)

You can pause or stop an algorithm at any time from this page. Pausing preserves all state; stopping detaches it from the portfolio (open positions stay open and become yours to manage).

External API algorithms

Want to run your own bot on your own server? Generate an API key from your account page and use the REST API. Any trade made through the API can be tagged with an algorithm name, and MongoTrader will group those trades under a named "External API algorithm" that shows up in your Algo Builder alongside internal algorithms.

Tag an external API trade
POST /portfolios/{id}/orders
Headers:
  X-API-Key: mt_your_api_key_here
  X-Algorithm-Name: my-dca-bot
  Content-Type: application/json

{
  "symbol": "AAPL",
  "side": "BUY",
  "type": "MARKET",
  "quantity": 10
}

The full reference — including every order type, margin/leverage fields, error codes, and rate limits — is on the API Documentation page.

Best practices

  • Start in Queue Approval mode. Validate the algorithm is doing what you expect before handing it the keys.
  • Use a dedicated portfolio. Keep the algorithm's book separate from your manual trading so you can measure it cleanly.
  • Set risk limits. Max open positions, max exposure, and a per-trade stop-loss are cheap insurance against bugs in your rules.
  • Be careful with leverage. A rules-based system at 50x can wipe out a portfolio in a single bad print. If you're new to leverage, start at 1x–5x.
  • Re-backtest after tuning. If you change parameters, always verify the new configuration still looks reasonable on historical data.