Auto Harmonic Pattern - Ultimate [Trendoscope]

Hello Traders, We are finally here. This is been my most ambitious and challenging project so far.

This is built on the basis of earlier harmonic pattern script Auto-Harmonic-Patterns-V2. In this version me and @CryptoArch_ have worked extensively to improve accuracy, performance, risk/reward ratio, and presentation/accuracy of stats. In short, we have tried to cover most of the shortfalls of previous version. While this will be our last script on Harmonic Patterns , it is certainly not the last update. Plenty of things can be added or improved and we will keep doing that.

About the script

Similar to Auto Harmonic Patterns V2, this script too is co-authored by myself and @CryptoArch_. But, we have decided to release this script as invite only script. We have also implemented additional security features due to which script will ask for Authorization key when you try to add script to the chart.

Accessing the script using Authorization key

When you add script to your chart, it will ask for authorization key to begin with. (This is done to overcome a bug with alerting system which many users are exploiting)

When you purchase subscription, along with adding users to invite only whitelist, we will also provide authorization key - which will be valid for the time of subscription. This key needs to be added to the prompt which comes up when you try to add indicator to the chart. Once this is done, you can save your chart and the key will remain as is.

Trial Users will not be provided with authorization key. They can still enter a wrong key and get into the script. But, script will only run for 5 bars. After 5 bars, script will stop working. But, you can refresh your chart to use the script for furhter 5 bars. Hence trial users will be able to use the script even without authorization key - but with a limitation that they need to refresh the chart once every 5 bars.

Once you pass initial authorization phase, script will be added on the chart

Following things are displayed by default on the chart

▶ Live patterns which are still in trade with XABCD and ratio labels.
▶ Entry, Stop and Target levels on chart for all live patterns.
▶ Open Trades Stat table - which again constitute details of each pattern, entry, stop and targets.
▶ Closed Trades Stat table - which contains statistics on closed trades based on zigzag as well as patterns.
▶ A bonus table is added to top right corner of the chart which suggests the immediate support and resistence level details.

When there are multiple patterns on chart, Entry, Stop, and Target labels and lines are created with specific distance from each other to provide clarity to the users. For example, take a look at Palladium hourly chart:


Lets talk about some of the settings. Most of these settings are already optimized and tested by us. Unless you have a specific trading plan which requires you to use specific things, these settings may not need any change.

Pattern Detection Settings

Search Depth - This setting says how many pivots to scan to find harmonic pattern . There are 4 different zigzag lengths availalble in the settings. Each zizgzag will have different search depth. First zigzag will scan for depth X 4 number of pivots . Second zigzag will scan for depth X 3 number of pivots . Third zigzag will scan for depth X 2 patterns whereas the 4th zigzag will scan for depth X 1 patterns.

So, if Depth is set as 10

Zigzag 1 (default length 5) will scan last 40 pivots for possible patterns.
Zigzag 2 (default length 8) will scan last 30 pivots for possible patterns.
Zigzag 3 (default length 13) will scan last 20 pivots for possible patterns.
Zigzag 4 (default length 21) will scan last 10 pivots for possible patterns.

This is done deliverately to avoid finding patterns which are too big and not tradeable and also to avoid error of not being able to draw lines to historical bars.

Error Percent - This is error tollerance for matching pattern ratios. We cannot expect price ratios to be exactly as per books. Hence, adding few error tolerance will help identify patterns better. By default this is set to 8. Can be reduced further if required.


Users can select upto 4 Zigzags. By default all are selected with default lengths - 5, 8, 13 and 21

Trailing and Targets

Trailing Start Stage - Defines when to start trailing stop-loss. It is recommended to set this value to either Target 1 or Target 2. Disabling the trailing or setting too far away may lead to being in trade on ranging market for too long. This may also result in drawing errors related to distance from current bar.

Custom Target Levels - Target and stop levels are set to optimal values based on individual patterns. If you want to override these levels, use the available input option to override targets and chose your custom Target1, Target2, Target3 and Target4

Patterns and Pattern Selection Methods

These settings give control to users to select only specific patterns. At present, number of patterns supported are same as that of Auto Harmonic Pattern V2. We will add more as and when we improve performance of our script.
However, this script has more ways in which you can select required patterns.

Selection types are categorised into 3 types
▶ Individual - Enable or Disable each pattern by its own. When individual mode is selected, Classic/Anti and Type Based inputs are ignored.
▶ Classic/Anti - Enable or Disable pattern by broad types - Classic or Anti/Alternate Patterns. When this option is selected, Individual pattern selections under CLASSIC PATTERNS and ANTI PATTERNS group is ignored. And also type based categorization is ignored.
▶ Type Based - Enable or Disable different types based on in relation to Elliot Waves. This mode is only for experts and do not use if you are not familiar with these types.

All Patterns
Classic Patterns

Anti Patterns
  • Anti Nenstar (Type I)
  • Anti Shark (Type II)
  • Anti Cypher (Type II)
  • Anti Crab (Type II)
  • Anti Butterfly (Type III)
  • Anti Bat (Type IV)
  • Anti Gartley (Type IV)
  • Navarro 200 (Type V)


These are the parameters which generate support/resistence table on the top right corner. These are not used in pattern recognisation. But, kept just to assist traders in making the decision to take the trades presented.

These stats are generated based on the indicator Divergence-Support-Resistence. But, instead of generating it for just one zigzag , we are looking at all 4 zigzags used for pattern detection. Users can select choice of their oscillators available in dropdown (By default RSI is selected). Ocillator lengths are automatically generated based on zigzag length with a constant multiplication factor. Users can also use an external oscillator as source to find out divergence based support-resistence.

Each zigzag will generate upto Max/ Zigzag levels. And only Max/Stats support and resistence levels are shown in the stats table. Stats table however displays total number of support and resistence levels. Higher number of support than resistence can be considered as good for going long whereas the reverse is good for taking short signals.

Miscelaneous Settings

Stats and Display - These settings can be used to manage display of stat table and patterns and positions.

Alerts - These setting help users to chose the type of alerts they want to receive. If you do not want to receive alerts on specific patterns, that can be achieved by disabling patterns in pattern settings before setting the alerts.

Generic Colors - These settings are kept in place to help users with light theme. Default settings are already inline with dark theme.

Stats in detail

Lets talk a bit about stats.

Dynamic Support Resistence

Snapshot of details shown in dynamic support/resistence levels are as below

Open Trade Stats

Open trade statistics are pretty straight forward. They represent each harmonic pattern and corresponding entry, stop and target levels.

Closed Trade Stats

Closed trade status display success/failure rate for patterns based on different zigzags, patterns based on bullish and bearish bias and for different individual patterns.

Definition of different states is defined as follows:
  • Failed - Patterns which reversed without touching the entry states. So, these are rather failed patterns than failed trades.
  • Stopped - These are the patterns which generated signal by crossing entry and then reversed to git the stop before reaching at least 1 target. These patters can be considered as failed trades.
  • Target (1-4) - These can considered as successful trades which at least crossed first target.
  • Total number of trades which includes trades stopped at all states for the category.

Alerts in detail

Alerts are genereated in standard JSON format. This can be used to integrate with trading bots with webhooks.

Alerts are generated when

Example of each type is captured in screenshot below

Possible Errors and how to tackle them

Similar to Auto Harmonic Patterns V2, this script too is highly CPU and memory intensive and may run into issues in this regard. We have seen errors such as

  • Drawing related errors where line cannot be drawn if it is referencing bars which are far back.
  • Execution time exceeds 40s
  • There may be ocassional 300ms loop error but we have not seen that in a while.

While the last two errors are pretty straight forward and may just have to restart execution of script or reload them, first problem is bit tricky to handle. In any case of errors - doing some or combination of following things may help avoid them

  • Disable higher length zigzags - if higher length zigzags are scanning too many bars back, there is high chance that pattern recognized will be failed to draw using pine commands
  • Reduce Search Depth or Error Percent- this will have the same impact as that of first point. But, instead ceasing one zigzag completely, it will impact all the zigzags selected. Use this if option 1 does not work or use it in conjunction with option 1
  • Unselect some of the patterns - This again may help if the error causing pattern is removed via this method. Use this as last option.

Special Thanks

  • Regular participants of Pine Chat Room who has helped me via interesting conversations and technical discussions.
  • Members of pro-pinecoders community who help me steer my ideas into right direction.
Release Notes: Updated without key run to 30 bars
Release Notes: Added Trade Direction filter based on feedback received.

This lets user filter patterns based on trade direction they are anticipating (long/short/all)

Updated Author's instructions with subscription details.
Release Notes: Added option to filter trades based on Support and Resistence levels.

If the option is enabled, pattern recognition skips patterns if the trade direction is not in confirmation with number of support resistence level. You can also pick filtering factor from the input as shown above. Filtering factor varies from -100 to +100
  • -100 is almost equivalend to disabling the filtering.
  • 0 means bullish trades are considered only if number of support levels are higher than that of resistence levels and bearish trades are considered only if number of resistence levels are higher than that of number of support levels.
  • +100 means bullish trades are considered only if there are no resistence levels above and bearish trades are considered only if there are no support levels below.
Release Notes: Further optimization done so that the pattern works even on 1 second chart 🔥🔥
Release Notes: Few updates.

▶ Instead of using zigzag colors on patterns, users now have option to use different color for each pattern. This will help recognize which stop, entry and target levels are corresponding to which pattern on the chart. Option is by default enabled. Disable this if you want zigzag based coloring.
▶ Some patterns had very wide PRZ box. Removed error ratio considerations on those patterns to fix this issue.
Release Notes: Few small updates

▶ Widened custom target ratios to allow lower values
▶ Small bug causing incorrect entry reached status on D bar is fixed.
▶ Update on display. Target levels are dimmed along with reducing size when they become irrelevent.

Release Notes: Updated small logical error related to Show XABCD and Show Ratios
Release Notes: Update depedent library version. Corrected minor error on cypher pattern combination.
Release Notes:
  • Updated trailing logic to trail by 2 levels instead of 1.
  • Fixed a small bug related to status update on long candles.
  • Added field "PreviousStatus" to status update alert
Release Notes:
  • Added TRIAL key by default. Subscription holders just need to use different key provided to them.
  • Added few fib levels to target ratios as per request.
Release Notes: Few updates with respect to visuals.

▶ Using a fixed range of colors for dark and light theme instead of generating random colors. This is because, some colors such as blue has lesser visibility in dark theme with same amount of light componenet. Hence, it is difficult to pick them randomly over HSL range.
▶ Added highlighting to present stop and next target values in open trades stat table.

It also comes with better combinations of light theme color combinations.
Release Notes: Added Timeframe field to all alerts.
Release Notes: Fixed alerts JSON error
Release Notes: ⬜ Few updates based on feedback

▶ Added few options to Show/hide closed stats selectively.

First Level of options are

  • Direction : Show closed stats for bullish and bearish patterns
  • Zigzag : Show closed stats based on zigzags
  • Pattern : Show closed stats based on pattern
These option allows to keep the closed stats to minimal or extensive based on the user preference.

Second level of options are about what to show in the Targets and Stops
  • Show Cumulative Targets : When this option is selected, Target 1 will show the cumulative count of all trades which reached target1. When disabled it shoes the targets which reached upto Target1 and hit stop without reaching target2. Similar calculations are done for Target 2, 3 and 4
  • Show In Percentage : Shows percentage of the stats rather than count.

Example of different representations are as shown below
Release Notes:
  • Added option to set extra padding for stop and entry to avoid fakeouts.
  • Target methods v1 and v2 are added. V1 corresponds to existing method whereas v2 contains further improvements in choosing targets.
  • Added trial watermark

Detailed A-Z settings guide created here: https://trendoscope.square.site/ahpu-settings-guide
Release Notes: Few bugfixes.
Release Notes: Added more vibrant colors and changes in settings look as below:

▶ Added option to limit max number of patterns on chart.
▶ I received review suggesting pattern selection screen is bit confusing. Hence, here is an attempt to simplify it a bit. As part of this.
  • Have removed pattern selection type parameter. All types are available.
  • Hence, appearance of pattern depends on what is not selected rather than what is selected.

For example, Gartley pattern will show only if All these options are checked.
  • Classic
  • Type1
  • Gartley

If at least one among these is not selected, then it will not show Gartley pattern.
Release Notes: ▶ Moved the key parameter towards the end of input parameter list as this is only required one time.
▶ Major update on alerts. Users now have option to add custom static tag in alerts. This custom tag can be used for auto-trading or third party alerting system. For example, users may chose to send things such as target application (Telegram or Discord channel id) or chart link etc.

Please note that, longer messages put in the custom field may impact the overall alert message. If there are things like character limit on alerts or third party applications, longer messages may cause truncation.
Release Notes: Minor update on trailing stop. Tightened trailing stop to avoid patterns lagging for longer time.
Release Notes: Few major changes

  • Making use of libraries to reduce burden on the single script. This includes libraries related to harmonicpatterns and arrayutils.
  • Added pattern name to open trades stat as per request.
Release Notes: Minor bugfixes.
Release Notes: Few bugfixes. Plus started adding version numbers so that users can distinguish new versions easily.
Release Notes: v24 Major updates

▶ Added time window for backtests

▶ Stats and display table - text size option added individually for each tables.

▶ Added timer widget which shows how much time and bars has elapsed with the script backtest.

Release Notes: V24.1 - Minor updates to few customer requests.
Release Notes: Minor Update Version 24.2

  • Updated library references
  • Few user requests on custom ratios
  • Error Percent increments are set to 1
Release Notes: Major updates:
  • Using eHarmonicpatterns library for efficient scanning
  • Updated library references to latest and related modifications
  • Alerts now contain syminfo.ticker instead of syminfo.tickerid. This is to avoid additional characters in specific future instruments
  • Enhanced S/R method to replicate the implementation of Auto Trendlines
Release Notes: V25.1

Let's make it bit colorful.

Added new settings to allow filling of harmonic triangles with pattern color.
Release Notes: V26 - Major updates in better PRZ calculation and update all libraries to latest.
Release Notes: Minor calculation updates.
Release Notes: V 26.2 - minor updates
Release Notes: V27 Major Updates
  • Option is added to show/hide XABCD in open stats
  • Stats table now also contains two more additional details - Trailing Risk/Reward and Live Risk/Reward

Trailing Risk Reward - Risk reward calculated with respect to trailing stop instead of initial stop. Previous target level is considered as entry. In short, Trailing RR is risk reward for entering at previous target to current target.
Live Risk Reward - Live risk reward updates on every tick. This is calculated based on current price as entry and current trailing stop as stoploss. So, at any point if you want to enter trade even after price has passed entry level, then you can refer to this stat to make your trading decisions.

Snapshot of settings added and the impact of these settings on open stats are as shown below.

Release Notes: U 1.0 Reboot

We are going to reboot the versioning for both AHPU and AHProjection due to major re-architecture of algorithm. This version also has several major updates.

🎲 Architectural update
Major re-architecture in our scanning algorithm allows us to scan more patterns without much compromise with respect to performance. With this change, 90% of the patterns or projections are identified with the first zigzag of length 5. Hence for better performance, disable other three zigzags from the settings.

We have also added option to set individual depths for each zigzag to give users better control on what they want to scan.

🎲 Fully customisable alerts are here!!
No more single static format alerts. You can customise the alerts the way you want. To make this happen, we have provided following placeholders.

▶ Common placeholders which are applicable for all alerts
{type} - Alert Type
- New Harmonic Pattern
- Harmonic Pattern Status Update
- Harmonic Pattern Trade Closure
{id} - Pattern Id. This is not fully unique id. But, this will be unique for all open trades. Once trade is closed, Ids are reused whenever feasible.
{ticker} - Ticker information
{timeframe} - Timeframe information
{price} - Current close price
{patterns} - Possible patterns for the projections or PRZ.
{direction} - Trade direction - Bullish or bearish
{entry} - Calculated entry for pattern
{stop} - Calculated stop for pattern
{tstop} - Trailing stop for the pattern in trade
{target1} - Target1 for pattern in trade
{target2} - Target2 for pattern in trade
{target3} - Target3 for pattern in trade
{target4} - Target4 for pattern in trade

▶ There are few specific placeholders, which are applicable for some alert types.
Harmonic Pattern Status Update
{status} - Status of the Pattern in trade
{laststatus} - Previous status of the Pattern in trade

Harmonic Pattern Trade Closure
{result} - Trade result upon closure

By default, the values of alert template is set to generate the json based alerts as before.

For example, if you are only concerned about getting alerts with pattern and direction information, all you need to do is, before setting the alerts, update these fields to:

type:{type}, ticker :{ticker}, patterns : {patterns}, direction : {direction}

When you do this, your alert will only contain this info, This also helps for algo traders to set alerts as per the specification of their bot services.
Release Notes: U1.1 Minor updates

  • Added option to select PRZ type. XAD range or BCD and XAD range. Default is XAD range.
  • Option added to select patterns which are having strict triangles without overflow.
  • Trail type - continuous or stepped option added.
  • Zigzag length removed from stats as it is redundant. And instead Id is added.
  • Updated library references.
Release Notes: U1.2
Had to reduce few conditional steps in order for script to work - which unfortunately broke without any changes.
Apologies for the inconvenience.
Release Notes: Version Update U1.3
  • Moved not so critical logic to libraries to make space for important stuff.
  • Library references updated
  • Removed few redundant things such as zigzag length, zigzag based colors etc.
  • Added more option to set alerts. Users can now enable/disable alerts for each status individually.

Alert options now look like below:
Release Notes: Update U1.4
  • Added PRZ type back.
  • Alerts - fixed template having extra space
  • fixed ratios on repainting D
Release Notes: Update U 1.5

  • Added option to set freeform target ratios
  • Added option to set XABCD and Ratio label size
  • Minor color adjustments
Release Notes: Update U1.6

Minor bugfixes and library updates
Release Notes: Update U1.7

To make everyones life easy, we have decided to ignore the alerts exploitation and go ahead with removal secondary key validation. This means, trial users will not have any restriction on usage of the script.
Release Notes: Forgot to remove the key parameter :) Not changing the version.
Release Notes:
  • Updated library references
  • Added breakeven as option for trailing type
  • Fixed backtest timer
Release Notes: Update U1.9

Minor performance updates
Release Notes: Update U2.0
Few bug fixes related to PRZ
Release Notes: Update U2.1

Fix alert issue using RecursiveAlerts library
Release Notes: Update U2.2

With this, Auto Harmonic Pattern Ultimate will be deprecated and will not be available for public use with or without invite anymore. Users are encouraged to use Auto-Harmonic-Pattern-UltimateX-Trendoscope instead

Invite-only script

Access to this script is restricted to users authorized by the author and usually requires payment. You can add it to your favorites, but you will only be able to use it after requesting permission and obtaining it from its author. Contact HeWhoMustNotBeNamed for more information, or follow the author's instructions below.

TradingView does not suggest paying for a script and using it unless you 100% trust its author and understand how the script works. In many cases you can find a good open-source alternative for free in our Community Scripts.


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.

Author's instructions

Trial Request : https://www.trendoscope.au/contact-us Purchase subscriptions: https://www.trendoscope.au/algorithms FAQs: https://www.trendoscope.au/faqs

Want to use this script on a chart?

Warning: please read before requesting access.