Indicator · Pine Script v6 · Own pane

Price Efficiency Ratio (PER) [SharpStrat]

by eddiebelaval· code credited to SharpStrat

This indicator calculates a price efficiency ratio by dividing the net close change over a lookback by the sum of absolute bar-to-bar moves, then scales the result from 0 to 100.

View on GitHub

GitHub stars7on the repository
Pine versionv6current
Lines of code108
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update3 months ago24 Jul 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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

108 lines of Pine Script v6 from pinescript/oscillators/price-efficiency-ratio-per-sharpstrat.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

price-efficiency-ratio-per-sharpstrat.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SharpStrat

//@version=6
indicator("Price Efficiency Ratio (PER) [SharpStrat]", overlay=false)

// INPUTS
length = input.int(30, "Lookback Period", minval=2, group="Core Settings")
enableSmoothing = input.bool(true, "Enable Smoothing", group="Core Settings")
smoothing = input.int(20, "Smoothing Period", minval=1, group="Core Settings")
useVolumeWeight = input.bool(false, "Volume-Weighted PER", tooltip="Weight price movements by volume", group="Core Settings")

// Zone
zoneType = input.string("Dynamic", "Threshold Type", options=["Fixed", "Dynamic"], tooltip="Fixed: Manual threshold | Dynamic: Auto-calculated", group="Threshold Settings")
threshold = input.float(25.0, "Efficiency Threshold (Fixed)", minval=0, maxval=100, tooltip="Above = Trending | Below = Ranging", group="Threshold Settings")
thresholdLookback = input.int(252, "Dynamic Threshold Lookback", minval=20, group="Threshold Settings")
dynamicPercentile = input.int(40, "Dynamic Threshold Percentile", minval=10, maxval=90, group="Threshold Settings")

showInfoBox = input.bool(true, "Show Info Box", group="Display Settings")

// calc
netDistance = math.abs(close - close[length])

// volume weighting
totalDistance = 0.0
for i = 1 to length
    priceMove = math.abs(close[i-1] - close[i])
    weight = useVolumeWeight ? volume[i] : 1.0
    totalDistance := totalDistance + (priceMove * weight)

weightedNetDistance = netDistance
if useVolumeWeight
    totalVolume = math.sum(volume, length)
    avgVolume = totalVolume / length
    weightedNetDistance := netDistance * avgVolume

per = totalDistance > 0 ? ((useVolumeWeight ? weightedNetDistance : netDistance) / totalDistance) * 100 : 0

perFinal = enableSmoothing ? ta.sma(per, smoothing) : per

// Dynamic Threshold
thresholdDynamic = ta.percentile_linear_interpolation(perFinal, thresholdLookback, dynamicPercentile)

thresholdFinal = zoneType == "Dynamic" ? thresholdDynamic : threshold

// visual
getGradientColor(value, thresh) =>
    if value < thresh
        intensity = (value / thresh) * 100
        redAmt = 255
        greenAmt = int(intensity * 1.5)
        color.rgb(redAmt, greenAmt, 0)
    else
        intensity = math.min(100, ((value - thresh) / (100 - thresh)) * 100)
        redAmt = int(255 - (intensity * 2.55))
        greenAmt = 255
        color.rgb(redAmt, greenAmt, 0)

lineColor = getGradientColor(perFinal, thresholdFinal)

lowerZoneFill = plot(thresholdFinal, "Threshold", color=color.new(color.gray, 100), display=display.none)
bottomBound = plot(0, "Bottom", color=color.new(color.red, 100), display=display.none)
fill(lowerZoneFill, bottomBound, color=color.new(color.red, 93), title="Ranging Zone")

upperZoneFill = plot(thresholdFinal, "Threshold Upper", color=color.new(color.gray, 100), display=display.none)
topBound = plot(100, "Top", color=color.new(color.green, 100), display=display.none)
fill(upperZoneFill, topBound, color=color.new(color.green, 93), title="Trending Zone")

plot(thresholdFinal, "Efficiency Threshold", color=color.new(color.white, 20), linewidth=2, style=plot.style_line)

hline(50, "Reference", color=color.new(color.gray, 80), linestyle=hline.style_dotted)

plot(perFinal, "PER", color=lineColor, linewidth=3)

// INFO 
if showInfoBox and barstate.islast
    var table infoTable = table.new(position.top_right, 1, 4, 
         border_width=2, 
         border_color=color.new(color.gray, 30),
         frame_color=color.new(color.gray, 30),
         frame_width=1)
    
    marketState = perFinal >= thresholdFinal ? "Trending" : "Ranging"
    
    stateColor = perFinal >= thresholdFinal ? color.new(color.green, 0) : color.new(color.red, 0)
    
    strategy = perFinal >= thresholdFinal ? "Trend Following" : "Mean Reversion"
    
    table.cell(infoTable, 0, 0, "Price Efficiency Ratio", 
               text_color=color.white, 
               bgcolor=color.new(color.blue, 60))
    
    table.cell(infoTable, 0, 1, str.tostring(perFinal, "#.##") + "%", 
               text_color=lineColor, 
               bgcolor=color.new(#829de9, 40))
    
    table.cell(infoTable, 0, 2, marketState + " | " + strategy, 
               text_color=color.white, 
               bgcolor=stateColor)
    
    thresholdInfo = zoneType + " Threshold: " + str.tostring(thresholdFinal, "#.#")
    if useVolumeWeight
        thresholdInfo := thresholdInfo + " | Vol-Weighted"
    
    table.cell(infoTable, 0, 3, thresholdInfo, 
               text_color=color.new(color.white, 30), 
               bgcolor=color.new(color.black, 40),
               text_size=size.small)

Overview

An optional volume weight and a simple moving average can smooth or reweight the reading. A fixed level or a rolling percentile sets the threshold that separates a red ranging zone from a green trending zone. The line, threshold, and optional info table appear in a separate pane. It does not generate trade entries or exits.

Details

Published by

eddiebelaval on GitHub

Code credit

SharpStrat, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
Lookback Periodint30length
Enable SmoothingbooltrueenableSmoothing
Smoothing Periodint20smoothing
Volume-Weighted PERboolfalseuseVolumeWeight
Threshold TypestringDynamiczoneType
Efficiency Threshold (Fixed)float25.0threshold
Dynamic Threshold Lookbackint252thresholdLookback
Dynamic Threshold Percentileint40dynamicPercentile
Show Info BoxbooltrueshowInfoBox
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

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 10 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers