TradingView indicator guide

Andean Oscillator indicator: formula and calculation checks

The Andean Oscillator is a price indicator created by Alex Pierrefeu, known as alexgrover on TradingView. It uses exponential envelopes of prices and squared prices to calculate Bull and Bear components, then smooths the larger component into a signal line. The names describe directional price variation. They do not identify buyer-initiated or seller-initiated trades. Use the calculation table below to check a script before assigning trading rules to its crossings.

Draft an Andean calculation

Read the components with their original attribution

Pierrefeu published the method on Alpaca and as the Andean Oscillator under alexgrover on TradingView. In the original interpretation, Bull above Bear indicates bullish dominance; Bear above Bull indicates bearish dominance. The signal line provides another comparison for the dominant component. These are readings of the indicator, not promises about the next price move.

  • A crossing is an event: the ordering changes between two observations. Bull remaining above Bear for ten bars is a persistent state, not ten new crossings.
  • Compare a script with the original author and formula, not its title alone. Added normalization, alternative inputs or a different signal smoother change the comparison.

Calculate four envelopes, then three output lines

Let O and C be open and close, n the envelope length, m the signal length, a = 2/(n + 1), and b = 2/(m + 1). A suffix p means the previous bar. U and D are upper and lower price states; U2 and D2 track squared prices. The equations follow the code in the Alpaca publication.

  • Use the lower states for Bull and the upper states for Bear. The TradingView description reverses these labels in its details paragraph; the published code resolves the discrepancy.
  • Dimensional check: squared-price terms produce price-squared differences; their square roots return price units. Doubling every positive price and the matching seeds doubles all three outputs. Raw values therefore have no universal percentage interpretation.
  • There is no volume, bid/ask or trade-direction input in these equations. An order-flow interpretation would require additional data and a different calculation.
State or outputUpdate
Upper price Umax(O, C, (1 − a) × Up + a × C)
Upper squared price U2max(O², C², (1 − a) × U2p + a × C²)
Lower price Dmin(O, C, (1 − a) × Dp + a × C)
Lower squared price D2min(O², C², (1 − a) × D2p + a × C²)
Bull√(D2 − D²)
Bear√(U2 − U²)
Signal S(1 − b) × Sp + b × max(Bull, Bear)

Reproduce a four-bar example

This hypothetical fixture uses n = m = 3, giving a = b = 0.5. Before A, set U = D = 100, U2 = D2 = 10000 and S = 0. Each listed bar has open equal to close; these are deliberate gaps between bars, not a continuous real-market series. Keep full precision during calculation and round only the displayed results.

  • At A, the lower squared state is (10000 + 10404)/2 = 10202. Bull = √(10202 − 101²) = 1. Upper states reset to the current price and its square, so Bear = 0.
  • At B, Bull = √(10509 − 102.5²) = √2.75. At C, Bear = √(10408 − 102²) = 2. These checks catch swapped component labels.
  • At D, close is unchanged but Bear remains √3. The retained upper states still contain earlier prices. An unchanged close does not force the oscillator to zero.
  • Open-price counterexample: change only A open from 102 to 100. D becomes 100 and D2 becomes 10000, making Bull zero. A close-only replica would incorrectly keep Bull at 1.
Bar / O = CU / U2D / D2Bull / BearSignal
A / 102102 / 10404101 / 102021 / 00.500000
B / 104104 / 10816102.5 / 105091.658312 / 01.079156
C / 100102 / 10408100 / 100000 / 21.539578
D / 100101 / 10204100 / 100000 / 1.7320511.635814

Make initialization and numerical limits explicit

Our fixture supplies a prior state, so it does not depend on a platform warm-up rule. The publication initializes the envelope states from the first close and its square. Its Python example seeds the signal with the first close; its Pine example applies an EMA to the larger component. Check the seed when comparing early values across implementations.

  • A negative-price counterexample is O = C = −2 after states U = D = −1 and U2 = D2 = 1, with a = 0.5. D = −2 and D2 = 2.5, so D2 − D² = −1.5. The usual real square root is undefined.
  • Subtracting two large, nearly equal values can also produce a tiny negative radicand from rounding. Log the raw states and magnitude first. A documented tolerance may address rounding; blindly replacing every negative result with zero hides invalid inputs or state errors.
Boundary testExpected diagnostic
Constant positive O = C with matching price seedsBoth components stay zero. A nonzero signal seed decays rather than immediately disappearing.
n = 1 and positive pricesa = 1. Each paired envelope becomes a matching price and square; both components collapse to zero.
m = 1Signal equals the larger component on each valid bar. That component cannot be strictly above its own signal.
Different signal seed, identical component inputsThe signal difference after k updates is (1 − b)^k times the initial difference.
Negative prices or synthetic spreadsSquaring no longer preserves price ordering. Check the radicands before taking square roots.

Compare completed TradingView bars

Record the symbol, feed, session, timeframe, candle type, lengths and amount of loaded history. At matching timestamps, compare open and close, then U, U2, D and D2, then the components and signal. Diagnose the first differing stage before changing colors or alert rules.

  • TradingView indicators update while a realtime bar develops. Its changing close can change the components and erase a temporary crossing. Use completed bars for the numerical comparison; barstate.isconfirmed identifies historical bars and the closing update of a realtime bar.
  • Keep smoothing calculations running consistently on each bar. Specify separately whether a plot or alert exposes the developing value or waits for confirmation.
  • For a Bull-over-Bear alert, write down the equality rule, previous-bar comparison and closing-time requirement. If testing trades, add order timing, exits, sizing, commission and slippage before interpreting any result.

Turn the checks into a Pineify coding request

Ask the Pine Script AI Coding Agent to draft or explain an implementation with the declared inputs and initialization. Include the four-bar fixture and request diagnostic outputs for all envelope states. Retain the original author attribution and review any code reuse under its applicable terms.

  • Specify open and close, positive-price scope, both lengths, the exact signal seed and a completed-bar alert policy.
  • Require the A-to-D outputs above, the changed-open counterexample, and a visible diagnostic for materially negative radicands.
  • Review generated code and validate its syntax, then compare numerical values in TradingView. Syntax success alone does not prove formula parity or profitable trading rules.
Where Pineify fits

Pine Script AI Coding Agent

Draft or inspect an Andean Oscillator specification with explicit seeds, confirmation timing and intermediate values for verification.

Draft an Andean calculation

Frequently asked questions

Educational information, not investment advice. All numerical examples are hypothetical calculation checks, not backtests. Indicator readings do not guarantee a price move or trading returns.

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.