Repository navigation
Description
Summary
An empty timeframe string stands for the chart timeframe in Pine (as in request.security(syminfo.tickerid, "", close), which #294 case 2 made work in 1.11.0), and timeframe.in_seconds("") is a common way to write the chart timeframe in seconds. Codegen 1.12.0 passes the empty string through:
secs = ... tf_to_seconds(std::string("")) ...and the engine's tf_to_seconds (src/timeframe.cpp) returns 0 for an empty string, so the value is 0 on every bar. With no argument, or with timeframe.period, Codegen emits tf_to_seconds(script_tf_) and the value is the chart's 3600 on a 1h chart. Nothing fails, so a script that divides or compares by this value runs with a silently wrong number.
timeframe.change("") has the same cause: it is emitted as tf_change(prev_bar_timestamp_, current_bar_.timestamp, std::string(""), syminfo_.timezone, syminfo_.session) and is never true, while timeframe.change(timeframe.period) is true on every bar after the first.
Versions
pineforge-codegen 1.12.0 with pineforge-engine v1.12.0 (6e27d0f2). Apple clang 17.0.0, macOS 15.8 arm64. BTCUSDT 1h bars from 2024-01-01 to 2024-03-01 (1,441 bars), initial capital 10000, no commission or slippage.
TradingView: BINANCE:BTCUSDT, 1h, Deep Backtesting over the same dates, measured on 2026-11-14: the two scripts and their controls save without error and give the same 26 trades (the last one still open at the end of the range), net profit 29.93, as the controls on PineForge. timeframe.in_seconds("") is 3600 on each of the 1,360 bars up to the last entry, as timeframe.in_seconds(timeframe.period); timeframe.change("") is false on the first bar of the range and true on the 1,359 bars after it up to the last entry, as timeframe.change(timeframe.period). The values were read through the order comment of each entry, as the minimum and maximum over the bars so far.
Reproduction
1. timeframe.in_seconds("")
//@version=6
strategy("timeframe.in_seconds empty string", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
secs = timeframe.in_seconds("")
// @pf-trace secs=secs
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
strategy.close("Long")
secs traces 0 on all 1,441 bars.
Control, one change: timeframe.in_seconds(timeframe.period). It traces 3600 on all 1,441 bars.
2. timeframe.change("")
//@version=6
strategy("timeframe.change empty string", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
chg = timeframe.change("") ? 1 : 0
// @pf-trace chg=chg
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
strategy.close("Long")
chg traces 0 on all 1,441 bars.
Control, one change: timeframe.change(timeframe.period). It traces 0 on bar 0 and 1 on bars 1 to 1440.
Both scripts and both controls run with 26 trades, net profit 29.93.
Expected
timeframe.in_seconds("") gives the chart timeframe in seconds, as the control: 3600 on a 1h chart; timeframe.change("") follows the chart timeframe as timeframe.change(timeframe.period) does. Mapping "" to script_tf_ where the argument is emitted, as already done for the call with no argument, would cover both.
Workaround
Pass timeframe.period, or call timeframe.in_seconds() / timeframe.change() with no argument.
Activity
luisleo526 commentedon Nov 14, 2026
Thank you for the detailed report and the controls; they make each case easy to reproduce.
We will reproduce the empty-timeframe cases (
timeframe.in_seconds("")giving 0 andtimeframe.change("")never firing) on Codegen 1.12.0 and on current main, find where the translation goes wrong, and post the findings here by 2026-11-15, with a fix target. This one is near the front of our queue because it can give a silently wrong value rather than a build error.🤖 Generated with Claude Code
luisleo526 commentedon Nov 15, 2026
Findings 2026-11-15 (UTC+8), as promised.
timeframe.in_seconds("")gives 0 andtimeframe.change("")never fires.request.securityalready does since 1.11.0.0) must be refused with its own clear error, some numeric argument forms are not refused yet, aboolargument (which TradingView refuses) must be refused in every form, and we are checking what TradingView returns fortimeframe.change(na)before we settle that case.Fix target: we cannot give one honestly yet, because those changes still have to pass review and verification, and the fix is not in today's batch. We will post the date here as soon as they have, and the merge commit when it lands.
Resolve empty timeframe arguments, keep reference types across calls,…
luisleo526 commentedon Nov 15, 2026
Fixed on main in 0ba632a (#405). Empty timeframe string arguments now resolve as the chart timeframe across the timeframe functions:
timeframe.in_seconds("")returns the chart's seconds, andtimeframe.change("")fires when the chart period changes. Regression tests cover each empty, explicit and omitted timeframe argument form; they fail on the previous main and pass now.Preserve compound value types across user function calls (#406)