Draw your first indicator

Forge API 1Updated 25 Oct 20263 min read

Get the file

Copy the file below, or press Download rsi_bands.py, and open it in your own editor. To have an AI tool write it, set up your AI tool first.

rsi_bands.pypython
import forge as fg
from forge import param, ta

FORGE_API = 1


class RsiBands(fg.Indicator):
    name = "RSI bands"
    short_name = "RSIB"
    pane = "new"
    precision = 2
    format = "number"

    period = param.Int(14, min=2, max=200)
    source = param.Source("close")

    rsi = fg.Output.line("RSI")
    hot = fg.Output.state("Overbought")
    levels = [fg.Level(70, "Overbought"), fg.Level(30, "Oversold")]
    warmup = lambda self: self.period

    def calculate(self, bars, start) -> None:
        r = ta.rsi(bars[self.source], self.period)
        self.out.rsi[start:] = r[start:]
        self.out.hot[start:] = r[start:] > 70

FORGE_API = 1 is required. A file without it is refused. A file holds exactly one fg.Indicator class, and pane = "new" draws it in its own pane under the price.

Read what it declares

Settings are class attributes made with param. param.Int(14, min=2, max=200) is a whole number that defaults to 14 and cannot leave 2 to 200. param.Source("close") picks which price the indicator reads.

An output is declared once and filled in calculate. fg.Output.line("RSI") holds one float for each bar, and fg.Output.state("Overbought") holds true or false for each bar. levels draws the two lines at 70 and 30.

Change it

Change the period from 14 to 7 and the levels to 80 and 20, and save the file.

Upload it to Forge

In Forge on oathra.app, open Custom indicators and press Upload a Python indicator. Choose the file, give it a name and press Save and check. Forge checks the file and says what it found.

You now have

A file that draws an RSI with two levels and an overbought state, and a settings form that came with it.

Next: Write your first strategy

Ask about this in the forum