OPEN-SOURCE SCRIPT
מעודכן trend line [odnac]

Overview
Trendline Conditions
Pivot Detection Methods (4 modes)
Settings
> Trendline Mode : Select pivot detection method
> Swing Left/Right Bars : Number of bars on each side for Swing Confirm mode
> Pivot Left/Right Bars : Number of bars on each side for Pivot High/Low mode
> Fractal Bars : Number of bars on each side for Williams Fractal
> Donchian Length : Lookback period for Donchian mode
> Show Labels : Toggle swing point labels on/off
> Show High/Low Trendlines : Toggle high/low trendlines on/off
> High/Low Line Color : Color of trendlines
Notes
This indicator automatically detects swing highs and swing lows, and draws trendlines connecting valid highs to highs and lows to lows. Lines automatically terminate when price breaks through them. Four pivot detection methods are supported.
Trendline Conditions
- High Trendline (Descending Resistance): Drawn only when the current swing high is lower than the previous swing high
- Low Trendline (Ascending Support): Drawn only when the current swing low is higher than the previous swing low
- Wick Breach Filter: If any candle wick (high/low) between two pivot points touches or crosses the trendline, the line is not drawn
- Breakout Detection: When the closing price crosses the trendline, the line is terminated at that bar
Pivot Detection Methods (4 modes)
- Swing Confirm
Detects highs and lows based on left/right bar count, but only accepts pivot points that pass an additional bearish/bullish confirmation condition. Produces fewer but more reliable swing points with less noise. - Pivot High/Low
Uses raw ta.pivothigh / ta.pivotlow values directly. Any point that is higher or lower than the surrounding N bars on each side is recognized as a pivot. - Williams Fractal
Confirms a pivot when the center bar's high/low is greater or less than N bars on both sides. The default value of 2 produces the classic 5-bar fractal pattern. - Donchian
Uses the highest high and lowest low over N bars as pivot points. A simple and clean channel-based pivot detection method.
Settings
> Trendline Mode : Select pivot detection method
> Swing Left/Right Bars : Number of bars on each side for Swing Confirm mode
> Pivot Left/Right Bars : Number of bars on each side for Pivot High/Low mode
> Fractal Bars : Number of bars on each side for Williams Fractal
> Donchian Length : Lookback period for Donchian mode
> Show Labels : Toggle swing point labels on/off
> Show High/Low Trendlines : Toggle high/low trendlines on/off
> High/Low Line Color : Color of trendlines
Notes
- Trendlines are drawn based on confirmed pivot points only, with no repainting
- The wick breach filter may result in fewer lines being drawn. This is intentional — only clean, high-confidence trendlines are displayed
- Each mode has its own independent parameters, so be sure to adjust settings individually when switching modes
הערות שחרור
Swing Confirm mode updated- Replaced rightBars window with unlimited confirmation — no time limit on swing candidates
- A swing high is confirmed when N consecutive renewing bearish closes (each lower than the last) are detected after the candidate
- A swing high is confirmed when N consecutive renewing bullish closes (each higher than the last) are detected after the candidate
- Swing point is plotted at the actual pivot bar, not the confirmation bar
- Right Bars setting replaced with Confirmation Count (default 3)
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.