Auto Harmonic Pattern - Backtester [Trendoscope]

Trendoscope Wizard Updated   
We are finally here with the implementation of backtesting tool for Auto-Harmonic-Pattern-UltimateX.


This script is based on our premium indicator - Auto-Harmonic-Pattern-UltimateX. In this script, along with implementation of scanning harmonic patterns, we provide various options via settings which enables users to build their own strategy based on harmonic patterns, use them with custom coded filters, backtest them on various tickers and timeframes.

Harmonic Patterns is concept and we can trade harmonic pattern in many ways. While general interest around harmonic patterns is to find reversal zones and use them for short term swing trades. But, using it along trend following strategies can also be very rewarding. Here is one of the educational idea I shared about using harmonic patterns for trend following. These are just few possibilities where users can explore further on how they want to trade this. The settings of this script are crafted in such a way that it enables users to explore all these possibilities.

🎲 Components

Chart components of this script is lighter compared to Auto Harmonic Pattern - UltimateX. This is because we want to keep lighter interface in order to support seamless execution of emulator. Since pine strategy framework does most of the things such as calculating profitability, keeping track of trades and results etc, display with respect to - "Closed Trade Stats" are removed from this script and "Open Trade Stats" are made lighter.

🎲 Settings

🎯 Trade Settings : Few important settings under this section are

  • Due to pine limitations, we will not be able to support both long and short in a same setup. Hence, users need to chose either long or short trade setup.
  • Entry/Base/Target play important role in defining your strategy.
  • Confluence is another important factor which lets users use multiple patterns at once as confirmation.

🎯 Zigzag Settings : Zigzag settings determine the size of patterns being formed.

Please note that smaller patterns may not yield very good results and larger patterns may take time to complete trade. Similarly higher depth can cause runtime issues. Recursive zigzag option is alternative to deep search algorithm.

🎯 Filters :

Filters enable users to select trades based on specific conditions. Ability to use external filter even allows writing and using custom filters to be used with this algorithm. Here is a video which explains how this can be done. HOW-TO-Use-external-filters

Pattern filters allow users to pick and chose patterns they want to trade. This can be done either individually or based on category

🎯 Alerts :

Apart from strategy specific alerts, the script also implements customisable alerts via pine alert() function. Alerts can be configured to send upon three conditions

  • When new pattern is created
  • When an existing pattern updates entry/stop/target due to safe repaint of D (Only happens when Trail Entry Price is selected)
  • When a pattern in trade closes either due to hitting stop or target

Important Note: Alerts fired via this method may not match the trades shown on chart as trades which are controlled via pine strategy emulator depends on various other factors such as pyramiding.

Alert template is customisable and users can make use of available placeholders to get dynamic data in alerts. Valid placeholders are
  • {alertType} - Alert type - New/Update/Close
  • {id} - Pattern Id
  • {ticker} - Ticker
  • {timeframe} - Chart timeframe
  • {price} - Current price
  • {patterns} - Identified pattern names
  • {direction} - Direction - Long/Short
  • {entry} - Entry Price
  • {stop} - Stop Price
  • {target} - Target Price
  • {orderType} - Limit/Stop - applicable for only New and Update types
  • {status} - Trade status. Valid values are Pending/Cancelled/Stopped/Success

Template is common for all custom alert types. Hence, updating the template will impact all custom alerts - New/Update/Close
	"alert" : "{alertType}",
	"id" : {id},
	"ticker" : "{ticker}",
	"timeframe" : "{timeframe}",
	"price" : {price},
	"patterns" : "{patterns}",
	"direction" : "{direction}",
	"entry" : {entry},
	"stop" : {stop},
	"target" : {target},
	"orderType" : {orderType}
	"status" : {status}

Here is a video on how to customise the alerts using templates and placeholders - HOW-TO-Customize-Alerts-With-Placeholders

🎯 Miscellaneous :

These are simple settings to control display and backtest bars. If you are running alerts, we suggest turning of Open Trades and Drawings and limit backtest to minimal value in order to improve efficiency of

🎯 Backtest Engine Parameters :

  • Default settings are optimised for trend following. Users are encouraged to play around with settings and filters to build strategy out of this tool.
  • Position sizing is not leveraged. Margin settings makes sure that trades cannot exceed capital.
  • All measures are taken to avoid repainting. Script does not use and real time bars. This drastically reduces the risk of repainting in scripts.
  • If you are premium user, please select "Bar Magnifier".

Release Notes:
Update Bx1.1

Option to Enable/Disable force closure of positions upon pattern closure
Disabling this option will keep positions open even if patterns are closed. But, the script will continue to cancel pending orders when patterns close.

Regular Inverse Mode
Added option to trade regular and inverse mode. In inverse mode, you will be able to backtest the outcome of trading against the pattern. With this Entry % and Stop % parameters are replaced with new Stop/Entry/Target ratios of regular mode.

Log Scale
Added option to scan patterns and project targets in log scale.

Custom Risk Calculation
Added option to calculate custom risk based on percent of equity or cash. In this method, trade position is calculated based on the risk amount rather than absolute position size. This can help to set equal risk for all trades irrespective of the pattern size.

When Force Close of position upon pattern closure is disabled, that means, the positions can run for longer time. This might block future pattern trades if the pyramiding is set to lower number. Hence, if the force close option is disabled, it is ideal to use higher number of pyramiding with very low position size. Which means, you will get into more trades but with smaller position size.

Default margin is set to 100 and also strategy position calculation logic are restricted not to use leveraged positions. This means, overall position size can never go beyond your capital.
Release Notes:
Major Update Bx1.2

  • Migrated whole code to use type based libraries - that helps us structure the code in a more modular way and run more efficiently.
  • Strict mode for ratio checks enabled. This helps reduce the number of patterns for those who want to be selective.
  • Removed Use Confluence option as it is less useful than initial estimation.
  • Inverse trade mode is removed. Will reevaluate adding this option back in the future.

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 Trendoscope 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 - Subscribe -

Want to use this script on a chart?

Warning: please read before requesting access.