Write your first strategy

Forge API 1Updated 13 Oct 20265 min read

What you need

  1. An Oathra account. Creating one is free.
  2. Price history for one symbol, exported from MetaTrader. Oathra ships no sample prices. Bring your price history
  3. A first test on your own price history needs storage, and the free plan includes none. Storage starts at 40 credits a month. Credit packs are coming soon.
  4. Credits for the data check and the test. Both are charged by the minute, and Forge shows the cost of a test before it starts. A standard test uses about 13 credits an hour.
  5. The numbers of a test are on both plans. The verdict is on the paid plan, $29 a month.

Write the strategy

A strategy is one Python file with one fg.Strategy class. Its compute method gets the price arrays as d and returns the signals for every bar at once.

rsi_cross.pypythonOpen in the editor
import forge as fg
from forge import param, ta

FORGE_API = 1


class RsiCross(fg.Strategy):
    bars = fg.bars.Time("H1")
    direction = "long"

    period = param.Int(14, min=2, max=50, group="RSI")
    buy_level = param.Int(30, min=10, max=45, step=5, group="RSI")
    exit_level = param.Int(60, min=50, max=80, step=5, group="RSI")

    def compute(self, d) -> fg.Signals:
        rsi = ta.rsi(d.close, self.period)
        return fg.Signals(
            long_entry=ta.crossover(rsi, self.buy_level),
            long_exit=rsi > self.exit_level,
        )
Open in the editor

The entry fires on the bar where the RSI crosses up through buy_level, not on every bar it stays above. The exit fires when it reaches exit_level.

bars = fg.bars.Time("H1") decides on one-hour bars. compute is pure: it reads d and the settings and nothing else, so it cannot look at the clock, the account or a random number.

Take it to Forge

Download the file. Testing is in Forge on oathra.app, on price history you upload.

Test in Forge ↗

Opens oathra.app in a new tab. You need an Oathra account. A test needs price history, storage and credits, and the verdict is on the paid plan.

You now have

A strategy file, ready to take to Forge.

Ask about this in the forum