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.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.