ChartPrime

Channels With Patterns [ChartPrime]

The Channels With Patterns indicator is an attempt at minimizing the delay in forming a trend channel. This indicator uses a single pivot in conjunction with a smooth version of the price to estimate the direction of an emerging trend. Using ATR, this indicator estimates the volatility of the new trend by adjusting the channel size by a multiple of the current ATR.

One of the biggest complains for any trend indicator is that it takes too long to create a channel or trend line. This indicator estimates the trend channel by checking if the price is moving in the correct direction and then it projects the channel from a single pivot. To allow for some margin of error, this script uses an offset to help center the channel.

This offset is generated from the ATR at the time of formation. In conjunction with forming estimated trend channels, this indicator features select candle stick patterns. These candle stick patterns are filtered by location in the formed trend channel. If the price is within an extremity of the trend channel it will appear. Filtering classical vanilla candle stick patterns using this methodology can result in some interesting results and possible confluence points for traders. For example; a bearish hammer appearing when filtered in an upper zone might add an extra level of realtime unique confluence traders.


Traders can use this script as a general trend line indicator that is a bit more forward looking than others, or it can be used it as its full blown trend channel estimator. Due to the fact that this is an estimate using the minimum possible information to make the channel, its accuracy will not always be perfect and can suffer compared to alternative methods.


When configuring the indicator it is important to understand the role of each input. Here is a description of all of the settings provided:

Presets (`preset`): This input allows users to quickly configure the indicator based on the market they are trading in. Selecting "Stocks," "Forex," or "Crypto" automatically adjusts various parameters to settings deemed optimal for these markets. The "User" option lets traders manually configure settings for a more personalized approach.

Style (`style`): This setting determines how pivot points are calculated. "Wick" uses the high and low of candlesticks (including wicks), which can be more sensitive to market extremes. "Body" uses only the open and close prices (the body of the candlesticks), potentially offering a more stable pivot point calculation.

Break Style (`break_style`): This option defines what price is used to determine if a channel has been broken. "Close" uses the closing price of a candlestick, while "High/Low" uses the highest and lowest prices. This affects how channel breaks are identified and can influence trading signals.

Instant Mode (`instant`): When enabled, this feature allows the indicator to form channels more quickly by initiating them as soon as potential formations are detected. This can provide earlier signals but may increase the risk of false positives.

ATR Length (`atr_length`): This input sets the period for the Average True Range (ATR), a common volatility indicator. A longer ATR period may smooth out the channel but could delay responsiveness to market changes. A shorter period might make the channel more responsive but potentially more erratic.

Offset Center (`offset`): Adjusts the vertical positioning of the channel. This can help in aligning the channel more accurately with the price action, depending on market conditions and personal trading strategies.

Size (`atr_multiplier`): Alters the channel's size relative to the ATR. A higher multiplier makes a wider channel, which might be useful in more volatile markets. A lower multiplier tightens the channel, which could be better for less volatile conditions.

Padding % (`padding`): This setting adjusts the padding within the top and bottom quarters of the channel. It essentially fine-tunes the channel's sensitivity to price movements near its boundaries.

Pivot Length (`pivot_length`): Determines the number of bars used to calculate pivot points. A longer length may provide more significant pivot points but can reduce the number of channels formed.

Pivot Look Forward (`look_forward`): Sets the number of bars to look forward in the pivot calculation, affecting how quickly the channel adapts to new pivots.

Average H/L Length (`avg_length`): Controls the smoothing of the high and low prices used in the channel calculation. A longer average length can lead to smoother, more gradual channel slopes.

Enable Hammer (`enable_hammer`): When enabled, the indicator will highlight Hammer candlestick patterns, which are often considered bullish reversal indicators.

Enable Inverted Hammer (`enable_ihammer`): This toggles the display of Inverted Hammer patterns, typically viewed as potential bullish reversal signals.

Enable Bullish Engulfing (`enable_bullish_engulfing`): Enables the identification of Bullish Engulfing patterns, another type of bullish reversal indicator.

Enable Bearish Engulfing (`enable_bearish_engulfing`): When activated, this highlights Bearish Engulfing patterns, which are often interpreted as bearish reversal signals.

Extend Channel (`extend`): This option, when enabled, extends the drawn channels forward until they are either broken or a new channel is formed.

Show Break Label (`show_break_label`): Toggles the display of labels indicating where the channel has been broken, providing visual cues for potential trade entries or exits.

Channel History Length (`history_length`): Determines how many historical channels are displayed on the chart. This can be useful for analyzing past performance and patterns.

Channel Colors (`top_color`, `bottom_color`, `center_color`): These settings allow customization of the channel's appearance by setting the colors of the top, bottom, and center lines.

Line Transparency (`line_trans`): Adjusts the transparency of the channel lines, helping to balance visibility with chart readability.

Center Line Transparency (`center_trans`): Specifically sets the transparency level of the center line of the channel.

Channel Fill Transparency (`fill_trans`): Modifies the transparency of the filled areas between the channel lines, which can enhance chart clarity and focus on the price action.

Break Colors (`break_up_color`, `break_down_color`): Sets the colors for labels that appear when the channel is broken, either upwards or downwards.

Break Label Text Color (`text_color`): Determines the color of the text in the break labels, enhancing readability based on the chart's background and color scheme.

Candle Pattern Colors (`h_color`, `ih_color`, `bullish_engulfing_color`, `bearish_engulfing_color`): These inputs allow for the customization of the colors used to highlight various candle patterns on the chart.

Candle Pattern Text Color (`candle_text_color`): Sets the color of the text for labels associated with candle pattern indicators.

Alerts (`new_channel_alert`, `break_alert`, `hammer_alert`, `ihammer_alert`, `bullish_engulfing_alert`, `bearish_engulfing_alert`): These toggles enable or disable alerts for different events, such as the formation of new channels, channel breaks, or the appearance of specific candle patterns. This feature is crucial for traders who rely on timely notifications for potential trading opportunities.


We have provided a few presets to allow you to get a feeling for how the indicator works with different settings easily. Here is a description of the settings used in each preset:

Stocks Preset:
Style: "Wick"
Break Style: False (High/Low)
Instant Mode: True
ATR Length: 10
Size (ATR Multiplier): 4
Pivot Length: 10
Pivot Look Forward: 15
Average H/L Length: 18

Forex Preset:
Style: "Wick"
Break Style: False (High/Low)
Instant Mode: True
ATR Length: 100
Size (ATR Multiplier): 5
Pivot Length: 10
Pivot Look Forward: 15
Average H/L Length: 18

Crypto Preset:
Style: "Wick"
Break Style: False (High/Low)
Instant Mode: True
ATR Length: 10
Size (ATR Multiplier): 4
Pivot Length: 10
Pivot Look Forward: 15
Average H/L Length: 18


This script first starts by defining and collecting the relevant data for the main body of the code with data(). This generates the pivot data, the levels, the ranges, the averages, the deltas, and finally the candle sticks. Once there is a higher low, or lower high detected via the pivots and the current price it triggers the formation of the new channel. It takes the delta between the last pivot and the current average price and projects the trend channel using this delta. If the price exceeds the extremities of the channel it will classify this as a break from the estimated structure and begin looking for a new channel. The idea is that when trending, the price will oscillate between extremities as defined by a range and direction. If the price is inside of one of these extremities the script will look for candle stick patterns. This is how the script operates.

On a more technical level, this script is meant to showcase Pine Script's custom types and methods. We have made use of a properties pattern allows functions to use a minimal number of arguments. This allows you to add new inputs without modifying a string of functions. The use of methods and data structures allows the main body of the code to be easy to understand and for the script as a whole to be easily modified. We have made sure that the script is modular so that users can incorporate this into their own custom scripts. It should be easy to expand on this script as the main logic is fairly compact and open for easy modification. All features are packed into their own function for easy use elsewhere. This is particularly evident in the candle stick section. I have simplified the process of creating candle stick patterns by creating a type. All users have to do is make methods for this type.

candle()=>
    polarity = open < close

    body_top = math.max(open, close)
    body_bottom = math.min(open, close)

    body_range = body_top - body_bottom
    top_wick = high - body_top
    bottom_wick = body_bottom - low

    average_body = ta.ema(body_range, 14)
    average_top_wick = ta.ema(top_wick, 14)
    average_bottom_wick = ta.ema(bottom_wick, 14)

    has_body = body_range != 0
    has_top_wick = top_wick != 0
    has_bottom_wick = bottom_wick != 0

    above_average_body = body_range > average_body
    above_average_top_wick = top_wick > average_top_wick
    above_average_bottom_wick = bottom_wick > average_bottom_wick

    candle_data.new(
       polarity
     , body_top
     , body_bottom
     , body_range
     , top_wick
     , bottom_wick
     , average_body
     , average_top_wick
     , average_bottom_wick
     , has_body
     , has_top_wick
     , has_bottom_wick
     , above_average_body
     , above_average_top_wick
     , above_average_bottom_wick
     )

In conclusion, this script offers a blend of rapid trend channel formation and candlestick pattern recognition, making it a unique tool for traders looking for a more proactive approach to trend analysis.

סקריפט קוד פתוח

ברוח TradingView אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יכולים להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אך שימוש חוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.

רוצה להשתמש בסקריפ זה בגרף?