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 อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน