OPEN-SOURCE SCRIPT
Gann Fan Strategy [KedarArc Quant]

Description
A single-concept, rule-based strategy that trades around a programmatic Gann Fan.
It anchors to a swing (or a manual point), builds 1×1 and related fan lines numerically, and triggers entries when price interacts with the 1×1 (breakout or bounce). Management is done entirely with the fan structure (next/previous line) plus optional ATR trailing.
What TV indicators are used
* Pivots: `ta.pivothigh/ta.pivotlow` to confirm swing highs/lows for anchor selection.
* ATR: `ta.atr` only to scale the 1×1 slope (optional) and for an optional trailing stop.
* EMA: `ta.ema` as a trend filter (e.g., only long above the EMA, short below).
No RSI/MACD/Stoch/Heikin/etc. The logic is one coherent framework: Gann price–time geometry, with ATR as a scale and EMA as a risk filter.
How it works
1. Anchor
* Auto: chooses the most recent *confirmed* pivot (you control Left/Right).
* Manual: set a price and bar index and the fan will hold that point (no re-anchoring).
* Optional Re-anchor when a newer pivot confirms.
2. 1×1 Slope (numeric, not cosmetic)
* ATR mode: `1×1 = ATR(Length) × Multiplier` (adapts to volatility).
* Fixed mode: `ticks per bar` (constant slope).
Because slope is numeric, it doesn’t change with chart zoom, unlike the drawing tool.
3. Fan Lines
Builds classic ratios around the 1×1: 1/8, 1/4, 1/3, 1/2, 1/1, 2/1, 3/1, 4/1, 8/1.
4. Signals
* Breakout: cross of price over/under the 1×1 in the EMA-aligned direction.
* Bounce (optional): touch + reversal across the 1×1 to reduce whipsaw.
5. Exits & Risk
* Take-profit at the next fan line; Stop at the previous fan line.
* If a level is missing (right after re-anchor), a fallback Risk-Reward (RR) is used.
* Optional ATR trailing stop.
Why this is unique
* True numeric fan: The 1×1 slope is calculated from ATR or fixed ticks—not from screen geometry—so it is scale-invariant and reproducible across users/timeframes.
* Deterministic anchor logic: Uses confirmed pivots (with your L/R settings). No look-ahead; anchors update only when the right bars complete.
* Fan-native trade management: Both entries and exits come from the fan structure itself (with a minimal ATR/EMA assist), keeping the method pure.
* Two entry archetypes: Breakout for momentum days; Bounce for range days—switchable without changing the core model.
* Manual mode: Lock a session’s bias by anchoring to a chosen swing (e.g., day’s first major low/high) and keep the fan constant all day.
Inputs (quick guide)
* Auto Anchor (Left/Right): pivot sensitivity. Higher values = fewer, stronger anchors.
* Re-anchor: refresh to newer pivots as they confirm.
* Manual Anchor Price / Bar Index: fixes the fan (turn Auto off).
* Scale 1×1 by ATR: on = adaptive; off = use ticks per bar.
* ATR Length / ATR Multiplier: controls adaptive slope; start around 14 / 0.25–0.35.
* Ticks per bar: exact fixed slope (match a hand-drawn fan by computing slope ÷ mintick).
* EMA Trend Filter: e.g., 50–100; trades only in EMA direction.
* Use Bounce: require touch + reverse across 1×1 (helps in chop).
* TP/SL at fan lines; Fallback RR for missing levels; ATR Trailing Stop optional.
* Transparency/Plot EMA: visual preferences.
Tips
* Range days: larger pivots (L/R 8–12), Bounce ON, ATR Multiplier \~0.30–0.40, EMA 100.
* Trend days: L/R 5–6, Breakout, Multiplier \~0.20–0.30, EMA 50, ATR trail 1.0–1.5.
* Match the TV Gann Fan drawing: turn ATR scale OFF, set ticks per bar = `(Δprice between anchor and 1×1 target) / (bars) / mintick`.
Repainting & testing notes
* Pivots require Right bars to confirm; anchors are set after confirmation (no look-ahead).
* Signals use the current bar close with TradingView strategy mechanics; real-time vs. bar-close can differ slightly, as with any strategy.
* Re-anchoring legitimately moves the structure when new pivots confirm—by design.
⚠️ Disclaimer
This script is provided for educational purposes only.
Past performance does not guarantee future results.
Trading involves risk, and users should exercise caution and use proper risk management when applying this strategy.
A single-concept, rule-based strategy that trades around a programmatic Gann Fan.
It anchors to a swing (or a manual point), builds 1×1 and related fan lines numerically, and triggers entries when price interacts with the 1×1 (breakout or bounce). Management is done entirely with the fan structure (next/previous line) plus optional ATR trailing.
What TV indicators are used
* Pivots: `ta.pivothigh/ta.pivotlow` to confirm swing highs/lows for anchor selection.
* ATR: `ta.atr` only to scale the 1×1 slope (optional) and for an optional trailing stop.
* EMA: `ta.ema` as a trend filter (e.g., only long above the EMA, short below).
No RSI/MACD/Stoch/Heikin/etc. The logic is one coherent framework: Gann price–time geometry, with ATR as a scale and EMA as a risk filter.
How it works
1. Anchor
* Auto: chooses the most recent *confirmed* pivot (you control Left/Right).
* Manual: set a price and bar index and the fan will hold that point (no re-anchoring).
* Optional Re-anchor when a newer pivot confirms.
2. 1×1 Slope (numeric, not cosmetic)
* ATR mode: `1×1 = ATR(Length) × Multiplier` (adapts to volatility).
* Fixed mode: `ticks per bar` (constant slope).
Because slope is numeric, it doesn’t change with chart zoom, unlike the drawing tool.
3. Fan Lines
Builds classic ratios around the 1×1: 1/8, 1/4, 1/3, 1/2, 1/1, 2/1, 3/1, 4/1, 8/1.
4. Signals
* Breakout: cross of price over/under the 1×1 in the EMA-aligned direction.
* Bounce (optional): touch + reversal across the 1×1 to reduce whipsaw.
5. Exits & Risk
* Take-profit at the next fan line; Stop at the previous fan line.
* If a level is missing (right after re-anchor), a fallback Risk-Reward (RR) is used.
* Optional ATR trailing stop.
Why this is unique
* True numeric fan: The 1×1 slope is calculated from ATR or fixed ticks—not from screen geometry—so it is scale-invariant and reproducible across users/timeframes.
* Deterministic anchor logic: Uses confirmed pivots (with your L/R settings). No look-ahead; anchors update only when the right bars complete.
* Fan-native trade management: Both entries and exits come from the fan structure itself (with a minimal ATR/EMA assist), keeping the method pure.
* Two entry archetypes: Breakout for momentum days; Bounce for range days—switchable without changing the core model.
* Manual mode: Lock a session’s bias by anchoring to a chosen swing (e.g., day’s first major low/high) and keep the fan constant all day.
Inputs (quick guide)
* Auto Anchor (Left/Right): pivot sensitivity. Higher values = fewer, stronger anchors.
* Re-anchor: refresh to newer pivots as they confirm.
* Manual Anchor Price / Bar Index: fixes the fan (turn Auto off).
* Scale 1×1 by ATR: on = adaptive; off = use ticks per bar.
* ATR Length / ATR Multiplier: controls adaptive slope; start around 14 / 0.25–0.35.
* Ticks per bar: exact fixed slope (match a hand-drawn fan by computing slope ÷ mintick).
* EMA Trend Filter: e.g., 50–100; trades only in EMA direction.
* Use Bounce: require touch + reverse across 1×1 (helps in chop).
* TP/SL at fan lines; Fallback RR for missing levels; ATR Trailing Stop optional.
* Transparency/Plot EMA: visual preferences.
Tips
* Range days: larger pivots (L/R 8–12), Bounce ON, ATR Multiplier \~0.30–0.40, EMA 100.
* Trend days: L/R 5–6, Breakout, Multiplier \~0.20–0.30, EMA 50, ATR trail 1.0–1.5.
* Match the TV Gann Fan drawing: turn ATR scale OFF, set ticks per bar = `(Δprice between anchor and 1×1 target) / (bars) / mintick`.
Repainting & testing notes
* Pivots require Right bars to confirm; anchors are set after confirmation (no look-ahead).
* Signals use the current bar close with TradingView strategy mechanics; real-time vs. bar-close can differ slightly, as with any strategy.
* Re-anchoring legitimately moves the structure when new pivots confirm—by design.
⚠️ Disclaimer
This script is provided for educational purposes only.
Past performance does not guarantee future results.
Trading involves risk, and users should exercise caution and use proper risk management when applying this strategy.
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。