Skip to content

Known issue in PineForge Codegen 1.9.1: state in per-bar timeframe requests #314

Closed

Description

@luisleo526

State inside request.security can produce incorrect results when the requested timeframe is chosen per bar, even when both choices are multiples of the chart and feed timeframe.

On BTCUSDT with a 1-hour chart and feed, the following script chooses 120 or 180 minutes. In released 1.9.1, its entry quantities matched TradingView for 126 of 205 entries. In the 120-minute arm, 17 of 96 matched. These are exact joins by entry time.

//@version=6
strategy("Selected timeframe", currency = currency.NONE, initial_capital = 1000000)
// state inside a request whose timeframe (120 or 180 minutes) is chosen each bar
payload() =>
    var float saved_v = na
    saved_v := nz(saved_v) + close
    saved_v
tf_v = close > open ? "120" : "180"
got_v = request.security(syminfo.tickerid, tf_v, payload())
qty_v = 1 + int(got_v / 1000) % 5
if bar_index > 6 and bar_index % 7 == 3
    strategy.entry("L", strategy.long, qty = qty_v)
if bar_index > 6 and bar_index % 7 == 5
    strategy.close("L")

Workaround: not yet verified.

Fixed in the next release (1.10.0). The measured fix candidate matches all 205 entry quantities for this case. No release date is announced here.

Updated 2026-11-03: this issue first said "the next patch release". The next release is 1.10.0, a minor release.

See also: pineforge-4pass/pineforge-engine#718.

Activity

  1. luisleo526 commented on Nov 2, 2026

    @luisleo526
    ContributorAuthor

    Fixed by #316, merged on 2026-11-03. State inside a request.security call whose timeframe is chosen per bar now gets one independent copy per selected timeframe. The float recurrence measured in this issue matches TradingView in 205 of 205 entries, where 1.9.1 matched 126. The fix ships in the next release. A requested timeframe that is not a multiple of the chart timeframe is a separate known issue, pineforge-4pass/pineforge-engine#718, and is not changed by this fix.

  2. luisleo526 commented on Nov 3, 2026

    @luisleo526
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions