This indicator determines the swing high and swing low levels in a given period and draws supply and demand zones based on these levels. It also adds BOS (Break of Structure) signals in case these zones are broken.
Code Detailing:
1. Settings and User Inputs:
Swing High/Low Length: The period used to determine the swing high and low levels. This can be set by the user.
History To Keep: Specifies the number of supply and demand zones in the past in the indicator.
Supply/Demand Box Width: The width of the supply and demand boxes, i.e. how much width will be left according to the ATR (Average True Range).
Visual Settings: Settings for colors and labels to customize the indicator.
2. Functions:
f_array_add_pop: Adds a new value and removes the oldest value from the array. This function is used to store a certain number of data.
f_sh_sl_labels: Adds labels to swing highs and lows. These labels are labels that indicate price action, such as "HH", "HL", "LH", "LL".
f_check_overlapping: Before drawing a new demand or supply zone, it checks if it overlaps with existing zones. If there is an overlap, a new zone is not drawn.
f_supply_demand: Draws supply and demand zones. This function determines the upper and lower limits of the supply and demand levels and draws a box.
f_sd_to_bos: If the supply or demand zone is broken, it changes the zone to "BOS" (Break of Structure).
f_extend_box_endpoint: Updates the existing supply and demand boxes, extending their right borders to the next bar index.
3. Calculations:
ATR (Average True Range): Used to measure price volatility. This is the value used as the basis for determining the size of supply and demand boxes.
Swing High and Swing Low: Swing highs and lows are calculated using the highest and lowest prices over a given period.
Box Array and POI (Point of Interest): A collection of drawn supply and demand boxes and the levels of interest found within these boxes.
4. Main Calculations and Actions:
New Swing High or Swing Low Formation: If a new swing high or low is formed, these levels are recorded and demand or supply zones are drawn.
Break of Structure (BOS): If price breaks the supply or demand zone, it marks the zone as "BOS".
Extension of Boxes: Supply and demand boxes are continuously extended according to the current bar index.
Visual Features:
Supply and Demand Zones: Supply zones are drawn in red and demand zones in green. A border color is also specified around the zones.
POI Labels: A POI (Point of Interest) label is displayed in the middle of each supply and demand zone.
BOS Labels: BOS label is added above broken supply or demand zones.
Customization with User Inputs:
Show Price Action Labels: An option to set the visibility of price action labels. These labels indicate swing highs and lows.
Different Color and Size Options: Colors for supply and demand zones and colors for POI labels can be customized by the user.
Conclusion:
This Pine Script™ provides a comprehensive tool to monitor supply and demand zones in the market, identify important price levels and analyze price movements in these zones. Based on classic price action methods, it detects supply and demand zones as well as breakouts of these zones.
진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.