Strategy · Pine Script v6 · On the chart

PF Probe Market Shift Probe 03 Shift Driven Entry

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

This strategy detects market regime state transitions based on pivot high and low break levels.

View on GitHub

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

69 lines of Pine Script v6 from validation/composite-marketshift-state-edge-detector-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 market-shift-probe-03-shift-driven-entry — entries on state-change edges
// Clean-room: written from validation goal, not from source.
//
// Purpose: isolates the rising-edge detector surface used to fire entries
// only on `market_state` transitions (not on every bar where the state is
// "true"). Two cross-bar `var int` slots — `market_state` and `prev_state` —
// produce a single-bar long signal when `market_state` flips to +1 from
// anything else, and a single-bar short signal on the symmetric -1 flip.
// The engine surface under test is the bar-end `prev_state := market_state`
// assignment ordering: the comparison MUST happen before the assignment, or
// the edge collapses and entries fire every bar instead of once.
//
// Validation goal: bit-exact trade list against TradingView's broker emulator
// on the reference 15-minute ETH-USDT-USDT feed. Long fires once per bull
// transition, short fires once per bear transition.
//
// 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 market-shift-probe-03-shift-driven-entry", shorttitle="PF_MS03_EDGE",
     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_pivot = input.int(5, "Pivot strength (left=right)", minval=2, maxval=20)

// ---- pivot tracking ------------------------------------------------
float ph = ta.pivothigh(high, i_pivot, i_pivot)
float pl = ta.pivotlow(low,   i_pivot, i_pivot)

var float last_ph = na
var float last_pl = na

if not na(ph)
    last_ph := ph
if not na(pl)
    last_pl := pl

// ---- regime state machine + edge detector --------------------------
var int market_state = 0
var int prev_state   = 0

bool break_up   = not na(last_ph) and close > last_ph
bool break_down = not na(last_pl) and close < last_pl

if break_up
    market_state := 1
else if break_down
    market_state := -1

bool long_edge  = market_state ==  1 and prev_state !=  1
bool short_edge = market_state == -1 and prev_state != -1

// ---- routing -------------------------------------------------------
if long_edge and strategy.position_size <= 0
    strategy.entry("L", strategy.long, qty=1, comment="bull edge")

if short_edge and strategy.position_size >= 0
    strategy.entry("S", strategy.short, qty=1, comment="bear edge")

// Update prev_state AFTER all comparisons + entries — last statement.
prev_state := market_state

Overview

PF Probe Market Shift Probe 03 Shift Driven Entry calculates pivot highs and lows using a specified strength setting and updates the market state when the close price breaks above the last pivot high or below the last pivot low. A long position is entered when the market shifts to a bullish state, and a short position is entered when it shifts to a bearish state. Existing positions reverse when opposing state transitions occur. Drawn directly on the price chart, the strategy uses no stop loss or take profit targets.

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

Trend, Breakout, Support & resistance

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
Pivot strength (left=right)int5i_pivot
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 trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated today · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
257 stars

This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos

Strategy v6 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Best Chart 1m Strategy Candle Bar
106 stars

Calculates multi-period logarithmic regression trend channels and deviation bands across up to twenty selectable lookback lengths directly on the price chart. It evaluates channel slopes and Pearson's correlation coefficient to detect market trends and generat

Strategy v5 TrendSupport & resistance Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of Advanced Trend Detection Strategy

This trend breakout strategy plots Donchian Channels consisting of upper, lower, and middle bands directly on the main price chart. Long positions enter when price touches the upper channel and pulls back to or below the middle band, placing a stop loss at the

Strategy v6 TrendBreakout
Updated 2 months ago · MPL-2.0 GitHub repository of Donchian Strategy - Dynamic TP, Fixed SL, 1% Risk, Daily Target
43 stars

This strategy executes trades on short-term cryptocurrency charts using a combination of pivot support and resistance levels and a multi-pole smoothed trend filter. Entries trigger when price crosses the smoothed trend line and confirms above or below a short-

Strategy v5 TrendBreakout Repaints
Updated 2 years ago · None stated GitHub repository of SOL 1m - Strategy Candle Bar

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