Strategy · Pine Script v6 · On the chart

PF Probe Market-Shift-Probe-01-Shift-State

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

This strategy maintains a market regime state based on breaks through recent pivot highs and lows.

View on GitHub

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

64 lines of Pine Script v6 from validation/composite-marketshift-pivot-state-machine-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-01-shift-state — bull/bear regime state machine on pivot breaks
// Clean-room: written from validation goal, not from source.
//
// Purpose: isolates the regime state machine surface used by structural-shift
// strategies. A `var int market_state` holds three values (0 neutral, 1 bull,
// -1 bear). Transitions happen only when price closes through the most recent
// confirmed pivot high (→ bull) or pivot low (→ bear). The engine surface
// under test is cross-bar `var` state mutation gated by `ta.pivothigh` /
// `ta.pivotlow` confirmation plus simple price-vs-level breakthrough. No
// orders depend on bracket arithmetic here — this probe routes a trivial
// flat-flip entry directly off `market_state` so any TV/engine drift is
// attributable to the pivot tracking + state mutation, nothing else.
//
// Validation goal: bit-exact trade list against TradingView's broker emulator
// on the reference 15-minute ETH-USDT-USDT feed. Long when state flips to 1,
// short when state flips to -1.
//
// 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-01-shift-state", shorttitle="PF_MS01_STATE",
     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)

// Hold the most-recently confirmed pivot levels across bars.
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 ------------------------------------------
var int market_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

// ---- trivial flat/flip routing off the state -----------------------
if market_state ==  1 and strategy.position_size <= 0
    strategy.entry("L", strategy.long, qty=1, comment="state bull")

if market_state == -1 and strategy.position_size >= 0
    strategy.entry("S", strategy.short, qty=1, comment="state bear")

Overview

PF Probe Market-Shift-Probe-01-Shift-State tracks pivot levels with user-set strength and flips from neutral to bull on price closing above the last pivot high or to bear on closing below the last pivot low. Long entries occur when the state is bull and flat, while short entries trigger when the state is bear and flat. The strategy uses fixed position sizing of 1 and reverses positions on state flips with no explicit exit rules or stop loss. The primary setting adjusts pivot strength. It plots directly on the price chart.

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, Support & resistance

Markets

Any symbol

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

Omar Edited WF

by Alorse
330 stars

Omar Edited WF is a trading strategy overlay built around Williams Fractals and multiple Exponential Moving Averages. It detects high and low fractal pivot points over configurable lookback periods alongside three adjustable EMA trendlines. Long entries are ma

Strategy v5 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of Omar Edited WF
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar
106 stars

This overlay strategy plots a two-timeframe Ichimoku setup on the price chart, with Tenkan, Kijun, Chikou, and Kumo from a base higher timeframe and an optional highest-timeframe cloud. It allows two entries in the same direction and uses ATR-based trailing st

Strategy v4 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of 2Tier Ichimoku Pyramiding [Takazudo]
104 stars

This strategy combines three Exponential Moving Averages with Williams Fractals to execute trend-following or mean-reverting trades. It analyzes price structure using short, medium, and long-term EMAs along with fractal highs and lows. Entries trigger when fra

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of 3MA and Fractals Strategy

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