OPEN-SOURCE SCRIPT
SouthStone FVG Swing Levels

// Highlights swing highs/lows on a user-selected higher timeframe (default H1)
// that have had a Fair Value Gap (3-bar imbalance) form through them. These
// levels tend to act as high-probability retest targets because price
// "gapped" away from them and liquidity remains.
//
// All detection runs on the selected HTF. Lines use time-based x-coordinates
// so they render identically on ANY chart timeframe. On M5 / M15 / M1 the
// H1 levels remain visible, anchored at the actual pivot times.
//
// Logic (runs on HTF, results piped to chart TF):
// 1. Detect pivot highs and pivot lows on HTF via ta.pivothigh/low.
// 2. Store each pivot as "pending".
// 3. On each HTF bar, check if a new 3-bar FVG has formed:
// Bullish FVG: low[0] > high[2] -> gap = [high[2], low[0]]
// Bearish FVG: high[0] < low[2] -> gap = [high[0], low[2]]
// 4. For each pending pivot:
// a) If this HTF bar forms a valid FVG whose gap contains the pivot
// AND the FVG direction matches (bullish for swing highs, bearish
// for swing lows) -> draw line, pivot done.
// b) Else if the PREVIOUS HTF bar's range touched the pivot level
// without being claimed by an FVG here -> discard pivot forever.
// c) Else -> stay pending.
// 5. Lines extend forward until max line age (in HTF bars) is reached,
// then stop extending with a fixed right endpoint.
//
// Non-repainting HTF pattern: uses [1] offset with lookahead_on per v6
// best practice. Signals appear at the start of the NEXT HTF bar after
// the confirming one.
//
// - Default colours split: swing-high lines (bullish FVG break) now blue
// (#2196f3); swing-low lines (bearish FVG break) remain red (#ef5350).
// Both remain user-configurable.
//
// - Major rewrite for HTF support. All detection logic runs inside a
// request.security() function on the selected HTF, so H1 levels stay
// anchored in time across all chart timeframes.
// - Line x-coordinates switched to xloc.bar_time for cross-TF consistency.
// - maxAge / maxLineAge thresholds now expressed in HTF bars, converted
// internally to milliseconds for time-based comparisons.
// - Added HTF input (default "60" = H1).
// that have had a Fair Value Gap (3-bar imbalance) form through them. These
// levels tend to act as high-probability retest targets because price
// "gapped" away from them and liquidity remains.
//
// All detection runs on the selected HTF. Lines use time-based x-coordinates
// so they render identically on ANY chart timeframe. On M5 / M15 / M1 the
// H1 levels remain visible, anchored at the actual pivot times.
//
// Logic (runs on HTF, results piped to chart TF):
// 1. Detect pivot highs and pivot lows on HTF via ta.pivothigh/low.
// 2. Store each pivot as "pending".
// 3. On each HTF bar, check if a new 3-bar FVG has formed:
// Bullish FVG: low[0] > high[2] -> gap = [high[2], low[0]]
// Bearish FVG: high[0] < low[2] -> gap = [high[0], low[2]]
// 4. For each pending pivot:
// a) If this HTF bar forms a valid FVG whose gap contains the pivot
// AND the FVG direction matches (bullish for swing highs, bearish
// for swing lows) -> draw line, pivot done.
// b) Else if the PREVIOUS HTF bar's range touched the pivot level
// without being claimed by an FVG here -> discard pivot forever.
// c) Else -> stay pending.
// 5. Lines extend forward until max line age (in HTF bars) is reached,
// then stop extending with a fixed right endpoint.
//
// Non-repainting HTF pattern: uses [1] offset with lookahead_on per v6
// best practice. Signals appear at the start of the NEXT HTF bar after
// the confirming one.
//
// - Default colours split: swing-high lines (bullish FVG break) now blue
// (#2196f3); swing-low lines (bearish FVG break) remain red (#ef5350).
// Both remain user-configurable.
//
// - Major rewrite for HTF support. All detection logic runs inside a
// request.security() function on the selected HTF, so H1 levels stay
// anchored in time across all chart timeframes.
// - Line x-coordinates switched to xloc.bar_time for cross-TF consistency.
// - maxAge / maxLineAge thresholds now expressed in HTF bars, converted
// internally to milliseconds for time-based comparisons.
// - Added HTF input (default "60" = H1).
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。