OPEN-SOURCE SCRIPT
XAUUSD/SPX with SMA(48)

📊 Gold vs S&P 500 | XAUUSD/SPX Ratio with SMA (48) – Full Pine Script Breakdown
In this video, we build and explain a custom Pine Script that plots the Gold to S&P 500 ratio (XAUUSD/SPX) along with a 48-period Simple Moving Average (SMA).
This ratio helps us analyze how Gold is performing against equities and whether smart money is shifting from risk assets (stocks) to safe haven (gold).
🔧 What’s Included in the Script:
✅ Live ratio of XAUUSD (Gold) / SPX (S&P 500)
✅ 48-period SMA for trend analysis
✅ Clean visual chart in a separate pane
✅ Pine Script v5 compatible
🧠 Why This Matters:
Tracking the XAUUSD/SPX ratio gives deeper insight into macro trends, inflation hedge behavior, and market sentiment.
A rising ratio can signal weakness in equities and strength in precious metals — a key trend for long-term investors and macro traders.
In this video, we build and explain a custom Pine Script that plots the Gold to S&P 500 ratio (XAUUSD/SPX) along with a 48-period Simple Moving Average (SMA).
This ratio helps us analyze how Gold is performing against equities and whether smart money is shifting from risk assets (stocks) to safe haven (gold).
🔧 What’s Included in the Script:
✅ Live ratio of XAUUSD (Gold) / SPX (S&P 500)
✅ 48-period SMA for trend analysis
✅ Clean visual chart in a separate pane
✅ Pine Script v5 compatible
🧠 Why This Matters:
Tracking the XAUUSD/SPX ratio gives deeper insight into macro trends, inflation hedge behavior, and market sentiment.
A rising ratio can signal weakness in equities and strength in precious metals — a key trend for long-term investors and macro traders.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้มันเป็นโอเพ่นซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันการทำงานของสคริปต์ได้ ขอแสดงความชื่นชมผู้เขียน! แม้ว่าคุณจะสามารถใช้งานได้ฟรี แต่อย่าลืมว่าการเผยแพร่โค้ดซ้ำนั้นจะต้องเป็นไปตามกฎระเบียบการใช้งานของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้มันเป็นโอเพ่นซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันการทำงานของสคริปต์ได้ ขอแสดงความชื่นชมผู้เขียน! แม้ว่าคุณจะสามารถใช้งานได้ฟรี แต่อย่าลืมว่าการเผยแพร่โค้ดซ้ำนั้นจะต้องเป็นไปตามกฎระเบียบการใช้งานของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน