TradingView indicator calculations

DeMarker indicator: calculate the ratio before reading the signal

The DeMarker indicator compares positive changes in adjacent bar highs with positive downward changes in adjacent bar lows. In the SMA version shown here, the smoothed high increase is divided by the sum of both smoothed changes. The result ranges from 0 to 1 when the denominator is positive. It is an oscillator, separate from the Setup and Countdown counts used by DeMARK Sequential.

Draft a DeMarker script

Calculate DeMax and DeMin independently

For each bar t, DeMax = max(high[t] − high[t−1], 0), and DeMin = max(low[t−1] − low[t], 0). Let U = SMA(DeMax, N) and D = SMA(DeMin, N). DeMarker = U / (U + D). This is the public SMA formulation documented by MetaQuotes. Both averages use the same N observations.

  • The changes are independent. An outside bar can contribute to both sides; do not keep only the larger change.
  • For complete equal-length SMA windows, the common division by N cancels. The ratio of the two sums gives the same result.
  • A reading of 0.7 means U is 70% of U + D. It is not a 70% chance of reversal.
Bar conditionDeMaxDeMin
Higher high, no lower lowPositive high increase0
Lower low, no higher high0Positive low decrease
Higher high and lower lowPositivePositive
High no higher; low no lower00

Reproduce a three-period calculation

The following highs and lows are hypothetical prices, not market data or a backtest. Set N = 3. Bar 0 supplies the previous high and low; the first full window contains changes from bars 1, 2 and 3.

  • At bar 3: U = (2 + 0 + 3) / 3 = 5/3; D = (0 + 2 + 1) / 3 = 1. DeMarker = 5 / (5 + 3) = 0.625, or 62.5 on a 0 to 100 scale.
  • At bar 4: the first change leaves the window. U = (0 + 3 + 0) / 3 = 1 and D = (2 + 1 + 0) / 3 = 1, so the ratio becomes 0.5. The current inside bar contributes no change, yet the oscillator moves.
  • Averaging the individual ratios from bars 1, 2 and 3 gives (1 + 0 + 0.75) / 3 = 0.5833. That is a different calculation from the required ratio of smoothed changes.
BarHighLowDeMaxDeMinThree-period DeMarker
010095UnavailableUnavailableUnavailable
11029620Warm-up
21019402Warm-up
310493310.625
410394000.500

Make the undefined cases visible

The ratio cannot distinguish the size of price changes after proportional scaling. Multiplying every DeMax and DeMin in the window by ten leaves the result unchanged. A high oscillator reading therefore does not measure how many price points the market moved or how much risk a position carries.

  • A zero denominator does not require flat prices. Starting from high/low 104/93, three successive inside bars 103/94, 102/95 and 101/96 produce three zero change pairs for N = 3.
  • Some implementations may carry the prior value or substitute 0.5. That is an added fallback convention; verify it before comparing charts.
  • Using EMA or RMA instead of SMA changes the history weights. The same length label does not make the values equivalent.
CaseMathematical resultPolicy in this example
U > 0 and D = 01Plot 1; do not divide U by D first.
U = 0 and D > 00Plot 0.
U = 0 and D = 00 / 0 is undefinedReturn na and leave a plot gap.
Fewer than N valid adjacent-bar pairsIncomplete windowReturn na until all N pairs are valid.

Inspect the calculation in Pine Script v6

This chart-timeframe indicator uses SMA, a 0 to 1 scale, and na for missing windows or zero denominators. The length input starts at 14 as an example setting; it is not an optimized parameter. Intermediate values appear in the Data Window. The line can update during the open bar, while the two alert conditions require a closed chart bar.

Educational calculation audit. Pine syntax validation passed; no strategy orders, higher-timeframe requests or performance claims are included.pine
//@version=6
indicator("DeMarker calculation audit", overlay=false, precision=4)
length = input.int(14, "SMA length", minval=1)
validPair = not na(high) and not na(low) and not na(high[1]) and not na(low[1])
deMax = validPair ? math.max(high - high[1], 0.0) : na
deMin = validPair ? math.max(low[1] - low, 0.0) : na
avgMax = ta.sma(deMax, length)
avgMin = ta.sma(deMin, length)
fullWindow = ta.sma(validPair ? 1.0 : 0.0, length) == 1.0
denominator = avgMax + avgMin
dem = fullWindow and denominator > 0.0 ? avgMax / denominator : na
plot(dem, "DeMarker (0 to 1)", color=color.blue, linewidth=2, style=plot.style_linebr)
hline(0.7, "Upper reference", color=color.gray)
hline(0.5, "Midpoint", color=color.gray, linestyle=hline.style_dotted)
hline(0.3, "Lower reference", color=color.gray)
plot(deMax, "DeMax", display=display.data_window)
plot(deMin, "DeMin", display=display.data_window)
plot(avgMax, "SMA DeMax", display=display.data_window)
plot(avgMin, "SMA DeMin", display=display.data_window)
crossAboveLower = ta.crossover(dem, 0.3)
crossBelowUpper = ta.crossunder(dem, 0.7)
alertcondition(barstate.isconfirmed and crossAboveLower, "Confirmed cross above 0.3", "DeMarker crossed above 0.3 on a closed chart bar.")
alertcondition(barstate.isconfirmed and crossBelowUpper, "Confirmed cross below 0.7", "DeMarker crossed below 0.7 on a closed chart bar.")

Verify the TradingView values before adding trading rules

Paste the script into Pine Editor, save it and add it to a standard candle chart. Compare a completed bar with the preceding N high/low changes using the Data Window. Record the symbol, session, timeframe and length so that another calculation uses the same observations.

  • Check a bar with both a higher high and a lower low, then an inside bar. The table above gives an arithmetic fixture for a separate test dataset; a live chart will have its own values.
  • Check the first valid result and any blank segment. Missing inputs should remain unavailable rather than becoming zero changes.
  • Compare decimal values before applying a 100-times display scale. If one chart shows 0.625 and another 62.5, inspect their scale labels first.
  • To use an alert, create it from the relevant confirmed-cross condition. Crossing back above 0.3 is an event; remaining above 0.3 is a state. The example implements the event.
  • An open bar can change its high or low and move the oscillator. The confirmed alert condition does not freeze the plotted line. Verify the close before treating a developing cross as final.

Separate DeMarker, RSI and DeMARK counting tools

Sharing an oscillator range or an author does not make indicators interchangeable. TradingView documents RSI with close as its default source and RMA smoothing. DeMARK describes its 9-13 product as a simplified form of Sequential and Combo, with Setup and Countdown phases.

  • The sample implements the public SMA formula described above. It does not claim to reproduce every proprietary DeMARK variant or the licensed 9-13 product.
  • A threshold can remain exceeded during a trend. Neither an extreme nor a return through a reference line supplies an exit, position size or expected return.
IndicatorInput or mechanismComparison boundary
This DeMarker implementationAdjacent highs and lows; SMA ratioClosing-price changes are not its inputs.
Standard close-based RSIPositive and negative close changes; RMA ratio scaled to 100Equal period lengths do not imply equal readings.
Sequential / Combo / DeMARK 9-13Setup and Countdown counting rulesA 9 or 13 count is not a DeMarker oscillator value.

Give Pineify the calculation and confirmation policy

Use the Pine Script AI Coding Agent to draft or explain changes to this specification. Include N, SMA smoothing, the plotted scale, the missing-window rule, the zero-denominator policy and the exact alert crossing. Ask for diagnostic plots so each intermediate value can be checked.

  • Keep indicator verification separate from strategy design. If you later add orders, specify entry execution, exits, position sizing, commissions and slippage.
  • Review generated code, validate its syntax and compare completed-bar values. A successful syntax check does not establish profitability or agreement with a differently defined indicator.
Where Pineify fits

Pine Script AI Coding Agent

Draft a DeMarker script with explicit inputs, missing-value behavior and confirmation rules, then verify its intermediate calculations.

Draft a DeMarker script

Frequently asked questions

Educational information, not investment advice. Prices and calculations are hypothetical. Indicator thresholds and syntax-valid code do not guarantee trading returns. This example is not an official DeMARK product.

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.