OPEN-SOURCE SCRIPT

Smart Trend Lines ๐’ฏ๐’ฝ๐‘’_๐“๐“Š๐“‡๐“€๐‘’๐“‡

7โ€ฏ267
Smart Trend Lines is a tool for drawing dynamic, highly accurate, and error-free trend lines (major, intermediate, and short-term) with the detection of breaks in these lines using advanced filters such as ADX (Average Directional Index), RSI (Relative Strength Index), and trading volume. It aims to assist traders in accurately identifying trends and breakout points, thereby enhancing decision-making in trading.

1. Features of the Indicator

// Dynamic Trend Line Drawing with Three Lengths:
- Main Line: Based on a long time period (default is 50 candles) to identify long-term trends.
- Mid Line: Based on a medium time period (default is 21 candles) to identify medium-term trends.
- Short Line: Based on a short time period (default is 9 candles) to identify short-term trends.

//Breakout Detection:
- Monitors breakouts when the price crosses a trend line, either upward (for downward lines) or downward (for upward lines).
- Uses filters (ADX, RSI, volume) to confirm the validity of the breakout and reduce false signals.

//Filters for Signal Confirmation:
- ADX: Confirms the strength of the trend (default minimum is 20).
- RSI: Checks for overbought conditions (above 65) or oversold conditions (below 35) to avoid false breakouts.
- Trading Volume: Compares the current trading volume with the moving average of volume to ensure momentum.

//Flexible Settings:
- Customization of line colors (upward and downward) and styles (solid, dashed, dotted).
- Option to show or hide mid and short lines.
- Selection of price type for breakout detection (close, high, low).

//Optional Display of Previous Lines:
- Allows users to optionally view previously drawn trend lines.

//Alerts and Labels:
- Provides instant alerts when a breakout occurs, along with details of the achieved conditions (e.g., V for volume, A for ADX, R for RSI).
- Adds visual labels on the chart at the point of breakout, with customizable label sizes.

//Automatic Line Extensions:
- Dynamically extends trend lines as long as they remain unbroken, ensuring that prices do not breach the line in the opposite direction.

2. Methods of Drawing Lines

// Identification of Pivot Points:
- Pivot High and Pivot Low points are detected using specific time periods for each type of line (Main: 50, Mid: 21, Short: 9).
- High points (Pivot High) are used to draw downward trend lines, while low points (Pivot Low) are used to draw upward trend lines.

Clarification:
- The `ta.pivothigh` function is used to identify high points (Pivot High), and the `ta.pivotlow` function is used to identify low points (Pivot Low) based on the specified periods for each line:
- Main Line:** Uses `trendLineLength` (default 50 candles).
- Mid Line:** Uses `trendLineLengthMid` (default 21 candles).
- Short Line:** Uses `trendLineLengthShort` (default 9 candles).

- High points (Pivot High) are utilized to draw downward trend lines, while low points (Pivot Low) are utilized to draw upward trend lines.

This ensures that the trend lines are dynamically drawn based on significant price pivots, providing a precise representation of the market's directional movements.

//Calculating the Slope:

- The slope between two points (start and end) is calculated using the difference in price divided by the difference in the number of candles:

Slope = ( Price Difference/Number of Candles Difference)


- Downward trend lines require a negative slope, indicating that the price is decreasing over time.
- Upward trend lines require a positive slope, indicating that the price is increasing over time.

This calculation ensures that the trend lines accurately reflect the direction and rate of price movement, providing traders with a clear visual representation of the market's momentum.

Additional Notes:
- The slope of the line reflects not only the direction (upward or downward) but also the intensity of the trend. The steeper the slope, the stronger and faster the price movement.
- The use of this dynamic method for calculating the slope ensures that trend lines adapt to changing market conditions, providing real-time updates for traders.
- The mathematical precision of this method enhances the reliability of trend lines and reduces errors, making it a valuable tool for technical market analysis.

//Drawing the Lines:

- Base Line (Start Line): Connects the two Pivot points (start and end).
- Extended Line (Trend Line): Starts from the endpoint of the base line and extends to the current candle with the same slope.
- The line's color and style are determined based on user settings (e.g., red for downward lines, green for upward lines).

Clarification:
- The function `line.new` is used to draw the base line (`bearishStartLine`) from the starting point (`bearStartIndex, bearStartVal`) to the endpoint (`bearEndIndex, bearEndVal`).
- The extended line (`bearishTrendLine`) starts from the endpoint and extends to the current candle (`bar_index`) using the slope (`bearSlope`) to maintain the trend direction.

// Extending the Lines:

- The lines are dynamically extended to the current candle if no breakout occurs.
- The extension stops when a breakout occurs or if the price crosses the line in the opposite direction.

Clarification:
- The function `extendTrendline` updates the extended line by modifying the endpoint coordinates (`x2, y2`) to the current candle (`bar_index`) using the slope (`slope).
- If a crossover in the opposite direction is detected via `checkExtendedStrictMode`, the extension stops at the previous candle.

3. Conditions for Drawing Lines

Presence of at Least Two Pivot Points:
- Drawing a line requires the presence of two Pivot points:
- Two high points (Pivot High) for a downward line.
- Two low points (Pivot Low) for an upward line.
- These points must fall within a specified time period, not exceeding five times the length of the line.

Slope Validation:
- A downward line requires a negative slope, meaning the endpoint is lower than the starting point.
- An upward line requires a positive slope, meaning the endpoint is higher than the starting point.

Validation of Strict Mode:

- All candles between the two Pivot points are examined to ensure that the price does not breach the trend line:
- For a downward line: The price (close, high, or low, depending on the settings) must not exceed the projected value of the line.
- For an upward line: The price must not fall below the projected value of the line.

This ensures that the trend line remains valid and accurately reflects the price movement without interruptions caused by temporary breaches.

Validation of Post-Pivot Break:

- Candles after the endpoint are examined to ensure that the price has not breached the line in the opposite direction, ensuring the line's validity.

Validation of Strict Extension:

- When extending the line, it is confirmed that the price does not breach the extended line in the opposite direction.

These checks ensure the trend line remains accurate and reliable, both during its initial drawing and as it dynamically extends over time.

4. Conditions for Breakout Detection

Price Crossing the Line:
- For a downward line: The price (close, high, or low, depending on the settings) exceeds the level of the line.
- For an upward line: The price falls below the level of the line.

Candle Confirmation:
- The candle must be closed (confirmed) to register the breakout.

Filter Conditions:

- Trading Volume:
- The trading volume must be higher than the moving average.
- For an upward breakout: A green candle (close > open) with a volume higher than the last green candle is preferred.
- For a downward breakout: A red candle (close < open) with a volume higher than the last red candle is preferred.

- ADX (Average Directional Index):
- The ADX value must exceed the minimum threshold (default is 20) to confirm the strength of the trend.

- RSI (Relative Strength Index) (if enabled):
- For an upward breakout: The RSI should be less than or equal to the upper limit (65) to avoid overbought conditions.
- For a downward breakout: The RSI should be greater than or equal to the lower limit (35) to avoid oversold conditions.

Non-Repetition of Breakouts:
- Each breakout is recorded only once per line until a new line is drawn.

These conditions ensure that breakouts are accurately detected and validated, minimizing false signals and enhancing the reliability of the trading decisions.

5. Additional Notes

Display Settings:
- Users can choose to show or hide previous lines and customize the size of labels (e.g., Very Small, Small, Normal, Large, Huge).

Visual Styles:
- Line styles vary to facilitate differentiation:
- Solid for the main line.
- Dashed for the intermediate line.
- Dotted for the short-term line.

Alerts:
- A single alert is sent for each breakout, with text specifying the type of breakout (main, intermediate, short) and the filters that have been met.

These features enhance user experience by providing flexibility in visualization, ease of interpretation, and timely notifications for informed trading decisions.


Disclaimer
The information and posts are not intended to be, or constitute, any financial, investment, trading or other types of preparation or execution of tasks or endorsed by TradingView.

Smart Trend Lines ู‡ูˆ ู…ุคุดุฑ ุชุญู„ูŠู„ ูู†ูŠ ูŠุฑุณู… ุฎุทูˆุท ุงุชุฌุงู‡ ุฏูŠู†ุงู…ูŠูƒูŠุฉ (ุฑุฆูŠุณูŠุฉุŒ ู…ุชูˆุณุทุฉุŒ ู‚ุตูŠุฑุฉ) ุนู„ู‰ ุงู„ุฑุณู… ุงู„ุจูŠุงู†ูŠุŒ ูˆูŠูƒุชุดู ูƒุณูˆุฑู‡ุง ุจุงุณุชุฎุฏุงู… ูู„ุงุชุฑ ADXุŒ RSIุŒ ูˆุญุฌู… ุงู„ุชุฏุงูˆู„ ู„ุชุฃูƒูŠุฏ ุงู„ุฅุดุงุฑุงุช.

1. ุงู„ู…ู…ูŠุฒุงุช
1. ุฎุทูˆุท ุงุชุฌุงู‡ ุจุซู„ุงุซุฉ ุฃุทูˆุงู„:
- ุฑุฆูŠุณูŠ (50 ุดู…ุนุฉ): ู„ู„ุงุชุฌุงู‡ุงุช ุทูˆูŠู„ุฉ ุงู„ุฃู…ุฏ.
- ู…ุชูˆุณุท (21 ุดู…ุนุฉ): ู„ู„ุงุชุฌุงู‡ุงุช ู…ุชูˆุณุทุฉ ุงู„ุฃู…ุฏ.
- ู‚ุตูŠุฑ (9 ุดู…ูˆุน): ู„ู„ุงุชุฌุงู‡ุงุช ู‚ุตูŠุฑุฉ ุงู„ุฃู…ุฏ.
2. ุงูƒุชุดุงู ุงู„ูƒุณูˆุฑ: ูŠุฑุตุฏ ุงุฎุชุฑุงู‚ ุงู„ุณุนุฑ ู„ู„ุฎุทูˆุท ู…ุน ูู„ุงุชุฑ ู„ุชู‚ู„ูŠู„ ุงู„ุฅุดุงุฑุงุช ุงู„ูƒุงุฐุจุฉ.
3. ูู„ุงุชุฑ ุงู„ุชุฃูƒูŠุฏ:
- ADX (>20): ูŠุคูƒุฏ ู‚ูˆุฉ ุงู„ุงุชุฌุงู‡.
- RSI (65/35): ูŠุชุฌู†โ€œBโ€ ู„ู„ุฑุฆูŠุณูŠุŒ โ€œMโ€ ู„ู„ู…ุชูˆุณุทุŒ โ€œSโ€ ู„ู„ู‚ุตูŠุฑ).
4. ุฅุนุฏุงุฏุงุช ู…ุฑู†ุฉ: ุชุฎุตูŠุต ุงู„ุฃู„ูˆุงู†ุŒ ุงู„ุฃู†ู…ุงุท (ู…ุชุตู„ุŒ ู…ุชู‚ุทุนุŒ ู…ู†ู‚ุท)ุŒ ูˆู†ูˆุน ุงู„ุณุนุฑ (ุฅุบู„ุงู‚ุŒ ุฃุนู„ู‰ุŒ ุฃุฏู†ู‰).
5. ุชู…ุฏูŠุฏ ุงู„ุฎุทูˆุท: ูŠู…ุฏุฏ ุงู„ุฎุทูˆุท ุชู„ู‚ุงุฆูŠู‹ุง ุญุชู‰ ุงู„ูƒุณุฑ.

2. ุทุฑู‚ ุฑุณู… ุงู„ุฎุทูˆุท
1. ู†ู‚ุงุท Pivot: ุชุญุฏูŠุฏ ุงู„ู†ู‚ุงุท ุงู„ุนู„ูŠุง (ู„ู„ุฎุทูˆุท ุงู„ู‡ุงุจุทุฉ) ูˆุงู„ุฏู†ูŠุง (ู„ู„ุตุงุนุฏุฉ) ุจุงุณุชุฎุฏุงู… ูุชุฑุงุช ุฒู…ู†ูŠุฉ (50ุŒ 21ุŒ 9).
2. ุญุณุงุจ ุงู„ู…ูŠู„: ู‚ุณู…ุฉ ูุฑู‚ ุงู„ุณุนุฑ ุนู„ู‰ ูุฑู‚ ุงู„ุดู…ูˆุน (ู…ูŠู„ ุณุงู„ุจ ู„ู‡ุงุจุทุŒ ู…ูˆุฌุจ ู„ุตุงุนุฏ).
3. ุฑุณู… ุงู„ุฎุทูˆุท: ุฎุท ุฃุณุงุณูŠ ูŠุฑุจุท ู†ู‚ุทุชูŠ PivotุŒ ูˆุฎุท ู…ู…ุชุฏ ุฅู„ู‰ ุงู„ุดู…ุนุฉ ุงู„ุญุงู„ูŠุฉ.
4. ุงู„ุชู…ุฏูŠุฏ: ูŠุณุชู…ุฑ ุงู„ุชู…ุฏูŠุฏ ุฅุฐุง ู„ู… ูŠููƒุณุฑ ุงู„ุฎุท.

3. ุดุฑูˆุท ุงู„ุฑุณู…
1. ูˆุฌูˆุฏ ู†ู‚ุทุชูŠู† Pivot ุถู…ู† ูุชุฑุฉ (โ‰ค5 ุฃุถุนุงู ุทูˆู„ ุงู„ุฎุท).
2. ู…ูŠู„ ู…ู†ุงุณุจ (ุณุงู„ุจ ู„ู‡ุงุจุทุŒ ู…ูˆุฌุจ ู„ุตุงุนุฏ).
3. ุงู„ูˆุถุน ุงู„ุตุงุฑู…: ุงู„ุณุนุฑ ู„ุง ูŠุฎุชุฑู‚ ุงู„ุฎุท ุจูŠู† ุงู„ู†ู‚ุทุชูŠู†.
4. ูุญุต ู…ุง ุจุนุฏ ุงู„ู†ู‚ุทุฉ: ุนุฏู… ุงุฎุชุฑุงู‚ ุงู„ุฎุท ุจุนุฏ ุงู„ู†ู‡ุงูŠุฉ.
5. ุชู…ุฏูŠุฏ ุตุงุฑู…: ุงู„ุณุนุฑ ู„ุง ูŠุฎุชุฑู‚ ุงู„ุฎุท ุงู„ู…ู…ุชุฏ.

4. ุดุฑูˆุท ุงู„ูƒุณุฑ
1. ุงุฎุชุฑุงู‚ ุงู„ุณุนุฑ ู„ู„ุฎุท (ููˆู‚ ุงู„ู‡ุงุจุทุŒ ุชุญุช ุงู„ุตุงุนุฏ).
2. ุชุฃูƒูŠุฏ ุงู„ุดู…ุนุฉ (ู…ุบู„ู‚ุฉ).
3. ูู„ุงุชุฑ:
- ุญุฌู… ุฃุนู„ู‰ ู…ู† ุงู„ู…ุชูˆุณุทุŒ ู…ุน ุดู…ุนุฉ ุฎุถุฑุงุก (ู„ู„ุตุงุนุฏ) ุฃูˆ ุญู…ุฑุงุก (ู„ู„ู‡ุงุจุท).
- ADX > 20.
- RSI: โ‰ค65 (ุตุงุนุฏ)ุŒ โ‰ฅ35 (ู‡ุงุจุท).
4. ูƒุณุฑ ูˆุงุญุฏ ู„ูƒู„ ุฎุท.

5. ู…ู„ุงุญุธุงุช
- ุงู„ุนุฑุถ: ุฎูŠุงุฑุงุช ู„ุฅุฎูุงุก ุงู„ุฎุทูˆุท ุงู„ุณุงุจู‚ุฉ ูˆุชุฎุตูŠุต ุงู„ุชุณู…ูŠุงุช.
- ุงู„ุชู†ุจูŠู‡ุงุช: ุชู†ุจูŠู‡ุงุช ููˆุฑูŠุฉ ู…ุน ุชูุงุตูŠู„ ุงู„ูู„ุงุชุฑ.

ุฅุฎู„ุงุก ุงู„ู…ุณุคูˆู„ูŠุฉ
ู„ุง ูŠูู‚ุตุฏ ุจุงู„ู…ุนู„ูˆู…ุงุช ูˆุงู„ู…ู†ุดูˆุฑุงุช ุฃู† ุชูƒูˆู†ุŒ ุฃูˆ ุชุดูƒู„ุŒ ุฃูŠ ู†ุตูŠุญุฉ ู…ุงู„ูŠุฉ ุฃูˆ ุงุณุชุซู…ุงุฑูŠุฉ ุฃูˆ ุชุฌุงุฑูŠุฉ ุฃูˆ ุฃู†ูˆุงุน ุฃุฎุฑู‰ ู…ู† ุงู„ู†ุตุงุฆุญ ุฃูˆ ุงู„ุชูˆุตูŠุงุช ุงู„ู…ู‚ุฏู…ุฉ ุฃูˆ ุงู„ู…ุนุชู…ุฏุฉ ู…ู† TradingView.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.