OPEN-SOURCE SCRIPT

Close-Only Market Structure

421
DYOR NFA
Function of the Close-Only Market Structure Script
The script is a custom indicator designed to display the market's structural trend based only on closing prices, ignoring price wicks (highs and lows) to focus on conviction.

pivotLengthInt Input: This user setting controls the sensitivity of the structure detection. It determines how many bars to look left and right to define a swing point (e.g., a setting of 5 means a bar's close must be the highest/lowest of the 5 preceding and 5 succeeding bars).

Swing Point Identification (SH/SL): It uses the ta.pivothigh() and ta.pivotlow() functions on the close price series to define Swing Highs (SH) and Swing Lows (SL).

Structure Tracking (structureType): It compares the most recent confirmed SH and SL against the immediately preceding ones (prevSH and prevSL) to classify the trend as one of the following four states:

HH (Higher High, Higher Low): Strong Uptrend

LL (Lower High, Lower Low): Strong Downtrend

HL/LH: Complex structure, consolidation, or reversal zones.

Structure Lines: It plots two continuous stepped lines (lastSH and lastSL) that hold the price of the most recent confirmed swing points, visually defining the current structure boundaries.

BOS Detection (Break of Structure): It identifies and plots a marker (BOS) when the current bar's close definitively breaks (closes above) the lastSH or closes below the lastSL, signaling a continuation of the trend or a major structural change.

Visual Confirmation:

Plots small SH/SL labels at the confirmed swing points.

Plots small HH/HL/LH/LL labels at the swing points to show the confirmed structural state.

Applies a light background color (green for bullish/ranging-up, red for bearish/ranging-down) for an at-a-glance view of the bias.

Alerts: It provides conditions for setting up notifications when a Bullish BOS or Bearish BOS occurs.

🚀 How to Use the Script
Open TradingView: Go to the chart where you want to apply the indicator.

Open Pine Editor: Click the Pine Editor tab at the bottom of the screen.

Paste and Save:

Copy the final, corrected Pine Script code.

Delete any existing code in the editor and paste the new code.

Click the Save button (or name the script) and then click Add to Chart.

Adjust Settings:

On the chart, hover over the indicator name ("Close-MS v6") and click the Gear Icon (Settings).

Pivot Lookback (L&R): Change this value to adjust sensitivity:

Smaller number (e.g., 3): More swings detected, structure changes faster, more noise.

Larger number (e.g., 10): Fewer swings detected, structure is more significant, less noise (recommended for higher timeframes).

Interpret the Chart:

The Red Stepped Line shows your current resistance (SH).

The Green Stepped Line shows your current support (SL).

Green Background: General bullish bias (making Higher Highs/Lows).

Red Background: General bearish bias (making Lower Highs/Lows).

BOS Triangle: Signals that the price has closed and validated a break of the previous structural high or low.

Set Alerts (Optional):

Click the Alert button (bell icon) on the TradingView toolbar.

Set the Condition to the indicator ("Close-MS v6").

Select the specific Alert Condition you want to monitor (e.g., "Bullish BOS" or "Bearish BOS").

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน