Convert a Pine Script strategy to Python: Pine to Forge

Forge API 1Updated 14 Oct 2026

What you write in Pine, and what you write in Forge instead. 37 names, grouped by what they are for.

What has no Forge form

You writeWhy
strategy(calc_on_every_tick=)Forge decides on closed bars only.
strategy(process_orders_on_close=)An order acts at the first real price after the bar's close, never at that close.
strategy(fill_orders_on_standard_ohlc=)Forge always fills at real prices.
strategy(use_bar_magnifier=)How finely a run checks fills between bars is set for the run, not in the strategy.
strategy(backtest_fill_limits_assumption=)A strategy cannot change how the fill engine treats limit orders.
strategy(risk_free_rate=)A strategy does not set a risk-free rate for the statistics.
request.security(lookahead=barmerge.lookahead_on)Forge never shows a higher timeframe's bar before it closes.
varipForge has no updates inside a bar, so there is nothing to keep between them.
barstate.isconfirmed, barstate.isnew, barstate.isrealtimeEvery bar a strategy sees is closed, so these checks are not needed.
alertcondition(), alert()A strategy does not send alerts. Put the alert in an indicator with fg.alert.

Name by name

The program's events

You writeIn Forge
//@version=6FORGE_API = 1 on the first linesfg.FORGE_API_LATEST
strategy("Name")class Name(fg.Strategy) with meta = fg.Meta(title="Name")fg.Strategyfg.Meta
strategy(calc_on_order_fills=)on_fill(self, ctx, fill) runs after each fill
varAn attribute set in setup(self, ctx)
barstate.isfirst, barstate.islastsetup(self, ctx) and on_end(self, ctx, reason)
library(), import user/lib/1A library file listing its names in __all__, imported with a Python import

Settings

You writeIn Forge
strategy(max_bars_back=)warmup = n on the class
input.int(), input.float(), input.bool(), input.string(), input.source(), input.timeframe(), input.symbol(), input.session(), input.time(), input.price(), input.color()param.Int, param.Float, param.Bool, param.Choice, param.Source, param.Timeframe, param.Symbol, param.Session, param.Time, param.Price, param.Colorfg.param.Intfg.param.Choicefg.param.Color

Orders

You writeIn Forge
strategy(default_qty_type=, default_qty_value=)size=fg.Size... in fg.Signalsfg.Size
strategy(pyramiding=)max_entries_per_direction = n on the class
strategy(close_entries_rule=)ctx.close(tag=...) closes the positions of one entry tag
strategy.entry()long_entry= and short_entry= in fg.Signals with tags=, or ctx.buy() and ctx.sell() in a hookfg.Signals
strategy.order()ctx.order(fg.Order.market(...)), .limit(...) or .stop(...)fg.Order
strategy.exit()stop=fg.Stop..., target=fg.Target..., trail=fg.Trail... in fg.Signalsfg.Stopfg.Targetfg.Trail
strategy.close()long_exit= or short_exit= in fg.Signals, or ctx.close(tag=id)fg.Signals
strategy.close_all()ctx.close_all()
strategy.cancel(), strategy.cancel_all()ticket.cancel(), ctx.cancel_all(tag=...)
strategy.risk.allow_entry_in()direction = "long" or "short" on the class
strategy.risk.max_position_size()caps = fg.Caps(max_lots=...)fg.Caps
strategy.risk.max_drawdown(), strategy.risk.max_intraday_loss(), strategy.risk.max_cons_loss_days()fg.prop rules, which stop or pause trading at a limit
strategy.risk.max_intraday_filled_orders()fg.Filter.max_trades(per="day", n=...)fg.Filter

Positions

You writeIn Forge
strategy.position_size, strategy.position_avg_pricepos.size and pos.avg_price of ctx.positions()
strategy.opentradeslen(ctx.positions())

History

You writeIn Forge
strategy.netprofit, strategy.closedtrades, strategy.wintradesctx.stats while the run goes; ctx.trades for each closed trade

The account

You writeIn Forge
strategy.equity, strategy.openprofitctx.account.equity, pos.unrealized

The symbol

You writeIn Forge
timeframe.period, syminfo.mintick, syminfo.pointvaluebars = fg.bars.Time("H1"), ctx.symbol.tick_size, ctx.symbol.tick_value

Time

You writeIn Forge
time, time_closed.time_open, d.time_close (UTC nanoseconds)

Data

You writeIn ForgeNoteTrap
request.security()d.tf("H4"), d["GBPUSD"] or d["GBPUSD"].tf("H4")Every other series is written in the file, so Forge loads it before the run.
na, na(), nz()NaN, fg.isna(x), fg.nz(x, 0)fg.isnafg.nz
close[1]Whole arrays in compute(); ctx.bars.close.ago(1) in a hookTrap

Indicators

You writeIn Forge
ta.*fg.ta functions, with Pine's names where the maths is the same: see the function table

Chart and screen

You writeIn Forge
plot(), plotshape(), bgcolor()plots= in fg.Signals, or ctx.plot and ctx.mark in a hookfg.Plot

Run settings

You writeIn Forge
strategy(initial_capital=)The Tester's starting capital. Suggest one with defaults = {"balance": 10000}.
strategy(currency=)The run's account currency, from your account settings. Suggest one with defaults = {"currency": "EUR"}.
strategy(commission_type=, commission_value=)The run's commission, set in the Tester or your execution profile
strategy(slippage=)The run's slippage setting
strategy(margin_long=, margin_short=)Margin comes from the broker's facts for the symbol

Pine's ta functions

Measured means the two were run on the same prices and compared. From the registry means it is read from Forge's own list of indicators.

PineIn ForgeSame mathsSame order of valuesHow we know
ta.smata.smaSameSameMeasured
ta.emata.emaDiffersSameMeasured
ta.rmata.rmaSameSameMeasured
ta.wmata.wmaSameSameMeasured
ta.vwmata.vwmaSameSameFrom the registry
ta.hmata.hmaDiffersSameFrom the registry
ta.almata.almaSameSameFrom the registry
ta.linregta.linregSame
ta.rsita.rsiSameSameMeasured
ta.stochta.stochDiffers
ta.macdta.macdSame
ta.ccita.cciSame
ta.cmota.cmoSame
ta.mfita.mfiDiffers
ta.momta.momSameSameMeasured
ta.rocta.rocSameSameMeasured
ta.changeta.changeSameSameMeasured
ta.wprta.wprSame
ta.trta.trSameDiffersMeasured
ta.atrta.atrDiffersSameMeasured
ta.bbta.bbSame
ta.bbwta.bbwSame
ta.kcta.kcDiffers
ta.kcwta.kcwDiffers
ta.stdevta.stdevSameDiffersMeasured
ta.varianceta.varianceSameSameMeasured
ta.dmita.dmiDiffers
ta.sarta.sarDiffers
ta.supertrendta.supertrendSameDiffersFrom the registry
ta.obvta.obvSame
ta.accdistta.accdistSame
ta.vwapta.vwapDiffers
ta.highestta.highestSameSameMeasured
ta.lowestta.lowestSameSameMeasured
ta.highestbarsta.highest_barsSame
ta.lowestbarsta.lowest_barsSame
ta.risingta.risingDiffersSameMeasured
ta.fallingta.fallingDiffersSameMeasured
ta.cumta.cumSameSameMeasured
ta.percentrankta.percentrankSameSameMeasured
ta.medianta.medianSameSameMeasured
ta.correlationta.correlationSameSameMeasured
ta.crossoverta.crossoverSameSameMeasured
ta.crossunderta.crossunderSameSameMeasured
ta.crossta.crossDiffersSameMeasured
ta.barssinceta.barssinceSameSameMeasured
ta.valuewhenta.valuewhenSameSameMeasured
ta.pivothighta.pivot_highDiffersSameFrom the registry
ta.pivotlowta.pivot_lowDiffersSameFrom the registry
nzta.nzSame

Every Forge name is in the reference.