Biên tập viên chọn
OPEN-SOURCE SCRIPT

Adaptive Candlestick Pattern Recognition System

Cập nhật
INTRODUCTION

Nearly three years in the making, intermittently worked on in the few spare hours of weekends and time off, this is a passion project I undertook to flesh out my skills as a computer programmer. This script currently recognizes 85 different candlestick patterns ranging from one to five candles in length. It also performs statistical analysis on those patterns to determine prior performance and changes the coloration of those patterns based on that performance. In searching TradingView's script library for scripts similar to this one, I had found a handful. However, when I reviewed the ones which were open source, I did not see many that truly captured the power of PineScrypt or leveraged the way it works to create efficient and reliable code; one of the main driving factors for releasing this 5,000+ line behemoth open sourced.

Please take the time to review this description and source code to utilize this script to its fullest potential.

CONCEPTS

This script covers the following topics: Candlestick Theory, Trend Direction, Higher Timeframes, Price Analysis, Statistic Analysis, and Code Design.

Candlestick Theory - This script focuses solely on the concept of Candlestick Theory: arrangements of candlesticks may form certain patterns that can potentially influence the future price action of assets which experience those patterns. A full list of patterns (grouped by pattern length) will be in its own section of this description. This script contains two modes of operation for identifying candlestick patterns, 'CLASSIC' and 'BREAKOUT'.

CLASSIC: In this mode, candlestick patterns will be identified whenever they appear. The user has a wide variety of inputs to manipulate that can change how certain patterns are identified and even enable alerts to notify themselves when these patterns appear. Each pattern selected to appear will have their Profit or Loss (P/L) calculated starting from the first candle open succeeding the pattern to a candle close specified some number of candles ahead. These P/L calculations are then collected for each pattern, and split among partitions of prior price action of the asset the script is currently applied to (more on that in Higher Timeframes).

BREAKOUT: In this mode, P/L calculations are held off until a breakout direction has been confirmed. The user may specify the number of candles ahead of a pattern's appearance (from one to five) that a pattern has to confirm a breakout in either an upward or downward direction. A breakout is constituted when there is a candle following the appearance of the pattern that closes above/at the highest high of the pattern, or below/at its lowest low. Only then will percent return calculations be performed for the pattern that's been identified, and these percent returns are broken up not only by the partition they had appeared in but also by the breakout direction itself. Patterns which do not breakout in either direction will be ignored, along with having their labels deleted.

In both of these modes, patterns may be overridden. Overrides occur when a smaller pattern has been detected and ends up becoming one (or more) of the candles of a larger pattern. A key example of this would be the Bearish Engulfing and the Three Outside Down patterns. A Three Outside Down necessitates a Bearish Engulfing as the first two candles in it, while the third candle closes lower. When a pattern is overridden, the return for that pattern will no longer be tracked. Overrides will not occur if the tail end of a larger pattern occurs at the beginning of a smaller pattern (Ex: a Bullish Engulfing occurs on the third candle of a Three Outside Down and the candle immediately following that pattern, the Three Outside Down pattern will not be overridden).

Important Functionality Note: These patterns are only searched for at the most recently closed candle, not on the currently closing candle, which creates an offset of one for this script's execution. (SEE LIMITATIONS)

Trend Direction - Many of the patterns require a trend direction prior to their appearance. Noting TradingView's own publication of candlestick patterns, I utilize a similar method for determining trend direction. Moving Averages are used to determine which trend is currently taking place for candlestick patterns to be sought out. The user has access to two Moving Averages which they may individually modify the following for each: Moving Average type (list of 9), their length, width, source values, and all variables associated with two special Moving Averages (Least Squares and Arnaud Legoux).

There are 3 settings for these Moving Averages, the first two switch between the two Moving Averages, and the third uses both. When using individual Moving Averages, the user may select a 'price point' to compare against the Moving Average (default is close). This price point is compared to the Moving Average at the candles prior to the appearance of candle patterns. Meaning: The close compared to the Moving Average two candles behind determines the trend direction used for Candlestick Analysis of one candle patterns; three candles behind for two candle patterns and so on. If the selected price point is above the Moving Average, then the current trend is an 'uptrend', 'downtrend' otherwise.

The third setting using both Moving Averages will compare the lengths of each, and trend direction is determined by the shorter Moving Average compared to the longer one. If the shorter Moving Average is above the longer, then the current trend is an 'uptrend', 'downtrend' otherwise. If the lengths of the Moving Averages are the same, or both Moving Averages are Symmetrical, then MA1 will be used by default. (SEE LIMITATIONS)

Higher Timeframes - This script employs the use of Higher Timeframes with a few request.security calls. The purpose of these calls is strictly for the partitioning of an asset's chart, splitting the returns of patterns into three separate groups. The four inputs in control of this partitioning split the chart based on: A given resolution to grab values from, the length of time in that resolution, and 'Upper' and 'Lower Limits' which split the trading range provided by that length of time in that resolution that forms three separate groups. The default values for these four inputs will partition the current chart by the yearly high-low range where: the 'Upper' partition is the top 20% of that trading range, the 'Middle' partition is 80% to 33% of the trading range, and the 'Lower' partition covers the trading range within 33% of the yearly low.

Patterns which are identified by this script will have their returns grouped together based on which partition they had appeared in. For example, a Bullish Engulfing which occurs within a third of the yearly low will have its return placed separately from a Bullish Engulfing that occurred within 20% of the yearly high. The idea is that certain patterns may perform better or worse depending on when they had occurred during an asset's trading range.

Price Analysis - Price Analysis is a major part of this script's functionality as it can fundamentally change how patterns are shown to the user. The settings related to Price Analysis include setting the number of candles ahead of a pattern's appearance to determine the return of that pattern. In 'BREAKOUT' mode, an additional setting allows the user to specify where the P/L calculation will begin for a pattern that had appeared and confirmed. (SEE LIMITATIONS)

The calculation for percent returns of patterns is illustrated with the following pseudo-code (CLASSIC mode, this is a simplified version of the actual code):



Statistic Analysis - This script uses Pine's built-in array functions to conduct the Statistic Analysis for patterns. When a pattern is found and its P/L calculation is complete, its return is added to a 'Return Array' User-Defined-Type that contains numerous fields which retain information on a pattern's prior performance. The actual UDT is as follows:



All values within this UDT will be updated when a return is added to it (some based on user input). The array.avg, array.median and array.stdev will be ran and saved into their respective fields after a return is placed in the 'returns' array. The 'polarities' integer array is what will be changed based on user input. The user specifies two different percentages that declare 'Positive' and 'Negative' returns for patterns. When a pattern returns above, below, or in between these two values, different indices of this array will be incremented to reflect the kind of return that pattern had just experienced.

These values (plus the full name, partition the pattern occurred in, and a 95% confidence interval of expected returns) will be displayed to the user on the tooltip of the labels that identify patterns. Simply scroll over the pattern label to view each of these values.

Code Design - Overall this script is as much of an art piece as it is functional. Its design features numerous depictions of ASCII Art that illustrate what is being attempted by the functions that identify patterns, and an incalculable amount of time was spent rewriting portions of code to improve its efficiency. Admittedly, this final version is nearly 1,000 lines shorter than a previous version (one which took nearly 30 seconds after compilation to run, and didn't do nearly half of what this version does). The use of UDTs, especially the 'patternObj' one crafted and redesigned from the Hikkake Hunter 2.0 I published last month, played a significant role in making this script run efficiently. There is a slight rigidity in some of this code mainly around pattern IDs which are responsible for displaying the abbreviation for patterns (as well as the full names under the tooltips, and the matrix row position for holding returns), as each is hard-coded to correspond to that pattern.

However, one thing I would like to mention is the extensive use of global variables for pattern detection. Many scripts I had looked over for ideas on how to identify candlestick patterns had the same idea; break the pattern into a set of logical 'true/false' statements derived from historically referencing candle OHLC values. Some scripts which identified upwards of 20 to 30 patterns would reference Pine's built-in OHLC values for each pattern individually, potentially requesting information from TradingView's servers numerous times that could easily be saved into a variable for re-use and only requested once per candle (what this script does).

FEATURES

This script features a massive amount of switches, options, floating point values, detection settings, and methods for identifying/tailoring pattern appearances. All modifiable inputs for patterns are grouped together based on the number of candles they contain. Other inputs (like those for statistics settings and coloration) are grouped separately and presented in a way I believe makes the most sense.

Not mentioned above is the coloration settings. One of the aims of this script was to make patterns visually signify their behavior to the user when they are identified. Each pattern has its own collection of returns which are analyzed and compared to the inputs of the user. The user may choose the colors for bullish, neutral, and bearish patterns. They may also choose the minimum number of patterns needed to occur before assigning a color to that pattern based on its behavior; a color for patterns that have not met this minimum number of occurrences yet, and a color for patterns that are still processing in BREAKOUT mode.

There are also an additional three settings which alter the color scheme for patterns: Statistic Point-of-Reference, Adaptive coloring, and Hard Limiting. The Statistic Point-of-Reference decides which value (average or median) will be compared against the 'Negative' and 'Positive Return Tolerance'(s) to guide the coloration of the patterns (or for Adaptive Coloring, the generation of a color gradient).

Adaptive Coloring will have this script produce a gradient that patterns will be colored along. The more bullish or bearish a pattern is, the further along the gradient those patterns will be colored starting from the 'Neutral' color (hard lined at the value of 0%: values above this will be colored bullish, bearish otherwise). When Adaptive Coloring is enabled, this script will request the highest and lowest values (these being the Statistic Point-of-Reference) from the matrix containing all returns and rewrite global variables tied to the negative and positive return tolerances. This means that all patterns identified will be compared with each other to determine bullish/bearishness in Adaptive Coloring.

Hard Limiting will prevent these global variables from being rewritten, so patterns whose Statistic Point-of-Reference exceed the return tolerances will be fully colored the bullish or bearish colors instead of a generated gradient color. (SEE LIMITATIONS)

Apart from the Candle Detection Modes (CLASSIC and BREAKOUT), there's an additional two inputs which modify how this script behaves grouped under a "MASTER DETECTION SETTINGS" tab. These two "Pattern Detection Settings" are 'SWITCHBOARD' and 'TARGET MODE'.

SWITCHBOARD: Every single pattern has a switch that is associated with its detection. When a switch is enabled, the code which searches for that pattern will be run. With the Pattern Detection Setting set to this, all patterns that have their switches enabled will be sought out and shown.

TARGET MODE: There is an additional setting which operates on top of 'SWITCHBOARD' that singles out an individual pattern the user specifies through a drop down list. The names of every pattern recognized by this script will be present along with an identifier that shows the number of candles in that pattern (Ex: "[PATTERN NAME] (# candles)"). All patterns enabled in the switchboard will still have their returns measured, but only the pattern selected from the "Target Pattern" list will be shown. (SEE LIMITATIONS)

The vast majority of other features are held in the one, two, and three candle pattern sections.

For one-candle patterns, there are:

3 — Settings related to defining 'Tall' candles:
  • The number of candles to sample for previous candle-size averages.
  • The type of comparison done for 'Tall' Candles: Settings are 'RANGE' and 'BODY'.
  • The 'Tolerance' for tall candles, specifying what percent of the 'average' size candles must exceed to be considered 'Tall'.


When 'Tall Candle Setting' is set to RANGE, the high-low ranges are what the current candle range will be compared against to determine if a candle is 'Tall'. Otherwise the candle bodies (absolute value of the close - open) will be compared instead. (SEE LIMITATIONS)

Hammer Tolerance - How large a 'discarded wick' may be before it disqualifies a candle from being a 'Hammer'.

Discarded wicks are compared to the size of the Hammer's candle body and are dependent upon the body's center position. Hammer bodies closer to the high of the candle will have the upper wick used as its 'discarded wick', otherwise the lower wick is used.

9 — Doji Settings, some pulled from an old Doji Hunter I made a while back:
  • Doji Tolerance - How large the body of a candle may be compared to the range to be considered a 'Doji'.
  • Ignore N/S Dojis - Turns off Trend Direction for non-special Dojis.
  • GS/DF Doji Settings - 2 Inputs that enable and specify how large wicks that typically disqualify Dojis from being 'Gravestone' or 'Dragonfly' Dojis may be.
  • 4 Settings related to 'Long Wick Doji' candles detailed below.
  • A Tolerance for 'Rickshaw Man' Dojis specifying how close the center of the body must be to the range to be valid.


The 4 settings the user may modify for 'Long Legged' Dojis are: A Sample Base for determining the previous average of wicks, a Sample Length specifying how far back to look for these averages, a Behavior Setting to define how 'Long Legged' Dojis are recognized, and a tolerance to specify how large in comparison to the prior wicks a Doji's wicks must be to be considered 'Long Legged'.

The 'Sample Base' list has two settings:

RANGE: The wicks of prior candles are compared to their candle ranges and the 'wick averages' will be what the average percent of ranges were in the sample.
WICKS: The size of the wicks themselves are averaged and returned for comparing against the current wicks of a Doji.

The 'Behavior' list has three settings:

ONE: Only one wick length needs to exceed the average by the tolerance for a Doji to be considered 'Long Legged'.
BOTH: Both wick lengths need to exceed the average of the tolerance of their respective wicks (upper wicks are compared to upper wicks, lower wicks compared to lower) to be considered 'Long Legged'.
AVG: Both wicks and the averages of the previous wicks are added together, divided by two, and compared. If the 'average' of the current wicks exceeds this combined average of prior wicks by the tolerance, then this would constitute a valid 'Long Legged' Doji. (For Dojis in general - SEE LIMITATIONS)

The final input is one related to candle patterns which require a Marubozu candle in them. The two settings for this input are 'INCLUSIVE' and 'EXCLUSIVE'. If INCLUSIVE is selected, any opening/closing variant of Marubozu candles will be allowed in the patterns that require them.

For two-candle patterns, there are:

2 — Settings which define 'Engulfing' parameters:
  • Engulfing Setting - Two options, RANGE or BODY which sets up how one candle may 'engulf' the previous.
  • Inclusive Engulfing - Boolean which enables if 'engulfing' candles can be equal to the values needed to 'engulf' the prior candle.


For the 'Engulfing Setting':

RANGE: If the second candle's high-low range completely covers the high-low range of the prior candle, this is recognized as 'engulfing'.
BODY: If the second candle's open-close completely covers the open-close of the previous candle, this is recognized as 'engulfing'. (SEE LIMITATIONS)

4 — Booleans specifying different settings for a few patterns:
  • One which allows for 'opens within body' patterns to let the second candle's open/close values match the prior candles' open/close.
  • One which forces 'Kicking' patterns to have a gap if the Marubozu setting is set to 'INCLUSIVE'.
  • And Two which dictate if the individual candles in 'Stomach' patterns need to be 'Tall'.


8 — Floating point values which affect 11 different patterns:
  • One which determines the distance the close of the first candle in a 'Hammer Inverted' pattern must be to the low to be considered valid.
  • One which affects how close the opens/closes need to be for all 'Lines' patterns (Bull/Bear Meeting/Separating Lines).
  • One that allows some leeway with the 'Matching Low' pattern (gives a small range the second candle close may be within instead of needing to match the previous close).
  • Three tolerances for On Neck/In Neck patterns (2 and 1 respectively).
  • A tolerance for the Thrusting pattern which give a range the close the second candle may be between the midpoint and close of the first to be considered 'valid'.
  • A tolerance for the two Tweezers patterns that specifies how close the highs and lows of the patterns need to be to each other to be 'valid'.


The first On Neck tolerance specifies how large the lower wick of the first candle may be (as a % of that candle's range) before the pattern is invalidated. The second tolerance specifies how far up the lower wick to the close the second candle's close may be for this pattern. The third tolerance for the In Neck pattern determines how far into the body of the first candle the second may close to be 'valid'.

For the remaining patterns (3, 4, and 5 candles), there are:

3 — Settings for the Deliberation pattern:
  • A boolean which forces the open of the third candle to gap above the close of the second.
  • A tolerance which changes the proximity of the third candle's open to the second candle's close in this pattern.
  • A tolerance that sets the maximum size the third candle may be compared to the average of the first two candles.


One boolean value for the Two Crows patterns (standard and Upside Gapping) that forces the first two candles in the patterns to completely gap if disabled (candle 1's close < candle 2's low).

10 — Floating point values for the remaining patterns:
  • One tolerance for defining how much the size of each candle in the Identical Black Crows pattern may deviate from the average of themselves to be considered valid.
  • One tolerance for setting how close the opens/closes of certain three candle patterns may be to each other's opens/closes.*
  • Three floating point values that affect the Three Stars in the South pattern.
  • One tolerance for the Side-by-Side patterns - looks at the second and third candle closes.
  • One tolerance for the Stick Sandwich pattern - looks at the first and third candle closes.
  • A floating value that sizes the Concealing Baby Swallow pattern's 3rd candle wick.
  • Two values for the Ladder Bottom pattern which define a range that the third candle's wick size may be.


* This affects the Three Black Crows (non-identical) and Three White Soldiers patterns, each require the opens and closes of every candle to be near each other.

The first tolerance of the Three Stars in the South pattern affects the first candle body's center position, and defines where it must be above to be considered valid. The second tolerance specifies how close the second candle must be to this same position, as well as the deviation the ratio the candle body to its range may be in comparison to the first candle. The third restricts how large the second candle range may be in comparison to the first (prevents this pattern from being recognized if the second candle is similar to the first but larger).

The last two floating point values define upper and lower limits to the wick size of a Ladder Bottom's fourth candle to be considered valid.

HOW TO USE

While there are many moving parts to this script, I attempted to set the default values with what I believed may help identify the most patterns within reasonable definitions. When this script is applied to a chart, the Candle Detection Mode (along with the BREAKOUT settings) and all candle switches must be confirmed before patterns are displayed. All switches are on by default, so this gives the user an opportunity to pick which patterns to identify first before playing around in the settings.

All of the settings/inputs described above are meant for experimentation. I encourage the user to tweak these values at will to find which set ups work best for whichever charts they decide to apply these patterns to.

Refer to the patterns themselves during experimentation. The statistic information provided on the tooltips of the patterns are meant to help guide input decisions. The breadth of candlestick theory is deep, and this was an attempt at capturing what I could in its sea of information.

LIMITATIONS

DISCLAIMER: While it may seem a bit paradoxical that this script aims to use past performance to potentially measure future results, past performance is not indicative of future results. Markets are highly adaptive and often unpredictable. This script is meant as an informational tool to show how patterns may behave. There is no guarantee that confidence intervals (or any other metric measured with this script) are accurate to the performance of patterns; caution must be exercised with all patterns identified regardless of how much information regarding prior performance is available.

Candlestick Theory - In the name, Candlestick Theory is a theory, and all theories come with their own limits. Some patterns identified by this script may be completely useless/unprofitable/unpredictable regardless of whatever combination of settings are used to identify them. However, if I truly believed this theory had no merit, this script would not exist. It is important to understand that this is a tool meant to be utilized with an array of others to procure positive (or negative, looking at you, short sellers) results when navigating the complex world of finance.

To address the functionality note however, this script has an offset of 1 by default. Patterns will not be identified on the currently closing candle, only on the candle which has most recently closed. Attempting to have this script do both (offset by one or identify on close) lead to more trouble than it was worth. I personally just want users to be aware that patterns will not be identified immediately when they appear.

Trend Direction - Moving Averages - There is a small quirk with how MA settings will be adjusted if the user inputs two moving averages of the same length when the "MA Setting" is set to 'BOTH'. If Moving Averages have the same length, this script will default to only using MA 1 regardless of if the types of Moving Averages are different. I will experiment in the future to alleviate/reduce this restriction.

Price Analysis - BREAKOUT mode - With how identifying patterns with a look-ahead confirmation works, the percent returns for patterns that break out in either direction will be calculated on the same candle regardless of if P/L Offset is set to 'FROM CONFIRMATION' or 'FROM APPEARANCE'. This same issue is present in the Hikkake Hunter script mentioned earlier. This does not mean the P/L calculations are incorrect, the offset for the calculation is set by the number of candles required to confirm the pattern if 'FROM APPEARANCE' is selected. It just means that these two different P/L calculations will complete at the same time independent of the setting that's been selected.

Adaptive Coloring/Hard Limiting - Hard Limiting is only used with Adaptive Coloring and has no effect outside of it. If Hard Limiting is used, it is recommended to increase the 'Positive' and 'Negative' return tolerance values as a pattern's bullish/bearishness may be disproportionately represented with the gradient generated under a hard limit.

TARGET MODE - This mode will break rules regarding patterns that are overridden on purpose. If a pattern selected in TARGET mode would have otherwise been absorbed by a larger pattern, it will have that pattern's percent return calculated; potentially leading to duplicate returns being included in the matrix of all returns recognized by this script.

'Tall' Candle Setting - This is a wide-reaching setting, as approximately 30 different patterns or so rely on defining 'Tall' candles. Changing how 'Tall' candles are defined whether by the tolerance value those candles need to exceed or by the values of the candle used for the baseline comparison (RANGE/BODY) can wildly affect how this script functions under certain conditions. Refer to the tooltip of these settings for more information on which specific patterns are affected by this.

Doji Settings - There are roughly 10 or so two to three candle patterns which have Dojis as a part of them. If all Dojis are disabled, it will prevent some of these larger patterns from being recognized. This is a dependency issue that I may address in the future.

'Engulfing' Setting - Functionally, the two 'Engulfing' settings are quite different. Because of this, the 'RANGE' setting may cause certain patterns that would otherwise be valid under textbook and online references/definitions to not be recognized as such (like the Upside Gap Two Crows or Three Outside down).

PATTERN LIST

This script recognizes 85 patterns upon initial release. I am open to adding additional patterns to it in the future and any comments/suggestions are appreciated. It recognizes:

15 — 1 Candle Patterns
  • 4 Hammer type patterns: Regular Hammer, Takuri Line, Shooting Star, and Hanging Man
  • 9 Doji Candles: Regular Dojis, Northern/Southern Dojis, Gravestone/Dragonfly Dojis, Gapping Up/Down Dojis, and Long-Legged/Rickshaw Man Dojis
  • White/Black Long Days

32 — 2 Candle Patterns
  • 4 Engulfing type patterns: Bullish/Bearish Engulfing and Last Engulfing Top/Bottom
  • Dark Cloud Cover
  • Bullish/Bearish Doji Star patterns
  • Hammer Inverted
  • Bullish/Bearish Haramis + Cross variants
  • Homing Pigeon
  • Bullish/Bearish Kicking
  • 4 Lines type patterns: Bullish/Bearish Meeting/Separating Lines
  • Matching Low
  • On/In Neck patterns
  • Piercing pattern
  • Shooting Star (2 Lines)
  • Above/Below Stomach patterns
  • Thrusting
  • Tweezers Top/Bottom patterns
  • Two Black Gapping
  • Rising/Falling Window patterns

29 — 3 Candle Patterns
  • Bullish/Bearish Abandoned Baby patterns
  • Advance Block
  • Collapsing Doji Star
  • Deliberation
  • Upside/Downside Gap Three Methods patterns
  • Three Inside/Outside Up/Down patterns (4 total)
  • Bullish/Bearish Side-by-Side patterns
  • Morning/Evening Star patterns + Doji variants
  • Stick Sandwich
  • Downside/Upside Tasuki Gap patterns
  • Three Black Crows + Identical variation
  • Three White Soldiers
  • Three Stars in the South
  • Bullish/Bearish Tri-Star patterns
  • Two Crows + Upside Gap variant
  • Unique Three River Bottom

3 — 4 Candle Patterns
  • Concealing Baby Swallow
  • Bullish/Bearish Three Line Strike patterns

6 — 5 Candle Patterns
  • Bullish/Bearish Breakaway patterns
  • Ladder Bottom
  • Mat Hold
  • Rising/Falling Three Methods patterns


WORKS CITED

Because of the amount of time needed to complete this script, I am unable to provide exact dates for when some of these references were used. I will also not provide every single reference, as citing a reference for each individual pattern and the place it was reviewed would lead to a bibliography larger than this script and its description combined. There were five major resources I used when building this script, one book, two websites (for various different reasons including patterns, moving averages, and various other articles of information), various scripts from TradingView's public library (including TradingView's own source code for *all* candle patterns), and PineScrypt's reference manual.

Bulkowski, Thomas N. Encyclopedia of Candlestick Patterns. Hoboken, New Jersey: John Wiley & Sons Inc., 2008. E-book (google books).

Various. Numerous webpages. CandleScanner. 2023. online. Accessed 2020 - 2023.

Various. Numerous webpages. Investopedia. 2023. online. Accessed 2020 - 2023.

AKNOWLEDGEMENTS

I want to take the time here to thank all of my friends and family, both online and in real life, for the support they've given me over the last few years in this endeavor. My pets who tried their hardest to keep me from completing it. And work for the grit to continue pushing through until this script's completion.

This belongs to me just as much as it does anyone else. Whether you are an institutional trader, gold bug hedging against the dollar, retail ape who got in on a squeeze, or just parents trying to grow their retirement/save for the kids. This belongs to everyone.

Private Beta for new features to be tested can be found here.

Vires In Numeris
Phát hành các Ghi chú
Minor bug fix: Trend Directions for The Bearish Three Line Strike, Bullish Breakaway, and Rising Three Methods had been overlooked. Disabling the counter-pattern to each of these would have caused these patterns to appear in the wrong trend.
Phát hành các Ghi chú
Clean Chart update
Phát hành các Ghi chú
(Bug Found - script breaking) - There was an issue I had found with appending the tooltips of labels with the percent returns of patterns. If the barstate is not tracked appending the percent return, it will continually add new percent returns to the pattern label's tooltip, exceeding the maximum number of characters this string may be and causing this script to stop working until it is refreshed or until that pattern is past the P/L Sample length.

FUNCTIONALITY CHANGE - This additional barstate check will now cause this script to fire an alert and append the tooltip with the percent return only when the current candle the % P/L calculation is being conducted on closes.

LIMITATION OF CHANGE - The barstate itself will yield true for the current candle when it has closed however: price may continue to change after a candle has closed, potentially causing multiple returns to be appended to the tooltips of labels for patterns identified on realtime bars.

"Realtime" bars are any candles that have closed on the chart without switching the chart* or refreshing the page*. The fix for multiple percent returns on the tooltips is simply to do one of these* actions.
Phát hành các Ghi chú
(Bug Discovered - 'BREAKOUT' mode) - There is currently a bug in 'BREAKOUT' mode which causes multiple patterns confirmed on the same candle to not register P/L calculations for some of those patterns, BREAKOUT mode will be disabled until a fix has been found.
Phát hành các Ghi chú
FOR IMMEDIATE RELEASE

(Functionality Update) - Added 'BOTH' setting to the "Engulfing Setting", this setting allows for both types of engulfing setups to be recognized simultaneously instead of choosing one or the other.
(Default Setting Change) - This Engulfing Setting has also had its default value to be set to 'BODY' and reflects the usual way patterns may be identified as 'Engulfing' instead. This may change how this script behaves, as certain patterns recognized before may change.
(Tolerances Adjusted) - The max value for one tolerance has been adjusted: Open/Close Tolerance (3 Candlesticks) (from 0.10 -> 0.35)

(New Functionality) - Input Error Handling: This removes certain global variables placed to handle certain problematic input. This script will now throw an error if the values set for maximum and minimum wick lengths of the Ladder Bottom's 4th candle are inverted. Additionally, other error handling includes problematic input with the 'FROM APPEARANCE' P/L Offset which restricts the use of P/L calculations until after the number of confirmation candles has passed (effectively P/L Sample Length must be > the Max-To-Breakout input by at least 1 to run properly). May change in the future.

(Patterns Affected) - Bullish/Bearish and Last Top/Bottom engulfing patterns, Three Inside/Outside Up/Down patterns, and the Ladder Bottom.

(Hotfix - BREAKOUT mode) - This hotfix changes the linked-list object which kept track of all confirmed objects into a var array that will queue and dequeue items from the array when: They have been confirmed, and they have reached the end of their P/L lifespan. This was necessary because linked-lists currently do not work in Pine as I thought they originally had (from a UDT perspective). I discovered that UDTs may not pass-by-reference, meaning their contents may not change when passed to a function meant to change those contents. The work around instead was to keep track of the number of candles that remain in a pattern that's been confirmed, and decrement this value on each passing candle. When this value is 0, the P/L calculation is conducted and appended to the set of returns for that pattern. This now allows multiple patterns to be confirmed on the same candle and have their returns placed at the same time (albeit this causes duplicate returns to be added into the matrix of returns for more than one pattern when the P/L Offset is 'FROM CONFIRMATION').

The end result is that the returns for all patterns are now properly kept track of in BREAKOUT mode, whereas before there were some returns which may have been skipped over, potentially causing the statistics presented for patterns to not be representative of the set of returns for those patterns. BREAKOUT mode should now work as intended.
Phát hành các Ghi chú
(Minor bug fix) - Barstate being checked before adding stats onto label tooltip sometimes causes stats not to display on identified patterns until one more candle close after the pattern's appearance.
Phát hành các Ghi chú
(string overflow bug) - Seems to be the bug that refused to die, f_DisplayStatsOnLabel call has been moved to the f_SetupPattern function. For some reason, despite not showing signs of continuing to append onto the label tooltip, the call to the first function was causing an overflow bug on patterns that had just been identified when the chart was let sit for long enough on higher timeframes (1D mainly, but could also occur on the 4hr as well I noticed). This fix should only call the function once when the pattern has been identified and the UDT associated with it is created. The f_DisplayStats should now only be called in the main call block for BREAKOUT mode, as pattern breakout direction determines which statistics are presented for that pattern.
adaptiveCandlestick analysiscandlestickpatterncandlestickpatternbreakoutcandlestickpatternformationMoving Averagesmultitimeframepatternrecognitionsystemtheory

Mã nguồn mở

Theo tinh thần TradingView thực sự, tác giả của tập lệnh này đã xuất bản dưới dạng nguồn mở để các nhà giao dịch có thể hiểu và xác minh. Chúc mừng tác giả! Bạn có thể sử dụng miễn phí. Tuy nhiên, bạn cần sử dụng lại mã này theo Quy tắc nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?

Thông báo miễn trừ trách nhiệm