Pine traps

Forge API 1Updated 1 Oct 2026

History references

close[1] in Pine is the previous bar. In Forge an array is ordered oldest first, so the previous bar is index -2.

import forge as fg

FORGE_API = 1


def previous_close(close):
    # Pine's close[1] is the bar before the latest closed one.
    return close[-2]

Repainting on the forming bar

A Pine script recalculates on every tick of the bar that is still forming, so its plot can move and then settle. A backtest only sees the settled value. Forge computes on closed bars, so what a chart shows is what a test used.

Look-ahead in higher timeframes

Pine's security call can be told to look ahead, which shows a higher-timeframe value before its bar has closed. Forge has no such setting: a slower series is visible on the first bar whose close is at or after its own close.

Persistent state

Pine's var keeps a value across bars. A Forge compute has no state, because it works on arrays. Express the state as an array operation, or use the bar-by-bar form with declared state fields.

na

Pine's na is Forge's NaN. A comparison with it is false in both.

import forge as fg
from forge import ta

FORGE_API = 1


def clean(value):
    # Pine's nz(value): a missing value becomes zero.
    return ta.nz(value)

Order fills

A Pine strategy fills a market order at the next bar's open by default. A Forge order decided at a close fills at the first real price after it, which is usually close to the same place and is always a price that traded.