Minimal strategy

Forge API 1Updated 1 Oct 2026

Strategy

A strategy needs a class, its bars and a compute method that returns signals. This one buys while the close is above its average and leaves when it is below.

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

FORGE_API = 1


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

    period = param.Int(50, min=10, max=200, step=10)

    def compute(self, d) -> fg.Signals:
        average = ta.sma(d.close, self.period)
        return fg.Signals(long_entry=d.close > average, long_exit=d.close < average)
Open in the editor
Test in Forge ↗

Opens oathra.app.

Was this page helpful?