OPEN-SOURCE SCRIPT
S&R Zones + PSY Levels, Pivot & EMA by Lazyhacker

PSY · S&R Zones · Pivot & EMA
What This Script Does & Why It's One Indicator
This tool is purpose-built for Nifty and BankNifty intraday traders who need a single, clean overlay covering the five most critical price-context layers: psychological levels, dynamic support/resistance zones, previous day levels, EMAs, and pivot points. Each component is chosen because it answers a specific question at the same moment:
Having these on separate indicators produces cluttered, difficult-to-read charts and requires switching between settings panels. This script integrates them with a unified settings panel and consistent visual design.
How Each Component Works
S&R Zones (Dynamic, Auto-Flipping)
Uses ta.pivothigh() and ta.pivotlow() with a configurable lookback period to identify confirmed swing highs and lows. Each pivot is drawn as a price zone (a box) rather than a line, because price rarely reacts to exact levels — zones are more realistic. Two filters prevent noise:
Zones automatically flip when price closes through them: a broken support becomes resistance (turns red) and vice versa (turns green). Zones being actively tested turn gray.
🔢 PSY (Psychological) Levels
Draws equidistant horizontal bands at psychologically significant round numbers:
The anchor (Base Level) and number of levels above/below are fully configurable. Zone width for each level type is independently adjustable. These levels act as price magnets and are among the most reliable intraday reference points for Indian index derivatives.
📅 Previous Day High / Low / Close (PDH / PDL / PDC)
Fetches the prior session's high, low, and close using request.security() with high[1], low[1], close[1] — properly offset expressions that carry no lookahead bias. These three levels are widely watched by institutional and retail participants and often act as the first intraday support/resistance.
📈 EMA Stack (Chart + Higher Timeframe)
HTF data uses barmerge.gaps_off without lookahead_on to ensure values only step at each completed HTF bar with no future data leakage.
🌀 Fibonacci Intraday Levels
Tracks the session high and low within a configurable session window (default 09:15–15:30 IST) and draws two intraday Fibonacci retracement levels:
These update dynamically as the day's range expands. They are most useful for identifying pullback entry zones within a trending day.
🔵 Pivot Points
Calculates standard pivot point levels (P, R1–R5, S1–S5) using TradingView's built-in ta.pivot_point_levels(). Supports six calculation methods: Traditional, Fibonacci, Woodie, Classic, DM, and Camarilla. The anchor timeframe auto-selects based on chart timeframe (Daily pivots for intraday, Weekly for daily charts, etc.) but is manually overridable. Up to 5 historical pivot periods can be displayed simultaneously.
The pivot request.security() call uses timeframe.change() as the trigger — a safe offset pattern that prevents lookahead bias on historical bars.
How to Use
Notes
What This Script Does & Why It's One Indicator
This tool is purpose-built for Nifty and BankNifty intraday traders who need a single, clean overlay covering the five most critical price-context layers: psychological levels, dynamic support/resistance zones, previous day levels, EMAs, and pivot points. Each component is chosen because it answers a specific question at the same moment:
- Where are the big round-number magnets? → PSY Levels
- Where has price historically reversed and is that zone still valid? → S&R Zones
- What are the key reference prices from yesterday? → PDH / PDL / PDC
- What is the current momentum structure? → EMA stack
- What are the mathematically derived support/resistance targets for today? → Pivot Points + Fibonacci
Having these on separate indicators produces cluttered, difficult-to-read charts and requires switching between settings panels. This script integrates them with a unified settings panel and consistent visual design.
How Each Component Works
S&R Zones (Dynamic, Auto-Flipping)
Uses ta.pivothigh() and ta.pivotlow() with a configurable lookback period to identify confirmed swing highs and lows. Each pivot is drawn as a price zone (a box) rather than a line, because price rarely reacts to exact levels — zones are more realistic. Two filters prevent noise:
- Zone Width (%): merges nearby pivots so overlapping zones don't clutter the chart.
- Min Pivot Strength (%): requires the price to have moved a minimum % away from the pivot, ensuring only significant reversals qualify.
Zones automatically flip when price closes through them: a broken support becomes resistance (turns red) and vice versa (turns green). Zones being actively tested turn gray.
🔢 PSY (Psychological) Levels
Draws equidistant horizontal bands at psychologically significant round numbers:
- BankNifty: Major levels at every 500 points, minor at every 250 points.
- Nifty: Major levels at every 100 points, minor at every 50 points.
The anchor (Base Level) and number of levels above/below are fully configurable. Zone width for each level type is independently adjustable. These levels act as price magnets and are among the most reliable intraday reference points for Indian index derivatives.
📅 Previous Day High / Low / Close (PDH / PDL / PDC)
Fetches the prior session's high, low, and close using request.security() with high[1], low[1], close[1] — properly offset expressions that carry no lookahead bias. These three levels are widely watched by institutional and retail participants and often act as the first intraday support/resistance.
📈 EMA Stack (Chart + Higher Timeframe)
- Chart EMAs: Two EMAs computed directly on the current chart timeframe (default 9 and 15). Used for immediate momentum and crossover signals.
- HTF EMAs: Two EMAs computed on a higher timeframe (default 5-minute, configurable). These smooth out lower-timeframe noise and show the broader intraday trend direction. When price is above both HTF EMAs, the bias is long; below both, the bias is short.
HTF data uses barmerge.gaps_off without lookahead_on to ensure values only step at each completed HTF bar with no future data leakage.
🌀 Fibonacci Intraday Levels
Tracks the session high and low within a configurable session window (default 09:15–15:30 IST) and draws two intraday Fibonacci retracement levels:
- 50%: The midpoint of the day's range — a natural mean-reversion target.
- 61.8%: The golden ratio retracement — the most widely respected Fibonacci level.
These update dynamically as the day's range expands. They are most useful for identifying pullback entry zones within a trending day.
🔵 Pivot Points
Calculates standard pivot point levels (P, R1–R5, S1–S5) using TradingView's built-in ta.pivot_point_levels(). Supports six calculation methods: Traditional, Fibonacci, Woodie, Classic, DM, and Camarilla. The anchor timeframe auto-selects based on chart timeframe (Daily pivots for intraday, Weekly for daily charts, etc.) but is manually overridable. Up to 5 historical pivot periods can be displayed simultaneously.
The pivot request.security() call uses timeframe.change() as the trigger — a safe offset pattern that prevents lookahead bias on historical bars.
How to Use
- Set your instrument (Nifty or BankNifty) and PSY anchor base level to match current market price range.
- On a 1–5 minute chart, all five components will activate with sensible defaults.
- Use PSY levels + Pivots as your primary S/R map for the session.
- Use S&R Zones to identify zones with historical significance and watch for flip behavior.
- Use PDH/PDL/PDC as the first intraday breakout or rejection reference.
- Use EMA stack for momentum bias — enter in the direction the chart EMAs are sloping when price is on the correct side of HTF EMAs.
- Use Fibonacci levels for intraday pullback targets once the day's range is established (typically after the first 30–60 minutes).
Notes
- Designed primarily for NSE index derivatives (Nifty, BankNifty) on intraday timeframes (1m–15m).
- All components are independently toggleable.
- No repainting: S&R zones are drawn at confirmed pivot bars (lookback bars in the past); Fibonacci and EMAs are real-time but non-predictive; pivot levels use closed HTF bars only.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.