|
PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
|
A/B comparison of the same strategy run with and without the bar magnifier. Quantifies the difference in trade count, fill prices, and net PnL.
The magnifier only adds resolution when script_tf > input_tf — i.e. the runtime is aggregating finer input bars up to a coarser script timeframe. With input_tf == script_tf it still walks each input bar as one sub-bar (the counters count them), but there is no finer path to recover.
The tutorial MACD strategy ships at 15-minute timeframe. Running it with input_tf="15", script_tf="60" (15-minute feed driving an hourly strategy) makes the magnifier sample intra-hour fills from the 15-minute bars.
ta.crossover evaluated at script-bar close) is bar-close-deterministic. Distribution modes only differ when the script has intra-bar strategy.exit(stop=…) brackets, trail stops, or take-profit limits — see Bar magnifier.Save it two directories below the repository root (for example demo/python/magnifier_ab.py in a clone): the ROOT and sys.path lines assume that depth.
| Observation | What it tells you |
|---|---|
sub_bars_total is 0 with magnifier on | The magnifier was actually off, or no bar was given an intrabar path. With script_tf == input_tf it still walks each input bar (one sub-bar each: 672 sub-bars, 2688 ticks on the tutorial feed), and a bar-close strategy's fills stay the same. |
| Trade count goes up with magnifier on | Stops/limits resolved intra-bar that would otherwise have rolled over to next-script-bar fills. |
| Trade count unchanged, PnL changes | Same fills, but at finer-grained prices — typical for strategy.exit(profit, loss) brackets. |
| Distribution modes give different PnL | Strategy has intra-bar exits (stops, limits, trailing). |
| Distribution modes give identical PnL | Strategy is bar-close-deterministic — distribution choice doesn't matter. |
ticks_total ≈ samples * sub_bars_total | Healthy sample density. Big gap → check for sub-bars too small to magnify. |
strategy.exit(stop=…, limit=…) brackets — the OCA pair fills on whichever level is hit first inside the bar.strategy.exit(trail_points=…, trail_offset=…) — trailing stops update on every magnified sample.calc_on_order_fills, the orders a fill recalculation places inside the bar: a market entry or strategy.close fills at that intrabar point.For pure bar-close strategies (the tutorial MACD is one), the magnifier is a no-op on PnL — only magnifier_sub_bars_total changes.