wedges
Download scriptThis script is a sophisticated technical analysis tool designed to automatically identify and visualize Wedges—specific price patterns where the high and low points of a market trend converge. It uses a combination of mathematical regression, statistical deviation, and multi-layered filtering to distinguish meaningful structural trends from minor market "noise."
Here is a breakdown of the logic used by the script:
1. Trend Identification & Regression
The core engine begins by analyzing price data over a user-defined period. Instead of just looking at simple highs or lows, it uses Linear Regression to calculate the "best fit" line for the current market movement.
- Slope Calculation: It determines the primary direction (angle) and height of the price movement.
- Dynamic Deviation: It calculates the standard deviation of price movement relative to that trend line. This allows the script to create "high" and "low" boundaries that expand or contract based on how volatile the market is at that specific moment.
2. Structural Peak Detection
The script scans the historical data to find significant Tops and Bottoms. Rather than marking every small wiggle in price, it applies a "Noise Filter." A point is only recorded as a valid peak or valley if it meets specific criteria:
- It must be a local extreme (higher than nearby points).
- The price spread must be large enough to be considered a significant reversal rather than just random fluctuation.
3. Wedge Construction & Scoring
Once the script identifies several "Top" and "Bottom" points, it attempts to connect them to form a wedge. To ensure accuracy, it uses a Scoring System:
- Angle Matching: It calculates the trajectory between various historical points.
- Best Fit Logic: If multiple possible lines could form a wedge, the script evaluates which one most closely aligns with the current standard deviation and slope.
- Visual Feedback: Once the "best" wedge is identified, it draws trend lines on your chart (represented by different colors like Light Sea Green).
4. Multi-Layered Filtering
To prevent the chart from becoming cluttered with false signals, the script employs three distinct filters:
- Deviation Filter: Ensures the price remains within a reasonable distance from the calculated wedge boundaries.
- Line Filter: Validates that the newly formed lines aren't too erratic compared to the established trend.
- ATR (Average True Range) Filter: This is a volatility check. It looks at recent market movement to ensure that the wedge is forming in a stable environment, helping to ignore "choppy" periods where price action lacks clear direction.
5. Visual Output
The script provides several different modes for how these wedges appear on the chart:
- Line Only/Set Buffer: Options to show just the trend lines or handle the data internally for further calculation.
- Automatic Cleaning: The script includes a "cleanup" mechanism that ensures old, irrelevant objects are removed from the screen as new ones are created, keeping your workspace organized and focused on current price action.
ÿþ/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
/ / | W e d g e s . m q 4 |
/ / | W e d g e s v 1 . 0 C o p y r i g h t 2 0 1 5 , f x b o r g |
/ / | h t t p : / / f x b o r g - l a b o . h a t e b l o . j p / |
/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
# p r o p e r t y c o p y r i g h t "