OPEN-SOURCE SCRIPT
已更新 Flat Top & Bottom Indicator

Flat Top & Bottom Indicator
Flat Top & Bottom Indicator is an open-source market-structure tool for identifying repeated structural highs and lows on a chart.
The script is designed to help traders see price areas where the market has previously formed a flat high or flat low and later returned to the same level. These areas may be useful as visual reference points for studying resistance, support, range behavior, breakouts, retests, or failed continuation.
This indicator does not predict future price movement and does not generate automatic buy or sell recommendations. It is intended as a charting and educational tool for traders who want to study repeated price structures more clearly.
How it works
The script searches back over a user-defined lookback period to find cases where the current high or low matches a previous structural high or structural low.
For a potential flat top, the script checks whether:
the current bar is forming a local high based on the selected pivot strength,
the current high matches a previous high within the lookback period,
the previous high was also a local structural high,
price did not create a higher or equal high between the two points,
and the current candle closes below its open.
For a potential flat bottom, the script checks whether:
the current bar is forming a local low based on the selected pivot strength,
the current low matches a previous low within the lookback period,
the previous low was also a local structural low,
price did not create a lower or equal low between the two points,
and the current candle closes above its open.
When these conditions are met, the indicator draws a horizontal line between the earlier structural point and the current bar. The label “SF Top” marks a structural flat top, and “SF Bottom” marks a structural flat bottom.
Inputs
Lookback Period controls how many historical bars the script searches for a matching structural high or low.
Pivot Strength controls how selective the script is when identifying local highs and lows. Higher values generally filter for more significant structures, while lower values may detect more frequent levels.
Flat Top Line Color and Flat Bottom Line Color allow users to customize the chart display.
Early Bird Mode controls whether the script can mark a structure during the current realtime bar or only after the bar is confirmed.
When Early Bird Mode is disabled, the script waits for the bar to close before plotting confirmed structures. When Early Bird Mode is enabled, the script can plot during the realtime bar as soon as the conditions are met. Realtime markings may update before the bar closes.
Alerts and data-window outputs
The script includes alert conditions for structural flat tops and structural flat bottoms.
It also plots hidden numeric signal outputs in the data window:
SF Top Signal: 1 when a structural flat top is detected, otherwise 0.
SF Bottom Signal: 1 when a structural flat bottom is detected, otherwise 0.
These outputs may be useful for alerts, review, or manual export.
How to use it
This indicator is best used as a visual market-structure aid. Traders can use the marked levels to observe how price behaves when it returns to a previously established high or low.
For example, traders may watch whether price rejects the level, breaks through it, retests it, or moves back into the prior range. The marked levels should be interpreted as context, not as standalone trade signals.
Users should combine this tool with their own market analysis, risk management, timeframe selection, and confirmation process.
Limitations
The indicator identifies historical structural relationships. A marked flat top or flat bottom does not guarantee that price will reverse, break out, or react in a predictable way.
Because the script requires repeated price structures, some signals may appear only after price has already interacted with a level. In fast-moving trends, low-liquidity markets, or highly volatile conditions, some levels may be less useful.
When Early Bird Mode is enabled, realtime markings can appear before the bar closes and may change as the bar develops. Users who prefer confirmed signals should keep Early Bird Mode disabled.
This script is open-source so users can inspect the logic, learn from it, and adapt it for their own educational use.
Flat Top & Bottom Indicator is an open-source market-structure tool for identifying repeated structural highs and lows on a chart.
The script is designed to help traders see price areas where the market has previously formed a flat high or flat low and later returned to the same level. These areas may be useful as visual reference points for studying resistance, support, range behavior, breakouts, retests, or failed continuation.
This indicator does not predict future price movement and does not generate automatic buy or sell recommendations. It is intended as a charting and educational tool for traders who want to study repeated price structures more clearly.
How it works
The script searches back over a user-defined lookback period to find cases where the current high or low matches a previous structural high or structural low.
For a potential flat top, the script checks whether:
the current bar is forming a local high based on the selected pivot strength,
the current high matches a previous high within the lookback period,
the previous high was also a local structural high,
price did not create a higher or equal high between the two points,
and the current candle closes below its open.
For a potential flat bottom, the script checks whether:
the current bar is forming a local low based on the selected pivot strength,
the current low matches a previous low within the lookback period,
the previous low was also a local structural low,
price did not create a lower or equal low between the two points,
and the current candle closes above its open.
When these conditions are met, the indicator draws a horizontal line between the earlier structural point and the current bar. The label “SF Top” marks a structural flat top, and “SF Bottom” marks a structural flat bottom.
Inputs
Lookback Period controls how many historical bars the script searches for a matching structural high or low.
Pivot Strength controls how selective the script is when identifying local highs and lows. Higher values generally filter for more significant structures, while lower values may detect more frequent levels.
Flat Top Line Color and Flat Bottom Line Color allow users to customize the chart display.
Early Bird Mode controls whether the script can mark a structure during the current realtime bar or only after the bar is confirmed.
When Early Bird Mode is disabled, the script waits for the bar to close before plotting confirmed structures. When Early Bird Mode is enabled, the script can plot during the realtime bar as soon as the conditions are met. Realtime markings may update before the bar closes.
Alerts and data-window outputs
The script includes alert conditions for structural flat tops and structural flat bottoms.
It also plots hidden numeric signal outputs in the data window:
SF Top Signal: 1 when a structural flat top is detected, otherwise 0.
SF Bottom Signal: 1 when a structural flat bottom is detected, otherwise 0.
These outputs may be useful for alerts, review, or manual export.
How to use it
This indicator is best used as a visual market-structure aid. Traders can use the marked levels to observe how price behaves when it returns to a previously established high or low.
For example, traders may watch whether price rejects the level, breaks through it, retests it, or moves back into the prior range. The marked levels should be interpreted as context, not as standalone trade signals.
Users should combine this tool with their own market analysis, risk management, timeframe selection, and confirmation process.
Limitations
The indicator identifies historical structural relationships. A marked flat top or flat bottom does not guarantee that price will reverse, break out, or react in a predictable way.
Because the script requires repeated price structures, some signals may appear only after price has already interacted with a level. In fast-moving trends, low-liquidity markets, or highly volatile conditions, some levels may be less useful.
When Early Bird Mode is enabled, realtime markings can appear before the bar closes and may change as the bar develops. Users who prefer confirmed signals should keep Early Bird Mode disabled.
This script is open-source so users can inspect the logic, learn from it, and adapt it for their own educational use.
版本注释
Tilt mode provides more signal opportunities by detecting near-flat TOP/BTM structures with a 1-tick difference.This mode is designed mainly for ES/MES.
Please use it with caution on NQ/MNQ, GC/MGC, and CL/MCL, as the signal quality may vary.
For other instruments, Tilt signals may occur very rarely and are generally not recommended.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。