stock market

How to Calculate Pivot Points in Python

Spread the love

Pivot point is a leading indicator used to assess directional movement of an asset and potential support and resistance level .

  • it is calculated using the previous day’s high , low and close prices .
  • traders use pivot points to predict where price may reverse or breakout .
  • pivot point work well in intraday trading because they give a quick view of market sentiment .

How to calculate pivot points.

then we calculate supports and resistance levels.

How to trade using pivot points

1. Range trading strategy
  • if price approaches support s1 or s2 , look for bullish candlesticks signals (pin bar , hammer) , go for buy .
  • if price approaches first resistance or second resistance , look for bearish candlestick signals (shooting star ) , go for sell .
2.Breakout strategy
  • if price breaks above resistance1 with strong volume , it may continue to second resistance and third resistance , go for long .
  • if price breaks below first support with strong volume , it may continue to second support and third support , go for short .
3. How to Implement pivot point using python

Explanation of above code

  • Defines a function called levels which takes ohlc_day as input.
  • df is expected to be a dataset (like a dictionary or DataFrame) containing "high", "low", and "close" prices.
  • The docstring tells us the purpose: it returns pivot point and support/resistance levels.
  • Gets the last high price ([-1] means last value in the list/series).
  • Rounds it to 2 decimal places.
BL Tune 510BT, On Ear Wireless Headphones with Mic, up to 40 Hours Playtime
Amazon

Pure Bass, Quick Charging, Dual Pairing, Bluetooth 5.0


We earn a commission if you make a purchase, at no additional cost to you.
  • Gets the last low price, rounded to 2 decimals.
  • Gets the last closing price, rounded to 2 decimals.
  • Calculates the pivot point.
  • Formula: (High + Low + Close) / 3
  • Pivot is the central reference price for next day’s trading.
  • Resistance 1 (R1) level.
  • Formula: 2*Pivot - Low
  • First level where price might face resistance if it goes up.
  • Resistance 2 (R2) level.
  • Formula: Pivot + (High - Low)
  • Second, stronger resistance level.
  • Resistance 3 (R3) level.
  • Formula: High + 2*(Pivot - Low)
  • Strongest resistance level.
  • Support 1 (S1) level.
  • Formula: 2*Pivot - High
  • First support level (price may stop falling here).
  • Support 2 (S2) level.
  • Formula: Pivot - (High - Low)
  • Second support level.
  • Support 3 (S3) level.
  • Formula: Low - 2*(High - Pivot)
  • Strongest support level.

Returns all calculated levels as a tuple.

Output looks like:
(Pivot, R1, R2, R3, S1, S2, S3)

Leave a Reply

Your email address will not be published. Required fields are marked *