TradingView indicator calculations

Polarized Fractal Efficiency: formula and direction

Polarized Fractal Efficiency (PFE) compares the straight-line distance between two prices with the length of the intervening price path, then assigns a direction sign and usually applies smoothing. Under the convention below, rising endpoints give a positive raw value and falling endpoints give a negative one. The reading describes the observed path; it does not predict a reversal or establish a profitable entry.

See the decision guide

A geometric formula with explicit conventions

TradeStation describes PFE as a Pythagorean comparison of straight-line and traveled distances, and exposes an adjusted-length option. To make the arithmetic reproducible, this page uses n equally spaced bar intervals, with closes p[0] through p[n] ordered oldest to newest. Each horizontal interval is one unit; prices retain their quoted units. Use integer n ≥ 2. This is a stated geometric implementation, not a claim that every platform uses identical indexing.

  • For smoothing length m ≥ 1, seed E with the first valid R. With m = 1, E equals R. Do not round intermediate calculations.
  • Wait for n + 1 consecutive valid closes. A missing price invalidates the window; resume with a new seed after a complete valid window. This reset policy is part of the example and must be matched when comparing scripts.
  • L is at least n, so a valid flat window does not divide by zero. The triangle inequality gives S ≤ L and therefore |R| ≤ 100 under this matching-window formula.
  • Equal endpoints return zero by the explicit sign rule, even though S/L remains positive. A script that assigns ties to its negative branch will disagree.
QuantityDefinition
Endpoint change Δp[n] − p[0]
Straight distance Ssqrt(Δ² + n²)
Traveled distance LΣ sqrt((p[i] − p[i−1])² + 1), for i = 1 through n
Raw signed PFE R100 × sign(Δ) × S / L, with sign(0) = 0
Smoothed PFE Eα × R + (1 − α) × previous E; α = 2 / (m + 1)

Compare a straight path with a zigzag path

These hypothetical five-close samples use n = 4 and no smoothing. The rising and zigzag paths both start at 100 and end at 104, so both have S = sqrt(4² + 4²) = 5.656854. Their traveled distances differ. A constant-slope rise has L = 4 × sqrt(2); the zigzag has L = 3 × sqrt(17) + 1.

  • The zigzag result is 100 × 5.656854249 / 13.369316877 = 42.312216. Its positive sign says the final close is higher, despite two different paths having the same net gain.
  • Reflecting the straight rise into a straight fall preserves both lengths and reverses the sign. The sign comes from the endpoints, not the most recent one-bar move.
  • The round trip and fully flat path both return zero here. Zero alone cannot distinguish active oscillation from no price movement; inspect the underlying closes.
  • Any constant nonzero slope reaches an absolute raw value of 100, even if its total price change is tiny. Efficiency is not the size of a tradeable move.
Closes, oldest firstSLRaw PFE
100, 101, 102, 103, 1045.6568545.656854+100.000000
100, 104, 100, 104, 1045.65685413.369317+42.312216
104, 103, 102, 101, 1005.6568545.656854−100.000000
100, 104, 100, 104, 1004.00000016.4924230.000000
100, 100, 100, 100, 1004.0000004.0000000.000000

See the delay added by EMA smoothing

Use the hypothetical sequence 100, 101, 102, 103, 104, 103, 102, 101, 100. Keep n = 4, use m = 5 so α = 1/3, and seed the EMA at the first valid raw value of 100. The table follows each completed five-close window after the rise turns down.

  • At the close of 101, the raw window direction is negative while the smoothed line remains positive: (−79.056942)/3 + 2 × 62.012654/3 = 14.989455.
  • The EMA crosses below zero one observation after the raw PFE becomes negative in this sample. That delay is specific to these inputs and the seed; it is not a fixed one-bar property.
  • The rolling window itself already retains earlier prices. Increasing n changes that memory; increasing m adds more smoothing. Compare both parameters separately.
Current windowEndpoint changeRaw PFEEMA(5)
100, 101, 102, 103, 104+4+100.000000+100.000000
101, 102, 103, 104, 103+2+79.056942+93.018981
102, 103, 104, 103, 10200.000000+62.012654
103, 104, 103, 102, 101−2−79.056942+14.989455
104, 103, 102, 101, 100−4−100.000000−23.340363

Price scaling changes this geometric ratio

The formula combines price differences with a fixed horizontal step of one. Adding the same constant to every price preserves PFE, but multiplying prices by a positive factor generally changes its magnitude. A chart zoom does not change the input series; converting the numerical prices into different units does.

  • Compress the zigzag changes by a factor of 100 around 100: 100, 100.04, 100, 100.04, 100.04. Now S = 4.000200 and L = 4.002399, so raw PFE is +99.945057 instead of +42.312216.
  • The pattern still zigzags. Its vertical distances have become small relative to the fixed horizontal distances, so the ratio is close to one. A large magnitude is therefore not a universal measure of low market noise across instruments.
  • If a script normalizes by ticks, volatility or another scale, record that transformation and verify its zero-denominator behavior. Its thresholds are not directly interchangeable with the unscaled examples here.

PFE, Kaufman Efficiency Ratio and FDI answer different questions

Kaufman Efficiency Ratio compares absolute endpoint change with the sum of absolute adjacent price changes. It has no horizontal-distance term and no direction sign. KAMA then uses ER to control a moving average. A Fractal Dimension Index instead estimates path roughness under its chosen estimator; it is not this signed efficiency oscillator.

  • Multiplying all prices by the same positive factor leaves Kaufman ER unchanged when its denominator is positive. It does not generally leave this PFE unchanged.
  • For a flat window, the unguarded ER formula is 0/0. This PFE has L = n and returns zero by its tie rule. Initialization and flat-window policies must be specified independently.
MeasureStraight rising sampleZigzag sampleOutput meaning
Raw PFE defined here+100+42.312216Signed geometric efficiency, price-scale dependent
Kaufman ER4/4 = 14/12 = 1/3Unsigned price-change efficiency
KAMANeeds history and smoothing settingsNeeds history and smoothing settingsA moving average in price units
FDIDepends on estimator and windowDepends on estimator and windowAn estimated dimension, without a direction sign

Verify a TradingView implementation before setting alerts

TradingView hosts several community PFE implementations. HPotter publishes an open-source version, while capissimo explicitly describes a customized formula. TradeStation also distinguishes Length from an adjusted Length − 1 convention. Record the author, version and formula before expecting settings with the same label to produce the same plot.

  • Check the exact endpoint offset, number of path segments, horizontal distance, scale factor, sign comparison, tie branch and any rounding. For this page, all distances span the same n intervals.
  • Compare S, L, Δ, R and E against the fixtures before evaluating trading thresholds. Seed differences can persist through the EMA even after the rolling windows agree.
  • Use the same symbol, session, timeframe, price adjustments and chart type for market comparisons. A nonstandard chart may supply synthetic closes.
  • The current close changes during an open bar. For a confirmed zero-cross alert, require a valid previous E ≤ 0 and current E > 0 at the chart close, or the symmetric downward condition. Do not alert merely because E remains on one side.
  • Chart-bar confirmation does not confirm an unfinished higher-timeframe input. Audit requested data separately. Thresholds such as ±50 describe a rule to test, not an established reversal probability.

Turn the verified definition into a Pine specification

The Pine Script AI Coding Agent can draft code from a written specification. Provide the formula, n-interval indexing, tie handling, missing-data reset, EMA seed and the fixture tables above. Request separate diagnostic plots for raw and smoothed PFE, then ask for syntax checking and compare the values in TradingView before adding alerts.

  • Specify chart-close evaluation, no future bars and no visual offset. Keep raw direction and smoothed direction separately named so an alert cannot silently switch meanings.
  • Use the rise, zigzag, fall, equal-endpoint and scaled fixtures as acceptance cases. A syntax check cannot establish numerical agreement or profitable trading behavior.
  • This workflow implements a public calculation. It does not recover protected or invite-only indicator source code.
Where Pineify fits

Pine Script AI Coding Agent

Draft a PFE script from an explicit formula and test fixtures, then review its numerical output and confirmed-bar alerts in TradingView.

Draft a PFE calculation

Frequently asked questions

Educational calculations, not investment advice. All price paths are hypothetical. No live trading performance, predictive accuracy or numerical match to a particular community script is claimed.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.