Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-tom-demark-pivots

$ Pinescript Tom DeMark Pivots

Master this unique pivot point system in TradingView's Pinescript, known for identifying precise potential turning points and trend exhaustion based on specific price relationships.

500+ Clients Helped
100% Satisfaction
Live Trading Ready
⚠️
Trading financial markets carries risk. All content (PineScript code, indicators, strategies) on this website is for educational purposes only. Past performance is not indicative of future results. By using any code or information from this site, you agree that you are solely responsible for your trading decisions. The author disclaims all liability for any losses incurred. To gain from experts experiences, You can always try our Invite Only Scripts
01

What are Tom DeMark Pivots?

Tom DeMark Pivots, often referred to as TD Pivots or DeMark Points, are a distinct set of support and resistance levels that aim to predict price reversals. Unlike traditional pivot points (Classic, Woodie, Camarilla) that use a fixed formula for their central pivot, DeMark's methodology employs a conditional approach based on the relationship between the previous period's open, high, low, and close. This makes DeMark Pivots highly adaptive and often results in levels that are more precise and dynamic, frequently indicating potential turning points with higher accuracy.

The core philosophy of DeMark Pivots is that price tends to find support or resistance at specific levels derived from previous price action, especially in relation to where the market closed relative to its open and high/low. These pivots are not just static levels but are signals for potential reversals or exhaustion points.

DeMark Pivots typically consist of a calculated "X" value which forms the basis for the central pivot (referred to as "TD Price Flip") and subsequent support (S1, S2) and resistance (R1, R2) levels. They are primarily used by traders to:

  • Identify precise turning points: DeMark levels are often seen as more predictive of exact reversal zones.
  • Anticipate trend exhaustion: Price reaching certain DeMark levels might signal that the current trend is overextended.
  • Set entry and exit points: Providing clear, actionable levels for trades.
02

Components and Calculation (Tom DeMark Pivots)

The calculation of Tom DeMark Pivots is highly conditional. It starts by determining an intermediate value, "X", based on the comparison of the previous period's closing price (`C`) to its opening price (`O`) and high (`H`) or low (`L`).


Let `H`, `L`, `C`, `O` be the previous period's High, Low, Close, and Open.
  1. Calculate 'X': This is the core difference in DeMark's methodology.
    • If `C < O` (previous close was lower than previous open): `X = H + (L * 2) + C`
    • If `C > O` (previous close was higher than previous open): `X = (H * 2) + L + C`
    • If `C == O` (previous close was equal to previous open): `X = H + L + (C * 2)`
  2. Central Pivot (TD Price Flip or Setup Reference Point):
    `PP = X / 4`
  3. First Resistance (R1):
    `R1 = X / 2 - L`
  4. First Support (S1):
    `S1 = X / 2 - H`
  5. Second Resistance (R2):
    `R2 = PP + (R1 - S1)` (This is less common, DeMark usually focuses on R1, S1 and the PP as primary levels)
  6. Second Support (S2):
    `S2 = PP - (R1 - S1)`
03

Basic Tom DeMark Pivots Implementation in Pinescript

pine-script@terminal
//@version=5
indicator("My Tom DeMark Pivots", overlay=true, max_bars_back=500) // overlay=true to plot on price chart.

// Input for the Pivot Point calculation timeframe
// DeMark pivots are predominantly used for intraday trading, so "D" (Daily) is most common.
pivotTimeframe = input.string("D", title="Pivot Timeframe", options=["D", "W", "M"])

// Get the Pivot Points values using ta.pivotpoints() with "Demark" type
// This function returns a tuple: [pp, r1, r2, r3, s1, s2, s3]
[pp, r1, r2, r3, s1, s2, s3] = ta.pivotpoints("Demark", pivotTimeframe, high, low, close, 1, open) // Pass 'open' as well

// Plotting the DeMark Levels
plot(pp, title="TD Price Flip", color=color.purple, linewidth=2, style=plot.style_stepline)
plot(r1, title="TD Resistance 1", color=color.red, linewidth=1, style=plot.style_stepline)
plot(s1, title="TD Support 1", color=color.green, linewidth=1, style=plot.style_stepline)
// For DeMark, R2/R3 and S2/S3 are less commonly focused on or directly derived.
plot(r2, title="TD Resistance 2", color=color.red, linewidth=1, style=plot.style_stepline)
plot(r3, title="TD Resistance 3", color=color.new(color.red, 50), linewidth=1, style=plot.style_stepline) // Lighter for less focus
plot(s2, title="TD Support 2", color=color.green, linewidth=1, style=plot.style_stepline)
plot(s3, title="TD Support 3", color=color.new(color.green, 50), linewidth=1, style=plot.style_stepline) // Lighter for less focus

// Optional: Add labels to the pivot lines for clarity (only on the first bar of a new period)
var label pp_label = na
var label r1_label = na
var label r2_label = na
var label r3_label = na
var label s1_label = na
var label s2_label = na
var label s3_label = na

// Check if it's the first bar of the new period (e.g., new day)
isNewPeriod = ta.change(time(pivotTimeframe))

if isNewPeriod
    label.delete(pp_label)
    label.delete(r1_label)
    label.delete(r2_label)
    label.delete(r3_label)
    label.delete(s1_label)
    label.delete(s2_label)
    label.delete(s3_label)

    pp_label := label.new(bar_index, pp, text="TD PP", style=label.style_label_left, color=color.new(color.purple, 70), textcolor=color.white)
    r1_label := label.new(bar_index, r1, text="TD R1", style=label.style_label_left, color=color.new(color.red, 70), textcolor=color.white)
    s1_label := label.new(bar_index, s1, text="TD S1", style=label.style_label_left, color=color.new(color.green, 70), textcolor=color.white)

    // Only plot labels for R2/R3/S2/S3 if they are meaningfully calculated (not NA)
    if not na(r2)
        r2_label := label.new(bar_index, r2, text="TD R2", style=label.style_label_left, color=color.new(color.red, 80), textcolor=color.white)
    if not na(r3)
        r3_label := label.new(bar_index, r3, text="TD R3", style=label.style_label_left, color=color.new(color.red, 90), textcolor=color.white)
    if not na(s2)
        s2_label := label.new(bar_index, s2, text="TD S2", style=label.style_label_left, color=color.new(color.green, 80), textcolor=color.white)
    if not na(s3)
        s3_label := label.new(bar_index, s3, text="TD S3", style=label.style_label_left, color=color.new(color.green, 90), textcolor=color.white)

// Extend labels horizontally
label.set_x(pp_label, bar_index)
label.set_x(r1_label, bar_index)
label.set_x(r2_label, bar_index)
label.set_x(r3_label, bar_index)
label.set_x(s1_label, bar_index)
label.set_x(s2_label, bar_index)
label.set_x(s3_label, bar_index)
$ ✓ Compiled successfully
04

Predictive Edge

Predictive Edge

DeMark Pivots are known for their conditional calculation, which can make them more predictive of exact turning points and trend exhaustion than other static pivot methods.

05

Practical Tom DeMark Pivots Trading Strategies

06

1. Reversal Trading at TD S1/R1

pine-script@terminal
//@version=5
strategy("TD Pivots Reversal Strategy", overlay=true)

pivotTimeframe = input.string("D", title="Pivot Timeframe", options=["D", "W", "M"])
[pp, r1, r2, r3, s1, s2, s3] = ta.pivotpoints("Demark", pivotTimeframe, high, low, close, 1, open)

// Plotting (simplified for strategy example)
plot(r1, title="TD R1", color=color.red, linewidth=1, style=plot.style_stepline)
plot(s1, title="TD S1", color=color.green, linewidth=1, style=plot.style_stepline)

// Long entry: Price bounces from TD S1
longCondition = close > s1 and close[1] <= s1[1]

// Short entry: Price rejects from TD R1
shortCondition = close < r1 and close[1] >= r1[1]

if (longCondition)
    strategy.entry("Long TD S1", strategy.long)

if (shortCondition)
    strategy.entry("Short TD R1", strategy.short)

// Basic exit: fixed profit/loss or target PP
profitTargetFactor = input.float(0.5, title="Profit Target (Ratio to S/R)", minval=0.1, maxval=1.0, step=0.1)
stopLossFactor = input.float(0.5, title="Stop Loss (Ratio to S/R)", minval=0.1, maxval=1.0, step=0.1)

// Calculate dynamic profit/stop targets
longProfitTarget = pp
longStopLoss = s2
shortProfitTarget = pp
shortStopLoss = r2

strategy.exit("Long TD S1 Exit", from_entry="Long TD S1", profit=longProfitTarget, stop=longStopLoss)
strategy.exit("Short TD R1 Exit", from_entry="Short TD R1", profit=shortProfitTarget, stop=shortStopLoss)
$ ✓ Compiled successfully
07

2. Trend Continuation / Breakout (Beyond R1 or S1)

pine-script@terminal
//@version=5
strategy("TD Pivots Breakout Strategy", overlay=true)

pivotTimeframe = input.string("D", title="Pivot Timeframe", options=["D", "W", "M"])
[pp, r1, r2, r3, s1, s2, s3] = ta.pivotpoints("Demark", pivotTimeframe, high, low, close, 1, open)

// Plotting (simplified for strategy example)
plot(r1, title="TD R1", color=color.red, linewidth=1, style=plot.style_stepline)
plot(s1, title="TD S1", color=color.green, linewidth=1, style=plot.style_stepline)

// Breakout logic: Price closes decisively above/below R1 or S1
longBreakoutCondition = close > r1 and close[1] <= r1[1]
shortBreakoutCondition = close < s1 and close[1] >= s1[1]

// Optional: Add volume confirmation for breakouts
volumeFactor = input.float(1.5, title="Volume Confirmation Factor", minval=1.0, step=0.1)
avgVolume = ta.sma(volume, 20) // Simple average volume for comparison
isHighVolume = volume > avgVolume * volumeFactor

if (longBreakoutCondition and isHighVolume)
    strategy.entry("Long TD R1 Breakout", strategy.long)

if (shortBreakoutCondition and isHighVolume)
    strategy.entry("Short TD S1 Breakout", strategy.short)

// Exit: Fixed profit/loss or target next potential levels (e.g., R2/S2 if valid)
atrLength = input.int(14, title="ATR Length for Exits", minval=1)
atrValue = ta.atr(atrLength)
profitMultiplier = input.float(1.5, title="Profit Target (ATR)", minval=0.5, step=0.1)
stopLossMultiplier = input.float(0.75, title="Stop Loss (ATR)", minval=0.1, step=0.1)

strategy.exit("Long TD R1 Breakout Exit", from_entry="Long TD R1 Breakout",
             profit=strategy.position_avg_price + atrValue * profitMultiplier,
             stop=strategy.position_avg_price - atrValue * stopLossMultiplier)

strategy.exit("Short TD S1 Breakout Exit", from_entry="Short TD S1 Breakout",
             profit=strategy.position_avg_price - atrValue * profitMultiplier,
             stop=strategy.position_avg_price + atrValue * stopLossMultiplier)
$ ✓ Compiled successfully
08

3. TD Price Flip as Trend Gauge

pine-script@terminal
//@version=5
indicator("TD Price Flip Trend Gauge", overlay=true)

pivotTimeframe = input.string("D", title="Pivot Timeframe", options=["D", "W", "M"])
[pp, r1, r2, r3, s1, s2, s3] = ta.pivotpoints("Demark", pivotTimeframe, high, low, close, 1, open)

// Plotting (simplified for trend gauge example)
plot(pp, title="TD Price Flip", color=color.purple, linewidth=2, style=plot.style_stepline)

// Determine intraday bias based on price relative to TD Price Flip
isBullishBias = close > pp
isBearishBias = close < pp

// Color background to easily visualize bias
bgcolor(isBullishBias ? color.new(color.teal, 95) : na, title="Bullish TD Bias")
bgcolor(isBearishBias ? color.new(color.maroon, 95) : na, title="Bearish TD Bias")

// Plot arrows on price crossing PP to show bias shift
plotarrow(ta.crossover(close, pp) ? close : na, title="Bias Shift Up", colorarrow=color.new(color.aqua, 0), style=plot.style_circles, offset=-bar_index+bar_index[1])
plotarrow(ta.crossunder(close, pp) ? close : na, title="Bias Shift Down", colorarrow=color.new(color.orange, 0), style=plot.style_circles, offset=-bar_index+bar_index[1])
$ ✓ Compiled successfully
09

Optimizing Tom DeMark Pivots Performance

To get the most from Tom DeMark Pivots in Pinescript:

  • Timeframe Alignment: DeMark Pivots are most effective for intraday trading or short-term swing trading. Using them on daily or weekly charts might provide less relevant signals as their precision on smaller timeframes is key. Ensure your chart timeframe is lower (e.g., 5-min, 15-min, 1-hour) than the pivot calculation timeframe (typically "D").
  • Confirmation is Paramount: DeMark levels offer potential turning points, but always seek confirmation. This could be from:
    • Candlestick patterns: Bullish/bearish reversal patterns forming at the levels.
    • Volume: Increased volume on a breakout or rejection.
    • Other indicators: Confluence with momentum oscillators (RSI, Stochastic) or trend indicators (Moving Averages).
  • Price Action Interaction: Observe how price reacts to the DeMark levels. Does it stall, consolidate, or reverse? Is it a quick spike and retreat, or a sustained breakout?
  • Context Matters: Understand the broader market trend. In a strong uptrend, bullish signals at S1 are higher probability than bearish signals at R1.
  • Adaptive Nature: Recognize that the "X" value, and thus the levels, adjust dynamically based on the previous bar's open/close relationship. This is a strength but means the levels are not as static as Classic Pivots.
10

Dynamic Precision

Dynamic Precision

DeMark Pivots adjust their calculation based on the prior bar's open-close relationship, offering a dynamic and often more precise identification of potential turning points.

11

Common Tom DeMark Pivots Pitfalls

  • Complexity: The conditional calculation of DeMark Pivots can be more complex to grasp initially compared to simpler pivot methods.
  • False Signals/Whipsaws: Like any indicator, DeMark Pivots can generate false signals in choppy or non-trending markets, or during periods of high volatility.
  • Over-Reliance: Using DeMark Pivots as the sole decision-making tool without additional confirmation can lead to significant losses. They are best used as part of a comprehensive strategy.
  • Gap Risk: Large overnight gaps can cause the current day's trading to occur far away from the calculated DeMark levels, making them less immediately relevant.
  • Limited Levels: While TD Price Flip, R1, and S1 are primary, higher R2/S2/R3/S3 levels might not always be consistently generated or as reliable as in other pivot systems.
12

Conclusion

Conclusion

Tom DeMark Pivots are a sophisticated and highly dynamic set of potential support and resistance levels available in Pinescript for TradingView. By employing a unique conditional calculation based on the previous period's price relationships, they aim to provide more precise and often more predictive turning points than traditional pivot systems. While requiring a deeper understanding of their underlying logic and diligent confirmation from other technical analysis tools, mastering Tom DeMark Pivots can significantly enhance your Pinescript strategies. By understanding their calculation, applying them to appropriate timeframes, and integrating them strategically into your overall trading plan, you can leverage these powerful levels to improve your entry/exit timing and better capitalize on market opportunities, particularly in identifying potential trend reversals.

Enhance Your Trading

Get a high-performance Pinescript analysis tool for actionable market insights, designed for traders on the move.

This strategy runs in live mode on TradingView, helping you identify potential opportunities.

Get Pinescript Strategy