OPEN-SOURCE SCRIPT
Gold Golden Zone with TP/SL

1. Higher Timeframe (HTF) Trend
The script fetches the close and an EMA (user‑defined length) from a higher timeframe (e.g., 1‑hour).
HTF Bullish → HTF close > HTF EMA
HTF Bearish → HTF close < HTF EMA
This ensures that entries align with the broader market direction.
2. Swing Detection for Fibonacci
Uses ta.pivothigh and ta.pivotlow with a user‑defined lookback (fib_swing_length) to find the most recent major swing high and low.
Stores both the price and the bar index of these swings.
Determines the current trend structure:
Uptrend when the last swing low occurred before the last swing high.
Downtrend when the last swing high occurred before the last swing low.
3. Fibonacci Golden Zone
For an uptrend, the Fibonacci levels are drawn from the swing low (0%) to the swing high (100%).
For a downtrend, they are drawn from the swing high (0%) to the swing low (100%).
The Golden Zone is the area between the 50% and 61.8% retracement levels – highlighted with a yellow box.
The script stores the exact values of the 50% and 61.8% levels (fib_50 and fib_618).
4. Position in Golden Zone
Long condition (in_golden_zone_uptrend):
low <= fib_50 and high >= fib_618
(Price overlaps the 50%–61.8% region during an uptrend)
Short condition (in_golden_zone_downtrend):
high >= fib_50 and low <= fib_618
(Price overlaps the 50%–61.8% region during a downtrend)
5. Raw Signals
Raw Long = HTF Bullish AND in_golden_zone_uptrend
Raw Short = HTF Bearish AND in_golden_zone_downtrend
6. Optional Confirmation Triggers
If the user enables use_confirmation, the signal must also satisfy one of the following:
Structure Break
Bullish: close above the last minor swing low (structure_lookback)
Bearish: close below the last minor swing high
Momentum Candle
Body of the current candle > 70% of its total range (indicating strong directional momentum)
Confirmation helps filter out false entries in choppy markets.
The script fetches the close and an EMA (user‑defined length) from a higher timeframe (e.g., 1‑hour).
HTF Bullish → HTF close > HTF EMA
HTF Bearish → HTF close < HTF EMA
This ensures that entries align with the broader market direction.
2. Swing Detection for Fibonacci
Uses ta.pivothigh and ta.pivotlow with a user‑defined lookback (fib_swing_length) to find the most recent major swing high and low.
Stores both the price and the bar index of these swings.
Determines the current trend structure:
Uptrend when the last swing low occurred before the last swing high.
Downtrend when the last swing high occurred before the last swing low.
3. Fibonacci Golden Zone
For an uptrend, the Fibonacci levels are drawn from the swing low (0%) to the swing high (100%).
For a downtrend, they are drawn from the swing high (0%) to the swing low (100%).
The Golden Zone is the area between the 50% and 61.8% retracement levels – highlighted with a yellow box.
The script stores the exact values of the 50% and 61.8% levels (fib_50 and fib_618).
4. Position in Golden Zone
Long condition (in_golden_zone_uptrend):
low <= fib_50 and high >= fib_618
(Price overlaps the 50%–61.8% region during an uptrend)
Short condition (in_golden_zone_downtrend):
high >= fib_50 and low <= fib_618
(Price overlaps the 50%–61.8% region during a downtrend)
5. Raw Signals
Raw Long = HTF Bullish AND in_golden_zone_uptrend
Raw Short = HTF Bearish AND in_golden_zone_downtrend
6. Optional Confirmation Triggers
If the user enables use_confirmation, the signal must also satisfy one of the following:
Structure Break
Bullish: close above the last minor swing low (structure_lookback)
Bearish: close below the last minor swing high
Momentum Candle
Body of the current candle > 70% of its total range (indicating strong directional momentum)
Confirmation helps filter out false entries in choppy markets.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน