Strategy · Pine Script v6 · On the chart

PF probe 4ema-rsi-probe-03-binary-bar-window

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

This strategy executes trades based on fast and slow exponential moving average crossovers constrained by a configurable intraday session window.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code60
Settings2inputs
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

60 lines of Pine Script v6 from validation/composite-4emarsi-session-window-nbar-exit-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
//
// PF probe 4ema-rsi-probe-03-binary-bar-window — session window + N-bar expiry
// Clean-room: written from validation goal, not from source.
//
// Purpose: isolates a binary-options-style fixed-bar exit combined with an
// intraday session-window gate. The engine surfaces under test are
// `time(timeframe.period, sessionSpec)` for the entry-gating window and a
// `var int` bars-in-trade counter that forces an exit after N bars. This
// validates that the engine's session-time evaluation and per-bar trade-age
// counter both align with TradingView's broker emulator at the boundary
// bars (open of session, last bar of trade).
//
// Validation goal: bit-exact entries that occur ONLY inside the session
// window, and bit-exact forced exits exactly N bars after entry regardless
// of any other condition. Pass = identical trade list vs TradingView.
//
// TV setup: 15m chart, ETH-USDT-USDT (Binance USDT-M Perpetual). Full window
// matching corpus/data/ohlcv_ETH-USDT-USDT_15m.csv. Strategy properties:
// leave defaults from script header. Export "List of trades" → tv_trades.csv.
//@version=6
strategy("PF probe 4ema-rsi-probe-03-binary-bar-window", shorttitle="PF_4ema03_WIN",
     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)

// ---- inputs --------------------------------------------------------
int    i_expiry_bars = input.int(8, "Forced exit after N bars", minval=1)
string i_session     = input.session("1000-2200", "Entry session (UTC)")

// ---- session gate (UTC reference; chart timezone overrides display) -
bool in_window = not na(time(timeframe.period, i_session, "UTC"))

// ---- trivial momentum trigger inside the window --------------------
float fast = ta.ema(close, 5)
float slow = ta.ema(close, 20)
bool  long_trigger  = ta.crossover(fast, slow)  and in_window
bool  short_trigger = ta.crossunder(fast, slow) and in_window

// ---- bars-in-trade counter ----------------------------------------
var int bars_in_trade = 0
if strategy.position_size != 0
    bars_in_trade += 1
else
    bars_in_trade := 0

bool expiry_due = strategy.position_size != 0 and bars_in_trade >= i_expiry_bars

// ---- order routing -------------------------------------------------
if long_trigger and strategy.position_size == 0
    strategy.entry("L", strategy.long, qty=1, comment="window long")

if short_trigger and strategy.position_size == 0
    strategy.entry("S", strategy.short, qty=1, comment="window short")

if expiry_due
    strategy.close_all(comment="bar-window expiry")

Overview

Long positions open on bullish EMA crosses and short positions open on bearish EMA crosses when no existing position is held. A counter tracks active trade duration and closes positions once a specified bar count threshold is reached. Drawn directly on the price chart, it features no take-profit or stop-loss orders, relying solely on the time-based bar expiry exit.

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

Moving averages, Sessions & time

Markets

Crypto

Timeframes

M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Forced exit after N barsint8i_expiry_bars
Entry session (UTC)session1000-2200i_session
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

This overlay strategy offers two selectable entry modes: a Bollinger squeeze on typical price and a simple moving-average cross. It filters trades by weekday, session, date range, and an optional news window, and can restrict direction or invert the side. Risk

Strategy v5 Volatility & bandsMoving averages
Updated today · None stated GitHub repository of Boilerplate Configurable Strategy [Yosiet]
257 stars

Donald - Test Logic Futures is an overlay strategy designed for intraday futures trading. It combines kernel regression functions with exponential moving averages to evaluate price retracements and entry timing. Trades are filtered by session execution windows

Strategy v5 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald - Test Logic Futures

Andean Scalping

by hasnocool
106 stars

Andean Scalping is a Pine Script v5 strategy template designed for backtesting trading signals. It features session and date-range filtering, directional trade toggles for long and short entries, and optional trend filtering tools including higher-timeframe EM

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of Andean Scalping
39 stars

This intraday strategy implements Mark Fisher's Opening Range Breakout (ORB) methodology tailored for index futures like ES and NQ. It calculates session opening ranges, volume z-scores, and VWAP bands to plot support, resistance, and confirmation levels on th

Strategy v6 BreakoutSessions & time Repaints
Updated 4 days ago · MIT GitHub repository of Futures Intraday Pro (ES/NQ) Strategy

P404 Smoke

by Musyimi97
16 stars

P404 Smoke is a price-chart strategy that sequences an optional higher-timeframe EMA bias, a liquidity range from recent pivots, a sweep of buy-side or sell-side liquidity, and a market structure shift within a set bar window. Comments state it then looks for

Strategy v5 SMC / ICT / price actionSupport & resistance
Updated 6 months ago · MIT GitHub repository of P404 Smoke

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