Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-pivot-points

$ Pine Script Pivot Points

Master this foundational indicator in TradingView's Pine Script that identifies key potential support, resistance, and reversal levels for intraday and swing trading strategies.

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 Pivot Points?

Pivot Points are significant levels derived from the high, low, and closing prices of a previous trading period (e.g., previous day, week, or month). Traders use these levels to predict potential support and resistance zones for the current or upcoming trading period. They are particularly popular among intraday traders for identifying key turning points or areas where price action might react.

The core idea is that these calculated levels represent a consensus of past price action, and therefore, they are likely to influence future price movements. When price approaches a pivot point, traders watch for either a bounce (support/resistance) or a breakout (continuation).

There are several types of Pivot Points (Classic, Fibonacci, Woodie, Camarilla, Demark), each with slightly different calculation formulas. However, the Classic Pivot Points are the most widely used and provide a solid foundation for understanding the concept.

In Pine Script, Pivot Points are a powerful tool for visualizing key price levels that can inform your pine script strategies for entries, exits, and risk management.

02

Components and Calculation (Classic Pivot Points)

Classic Pivot Points consist of a central Pivot Point (PP), three resistance levels (R1, R2, R3), and three support levels (S1, S2, S3). These are calculated using the previous period's (e.g., yesterday's) High, Low, and Close prices:

  1. Pivot Point (PP): The central point, considered the "fair value" or balance point for the current period.
    PP = (High[previous_period] + Low[previous_period] + Close[previous_period]) / 3
  2. First Resistance (R1):
    R1 = (2 * PP) - Low[previous_period]
  3. First Support (S1):
    S1 = (2 * PP) - High[previous_period]
  4. Second Resistance (R2):
    R2 = PP + (High[previous_period] - Low[previous_period])
    R2 = PP + (R1 - S1) (Alternative)
  5. Second Support (S2):
    S2 = PP - (High[previous_period] - Low[previous_period])
    S2 = PP - (R1 - S1) (Alternative)
  6. Third Resistance (R3):
    R3 = R1 + (High[previous_period] - Low[previous_period])
  7. Third Support (S3):
    S3 = S1 - (High[previous_period] - Low[previous_period])
03

Basic Pivot Points Implementation in Pine Script

pine-script@terminal
//@version=5
indicator("My Pivot Points", overlay=true, max_bars_back=500)

// Input for the Pivot Point calculation timeframe
pivotTimeframe = input.string("D", title="Pivot Timeframe", options=["D", "W", "M"])

// Input for the type of Pivot Points
pivotType = input.string("Classic", title="Pivot Type", options=["Classic", "Fibonacci", "Woodie", "Camarilla", "Demark"])

// Get the Pivot Points values using ta.pivotpoints()
[pp, r1, r2, r3, s1, s2, s3] = ta.pivotpoints(pivotType, pivotTimeframe, high, low, close, 1)

// Plotting the Pivot Points levels
plot(pp,   title="Pivot Point",    color=color.purple,   linewidth=2, style=plot.style_stepline)
plot(r1,   title="Resistance 1",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(r2,   title="Resistance 2",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(r3,   title="Resistance 3",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(s1,   title="Support 1",      color=color.green,    linewidth=1, style=plot.style_stepline)
plot(s2,   title="Support 2",      color=color.green,    linewidth=1, style=plot.style_stepline)
plot(s3,   title="Support 3",      color=color.green,    linewidth=1, style=plot.style_stepline)
$ ✓ Compiled successfully
04

Static Levels

Static Levels

Unlike moving averages, Pivot Points are static levels for the entire trading period, calculated based on the previous period's high, low, and close. This makes them predictable.

05

Practical Pivot Points Trading Strategies

1. Support and Resistance Trading (Reversals)

This is the most common use of Pivot Points. Traders look for price to react to these levels, either bouncing off them or failing to break through, signaling potential reversals.

  • Buy Signal: Price approaches or touches S1, S2, or S3 from above and shows bullish reversal patterns (e.g., hammer, engulfing, strong bounce).
  • Sell Signal: Price approaches or touches R1, R2, or R3 from below and shows bearish reversal patterns (e.g., shooting star, engulfing, strong rejection).
  • Pivot Point as Magnet: Price often gravitates towards the central Pivot Point (PP).
//@version=5
strategy("Pivot Point Reversal Strategy", overlay=true)

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

plot(pp,   title="Pivot Point",    color=color.purple,   linewidth=2, style=plot.style_stepline)
plot(r1,   title="Resistance 1",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(r2,   title="Resistance 2",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(r3,   title="Resistance 3",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(s1,   title="Support 1",      color=color.green,    linewidth=1, style=plot.style_stepline)
plot(s2,   title="Support 2",      color=color.green,    linewidth=1, style=plot.style_stepline)
plot(s3,   title="Support 3",      color=color.green,    linewidth=1, style=plot.style_stepline)

longCondition = close > s1 and close[1] <= s1[1]
shortCondition = close < r1 and close[1] >= r1[1]
isNewPeriod = ta.change(time(pivotTimeframe))

if (longCondition and not isNewPeriod)
    strategy.entry("Long Reversal S1", strategy.long)

if (shortCondition and not isNewPeriod)
    strategy.entry("Short Reversal R1", strategy.short)

strategy.exit("Long Reversal S1 Exit", from_entry="Long Reversal S1", profit=r1, stop=s2)
strategy.exit("Short Reversal R1 Exit", from_entry="Short Reversal R1", profit=s1, stop=r2)

2. Breakout Trading (Continuation)

If price decisively breaks through a pivot level with strong momentum and volume, it can signal a continuation of the trend towards the next pivot level.

  • Buy Signal: Price breaks above R1, R2, or R3 with strong bullish momentum.
  • Sell Signal: Price breaks below S1, S2, or S3 with strong bearish momentum.
  • False Breakouts: Be wary of price quickly reversing after a breakout.
//@version=5
strategy("Pivot Point Breakout Strategy", overlay=true)

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

plot(pp,   title="Pivot Point",    color=color.purple,   linewidth=2, style=plot.style_stepline)
plot(r1,   title="Resistance 1",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(r2,   title="Resistance 2",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(r3,   title="Resistance 3",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(s1,   title="Support 1",      color=color.green,    linewidth=1, style=plot.style_stepline)
plot(s2,   title="Support 2",      color=color.green,    linewidth=1, style=plot.style_stepline)
plot(s3,   title="Support 3",      color=color.green,    linewidth=1, style=plot.style_stepline)

longBreakoutCondition = close > r1 and close[1] <= r1[1] and volume > volume[1] * 1.5
shortBreakoutCondition = close < s1 and close[1] >= s1[1] and volume > volume[1] * 1.5

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

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

strategy.exit("Long Breakout R1 Exit", from_entry="Long Breakout R1", profit=r2, stop=pp)
strategy.exit("Short Breakout S1 Exit", from_entry="Short Breakout S1", profit=s2, stop=pp)

3. Trend Bias with Pivot Point (PP)

The central Pivot Point (PP) can act as an excellent indicator of the intraday trend bias.

  • Bullish Bias: If price consistently trades above the Pivot Point (PP), it suggests a bullish intraday bias.
  • Bearish Bias: If price consistently trades below the Pivot Point (PP), it suggests a bearish intraday bias.
  • Mid-Day Crossing: If price crosses the PP mid-day, it can signal a shift in the intraday bias.
//@version=5
indicator("Pivot Point Trend Bias", overlay=true)

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

plot(pp,   title="Pivot Point",    color=color.purple,   linewidth=2, style=plot.style_stepline)
plot(r1,   title="Resistance 1",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(r2,   title="Resistance 2",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(r3,   title="Resistance 3",   color=color.red,      linewidth=1, style=plot.style_stepline)
plot(s1,   title="Support 1",      color=color.green,    linewidth=1, style=plot.style_stepline)
plot(s2,   title="Support 2",      color=color.green,    linewidth=1, style=plot.style_stepline)
plot(s3,   title="Support 3",      color=color.green,    linewidth=1, style=plot.style_stepline)

isBullishBias = close > pp
isBearishBias = close < pp

bgcolor(isBullishBias ? color.new(color.teal, 95) : na, title="Bullish Intraday Bias")
bgcolor(isBearishBias ? color.new(color.maroon, 95) : na, title="Bearish Intraday Bias")
06

Optimizing Pivot Points Performance

To get the most from Pivot Points in Pine Script:

  • Timeframe Alignment: Ensure the pivot timeframe aligns with your trading style. Daily pivots are common for intraday trading, while weekly/monthly pivots are useful for swing trading.
  • Confirmation is Key: Combine Pivot Points with other indicators (candlestick patterns, volume, MACD, RSI) to confirm reversals or breakouts.
  • Market Open Reaction: Pay close attention to how price reacts to PP and R1/S1 levels at the market open.
  • Different Pivot Types: Experiment with different pivot calculation types (Fibonacci, Woodie, Camarilla) in `ta.pivotpoints()`.
  • Watch for Confluence: Pivot Points become more powerful when they align with moving averages, trendlines, or previous significant highs/lows.
07

Predictable Levels

Predictable Levels

Pivot Points are unique because they are fixed and known at the beginning of the trading period, allowing traders to plan their strategies in advance.

08

Common Pivot Points Pitfalls

  • Not Universal Support/Resistance: While often acting as support/resistance, Pivot Points are not guaranteed.
  • Trend vs. Range: Pivot Points work best in ranging or moderately trending markets.
  • Over-Reliance: Using Pivot Points as the sole decision-making tool is risky.
  • Lookback Period: Using the wrong pivot timeframe can lead to irrelevant levels.
  • False Breakouts: Price can frequently "fake out" by briefly breaking a pivot level only to reverse quickly.
  • Gaps: Large overnight gaps can make the initial Pivot Point levels less relevant.
09

Conclusion

Conclusion

Pivot Points are a foundational and highly valued technical indicator available in Pine Script for TradingView. By providing pre-calculated levels of potential support, resistance, and reversals, they offer traders a clear framework for navigating intraday and short-term price movements. While their primary strength lies in identifying these static levels, their true power is unlocked when combined with price action, volume analysis, and other confirming indicators. By understanding their calculation, thoughtfully selecting the appropriate timeframe and type, and integrating them strategically into your pine script strategies, you can leverage Pivot Points to enhance your decision-making, improve your entry/exit timing, and better manage risk in dynamic markets.

Enhance Your Trading

Get a high-performance Pine Script 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 Pine Script Strategy