ATR stop and target

Forge API 1Updated 1 Oct 2026

Strategy

The stop sits stop_mult times the average true range from the entry. The target is target_r times the distance to the stop, so a target of 2 risks one to make two.

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

FORGE_API = 1


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

    period = param.Int(50, min=10, max=200, step=10, group="Entry")
    stop_mult = param.Float(2.0, min=1.0, max=4.0, step=0.5, group="Risk")
    target_r = param.Float(2.0, min=1.0, max=4.0, step=0.5, group="Risk")

    def compute(self, d) -> fg.Signals:
        average = ta.sma(d.close, self.period)
        return fg.Signals(
            long_entry=ta.crossover(d.close, average),
            long_exit=d.close < average,
            stop=fg.Stop.atr(mult=self.stop_mult, length=14),
            target=fg.Target.r(value=self.target_r),
        )
Open in the editor
Test in Forge ↗

Opens oathra.app.

Was this page helpful?