Strategy · Pine Script v6 · On the chart

PF na-chain probe 01 - deep history int na

by pineforge-4pass· code credited to PineForge contributors 2026

This strategy computes a session-gated RSI value using a deep history reference of 500 bars on a source that is NA outside the session window.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code51
Settings0inputs
LicenceApache-2.0
Last update5 days ago23 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

51 lines of Pine Script v6 from validation/na-deep-history-int-na-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// na-chain probe 01 — deep history + int-NA + na->bool cast
//
// Purpose: surface int-NA undefined behavior and `nz` chain truncation.
// We feed `ta.rsi` a `na`-gated source, request history depth >= 500,
// keep `nz` only at the leaf, use `time(session)` to produce out-of-session
// `na<int64>` values, and then cast `na` through to a bool used by the
// entry condition. If the C++ runtime's int-NA sentinel collides with
// `INT_MIN` in any reduction path, the trade list will diverge from TV.
//
// Trade shape: long-only. Every bar we compute a session-gated RSI on a
// source that is `na` outside session, only `nz`'d at the very last step
// (so intermediate RSI internals see `na`). Entry on RSI cross-up of 30
// AND non-na session id; exit on cross-down of 70.
//
// TV setup: 15m chart, ETH-USDT-USDT, same window as
// data/ohlcv_ETH-USDT-USDT_15m.csv. Export the trade list to tv_trades.csv.
//@version=6
strategy("PF na-chain probe 01 - deep history int na", shorttitle="NA_p01_INT", overlay=true,
     initial_capital=1000000,
     commission_type=strategy.commission.percent, commission_value=0, slippage=0,
     default_qty_type=strategy.fixed, default_qty_value=1, pyramiding=1,
     process_orders_on_close=false,
     max_bars_back=500)

// Out-of-session producer: time(timeframe, session, timezone) returns na<int64> outside the window
int sessId = time(timeframe.period, "0930-1600", "America/New_York")

// Gated source — na outside session; nz only at the leaf
float gatedSrc = na(sessId) ? na : close

// Deep history reach (500 bars back) on the gated source
float deepRef = nz(gatedSrc[499], close)

// Mix gated + deep-history into RSI; nz applied at leaf only
float src = nz(gatedSrc, deepRef)
float rsiVal = ta.rsi(src, 14)

// na -> bool cast path
bool sessOk = not na(sessId)

bool entryCond = ta.crossover(rsiVal, 30.0) and sessOk
bool exitCond  = ta.crossunder(rsiVal, 70.0)

if entryCond and strategy.position_size == 0
    strategy.entry("L", strategy.long, qty=1, comment="entry long")
if exitCond and strategy.position_size > 0
    strategy.close("L", comment="exit long")

Overview

PF na-chain probe 01 - deep history int na signals long entries on RSI crossover above 30 with valid session and closes positions on crossover below 70. The strategy plots on the price chart with overlay=true and uses fixed position sizing of 1. Main settings control deep history reach and session gating. It has no stop loss and tests NA chain behavior through nz casting.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Oscillators & momentum, Sessions & time

Markets

Crypto

Timeframes

M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

ARR VWAP Intraday

by hasnocool
106 stars

This strategy plots VWAP on the price chart and trades only between a start hour and an end hour. It enters long when VWAP is rising and RSI is above a threshold, and short when VWAP is falling and RSI is below a threshold. If the reversal option is on, it clo

Strategy v4 Oscillators & momentumVolume Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of ARR VWAP Intraday
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy
43 stars

Donald - AI Futures is a price-chart strategy that estimates inner and outer high-low zones and a smoothed close with rational quadratic kernel regression. It builds bullish and bearish momentum signals, optionally compares volume with a volume-weighted moving

Strategy v5 Oscillators & momentumSMC / ICT / price action Repaints
Updated 2 years ago · None stated GitHub repository of Donald - AI Futures

Turtle MACD Time-Zone Filter

by skywalker0803r
42 stars

This strategy enters long when price closes above the prior Donchian high and short when it closes below the prior Donchian low, only while flat and inside a Taipei-hour window. It exits on a MACD histogram reversal or through an ATR stop and a percentage take

Strategy v5 BreakoutOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Turtle MACD Time-Zone Filter

Morning Scalp

by benso87
24 stars

This strategy tracks an opening session time range to establish directional bias and triggers pullback trades using Stochastic RSI. Once price breaks out of the initial range, it establishes a directional bias and enters when the Stochastic RSI crosses over in

Strategy v5 Sessions & timeBreakout
Updated 4 years ago · MPL-2.0 GitHub repository of Morning Scalp

XAUUSD SMC Bot

by GifariKemal
15 stars

This strategy plots on the XAUUSD price chart and looks for Smart Money Concepts entries on the fifteen-minute timeframe. It scores fair value gaps, order blocks, liquidity sweeps, break of structure, and change of character, plus EMA, RSI, MACD, and higher-ti

Strategy v5 SMC / ICT / price actionOscillators & momentum
Updated 8 months ago · None stated GitHub repository of XAUUSD SMC Bot

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers