Strategy · Pine Script v6 · Own pane

Percent Rank Reversion

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

This strategy measures the percentile rank of bar-to-bar close changes and plots that rank in a separate pane with a five-bar simple moving average and fixed overbought, oversold, and midline levels.

View on GitHub

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

43 lines of Pine Script v6 from validation/ta-percentrank-mean-reversion-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 25 — percent-rank mean reversion
// Purpose: parity test for ta.percentrank() over price-change series with
// extreme-then-rising / extreme-then-falling reversion entries.
//
//@version=6
strategy("Percent Rank Reversion", overlay=false, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)

// === Inputs ===
prLen  = input.int(50, "Percentile Rank Length", minval=10)
obPR   = input.float(90, "Overbought PR")
osPR   = input.float(10, "Oversold PR")

// === Percent Rank of price changes ===
priceChange = close - close[1]
pr = ta.percentrank(priceChange, prLen)

// === Smoothed signal ===
prSmooth = ta.sma(pr, 5)

// === Mean reversion signals ===
longCond  = pr < osPR and pr > pr[1]
shortCond = pr > obPR and pr < pr[1]

if longCond
    strategy.entry("Long", strategy.long)
if shortCond
    strategy.entry("Short", strategy.short)

// === Exit at middle ===
if strategy.position_size > 0 and pr > 50
    strategy.close("Long")
if strategy.position_size < 0 and pr < 50
    strategy.close("Short")

plot(pr, "Percent Rank", color=color.blue)
plot(prSmooth, "Smooth PR", color=color.orange)
hline(obPR, "OB", color=color.red)
hline(osPR, "OS", color=color.green)
hline(50, "Mid", color=color.gray)

Overview

Percent Rank Reversion enters long when the rank is below the oversold threshold and rising, and short when the rank is above the overbought threshold and falling. Open longs close once the rank rises above 50, and open shorts close once it falls below 50. Length and both extreme thresholds are user inputs. There is no stop loss.

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

Separate pane below the chart

Category

Oscillators & momentum, Mean reversion

Markets

Any symbol

Timeframes

Any timeframe

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
Percentile Rank Lengthint50prLen
Overbought PRfloat90obPR
Oversold PRfloat10osPR
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 strategy combines Larry Williams' Vix Fix synthetic volatility indicator with Bollinger Bands. It calculates standard and inverted Williams Vix Fix metrics, displaying them as histogram columns with standard deviation bands in a separate pane. Long entrie

Strategy v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Williams Vix Fix Strategy [Alorse]

2xTP, SL to Entry

by hasnocool
106 stars

This strategy executes mean-reversion trades based on Bollinger Bands and the Stochastic Oscillator. Long orders trigger when price dips below the lower band alongside a bullish Stochastic crossover, with an optional oversold threshold. Short orders execute on

Strategy v5 Mean reversionOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 2xTP, SL to Entry

Greeffer BB Strategy

by SammyEnigma
18 stars

This strategy fades Bollinger Band extremes using the close. It enters short when price crosses above the upper band and the 14-period RSI is above 70, and enters long when price crosses below the lower band and RSI is below 30. It closes half of an open short

Strategy v4 Volatility & bandsOscillators & momentum
Updated 6 years ago · None stated GitHub repository of Greeffer BB Strategy

This strategy calculates the WaveTrend oscillator alongside Stochastic RSI to identify reversal setups at overbought and oversold extremes. It enters long positions when the WaveTrend oscillator crosses upward below configured oversold levels, and enters short

Strategy v6 Oscillators & momentumMean reversion Repaints
Updated yesterday · MIT GitHub repository of WaveTrend v4 [WavesUnchained] Strategy

Williams %R Reversal - Eterna MCP

by EternaHybridExchange
9 stars

This strategy tracks the Williams %R oscillator to trade mean-reversion bounces from overbought and oversold extremes. It opens long or short positions when a reversal signal occurs alongside confirming price direction, while generating JSON-formatted alert pa

Strategy v5 Oscillators & momentumMean reversion
Updated 7 months ago · MIT GitHub repository of Williams %R Reversal - Eterna MCP

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