OPEN-SOURCE SCRIPT
Nifty Hierarchical Macro Guard

Overview
The Nifty Hierarchical Macro Guard is a "Market Compass" indicator specifically designed for Indian equity traders. It locks its logic to the Nifty 50 Index (NSE:NIFTY) and applies a strict hierarchy of trend analysis. The goal is simple: prioritize the long-term trend (Monthly/Weekly) to decide if you should even be in the market, then use the short-term trend (Daily) for precise exit timing.
This script ensures you never ignore a macro "crash" signal while trying to trade minor daily fluctuations.
The Color Hierarchy (Priority Logic)
The indicator uses a "Top-Down" filter. Higher timeframe signals override lower timeframe signals:
Level 1: Monthly (Ultra-Macro) — Deep Maroon
Condition: Nifty 10 EMA is below the 20 EMA on the Monthly chart.
Action: This is the highest priority. The background will turn Deep Maroon, overriding all other colors. This is your "Forget Trading" signal. The long-term structural trend is broken.
Level 2: Weekly (Macro Warning) — Dark Red
Condition: Monthly is Bullish, but Nifty 10 EMA is below the 20 EMA on the Weekly chart.
Action: The background turns Dark Red. This indicates a significant macro correction. You should stay out of fresh positions and protect capital.
Level 3: Daily (Tactical) — Light Red / Light Green
Condition: Both Monthly and Weekly are Bullish (Green).
Action: The background will now react to the Daily 10/20 EMA cross.
Light Green: Nifty is healthy; safe for fresh positions.
Light Red: Tactical exit signal. Nifty is seeing short-term weakness; exit positions quickly.
Key Features
Symbol Locked: No matter what stock you are viewing (Reliance, HDFC, Midcaps), the background only reacts to NSE:NIFTY.
Clean Interface: No messy lines or labels on the price chart. The information is conveyed purely through background color shifts.
Customizable: Change the MA types (EMA/SMA) and lengths (e.g., 10/20 or 20/50) in the settings.
Macro Dashboard: A small, transparent table in the top-right corner displays exactly which timeframe is currently controlling the background color.
How to Use for Nifty Strategy
Stay Out: If the chart is Deep Maroon or Dark Red, do not look for "buying the dip." Wait for the macro health to return.
Take Exits: If the background is Light Green and suddenly turns Light Red, it means the Daily Daily 10/20 cross has happened. Exit your Nifty-sensitive positions immediately.
The Nifty Hierarchical Macro Guard is a "Market Compass" indicator specifically designed for Indian equity traders. It locks its logic to the Nifty 50 Index (NSE:NIFTY) and applies a strict hierarchy of trend analysis. The goal is simple: prioritize the long-term trend (Monthly/Weekly) to decide if you should even be in the market, then use the short-term trend (Daily) for precise exit timing.
This script ensures you never ignore a macro "crash" signal while trying to trade minor daily fluctuations.
The Color Hierarchy (Priority Logic)
The indicator uses a "Top-Down" filter. Higher timeframe signals override lower timeframe signals:
Level 1: Monthly (Ultra-Macro) — Deep Maroon
Condition: Nifty 10 EMA is below the 20 EMA on the Monthly chart.
Action: This is the highest priority. The background will turn Deep Maroon, overriding all other colors. This is your "Forget Trading" signal. The long-term structural trend is broken.
Level 2: Weekly (Macro Warning) — Dark Red
Condition: Monthly is Bullish, but Nifty 10 EMA is below the 20 EMA on the Weekly chart.
Action: The background turns Dark Red. This indicates a significant macro correction. You should stay out of fresh positions and protect capital.
Level 3: Daily (Tactical) — Light Red / Light Green
Condition: Both Monthly and Weekly are Bullish (Green).
Action: The background will now react to the Daily 10/20 EMA cross.
Light Green: Nifty is healthy; safe for fresh positions.
Light Red: Tactical exit signal. Nifty is seeing short-term weakness; exit positions quickly.
Key Features
Symbol Locked: No matter what stock you are viewing (Reliance, HDFC, Midcaps), the background only reacts to NSE:NIFTY.
Clean Interface: No messy lines or labels on the price chart. The information is conveyed purely through background color shifts.
Customizable: Change the MA types (EMA/SMA) and lengths (e.g., 10/20 or 20/50) in the settings.
Macro Dashboard: A small, transparent table in the top-right corner displays exactly which timeframe is currently controlling the background color.
How to Use for Nifty Strategy
Stay Out: If the chart is Deep Maroon or Dark Red, do not look for "buying the dip." Wait for the macro health to return.
Take Exits: If the background is Light Green and suddenly turns Light Red, it means the Daily Daily 10/20 cross has happened. Exit your Nifty-sensitive positions immediately.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.