vpirinski

BreakoutTrendFollowing

vpirinski Updated   
INFO:
The "BreakoutTrendFollowing" indicator is a comprehensive trading system designed for trend-following in various market environments. It combines multiple technical indicators, including Moving Averages (MA), MACD, and RSI,
along with volume analysis and breakout detection from consolidation, to identify potential entry points in trending markets. This strategy is particularly effective for assets that exhibit strong trends and significant price movements.
Note that using the consolidation filter reduces the amount of entries the strategy detects significantly, and needs to be used if we want to have an increased confidence in the trend via breakout.
However, the strategy can be easily transformed to various only trend-following strategies, by applying different filters and configurations.
The indicator can be used to connect to the Signal input of the TTS (TempalteTradingStrategy) by jason5480 in order to backtest it, thus effectively turning it into a strategy (instructions below in TTS CONNECTIVITY section)

DETAILS:
The strategy's core is built upon several key components:
  • Moving Average (MA): Used to determine the general trend direction. The strategy checks if the price is above the selected MA type and length.
  • MACD Filter: Analyzes the relationship between two moving averages to confirm the trend's momentum.
  • Consolidation Detection: Identifies periods of price consolidation and triggers trades on breakouts from these ranges.
  • Volume Analysis: Assesses trading volume to confirm the strength and validity of the breakout.
  • RSI: Used to avoid overbought conditions, ensuring trades are entered in favorable market situations.
  • Wick filters: make sure there is not a long wick that indicates selling pressure from above

The strategy generates buy signals when several conditions are met concurrently (each one of them can be individually enabled/disabled)"
  • The price is above the selected MA.
  • A breakout occurs from a configurable consolidation range.
  • The MACD line is above the signal line, indicating bullish momentum.
  • The RSI is below the overbought threshold.
  • There's an increase in trading volume, confirming the breakout's strength.
Currently the strategy fires SL signals, as the approach is to check for loss of momentum - i.e. crossunder of the MACD line and signal line, but that is to everyone to determine the exit conditions.
The buy and SL signals are set on the chart using green or orange triangles on the below/above the price action.

SETTINGS:
Users can customize various parameters, including MA type and period, MACD settings, consolidation length, and volume increase percentage. The strategy is equipped with alert conditions for both entry (buy signals) and exit (set stop loss) points, facilitating both manual and automated trading.
Each one of the technical indicators, as well as the consilidation range and breakout/wick settings can be configured and enabled/disabled individually.
Please thoroughly review the available settings of the script, but here is an outline of the most important ones:
Use bar wicks (instead of open/close) - the ref_high/low will be taken based on the bar wicks, rather than the open/close when determining the breakout and MA
Enter position only on green candles - additional filters to make sure that we enter only on strong momentum
  • MA Filter: (enable, source, type, length) - general settings for MA filter to be checked against the stock price (close or upper wick)
  • MACD Filter: (enable, source, Osc MA type, Signal MA type, Fast MA length, Slow MA length, Low MACD Hist) - detailed settings for fine MACD tuning
  • Consolidation:
  • Consolidation Type: we have two different ways of detecting the consolidation, note the types below.
  • CONSOLIDATION_BASIC - consolidation areas by looking for the pivot point of a trend and counts the number of bars that have not broken the consolidation high/low levels.
  • CONSOLIDATIO_RANGE_PERCENT - identifies consolidation by comparing the range between the highest and lowest price points over a specified period.
    So in summary the CONSOLIDATIO_RANGE_PERCENT uses a percentage-based range to define consolidation, while CONSOLIDATION_BASIC uses a count of bars within a high-low range to establish consolidation.
    Thus the former is more focused on the tightness of the price range, whereas the latter emphasizes the duration of the consolidation phase.
    The CONSOLIDATIO_RANGE_PERCENT might be more sensitive to recent price movements and suitable for shorter-term analysis, while CONSOLIDATION_BASIC could be better for identifying longer-term consolidation patterns.
  • Min consolidation length - applicable for CONSOLIDATION_BASIC case, the min number of bars for the price to be in the range to consider consolidation
  • Consolidation Loopback period - applicable for CONSOLIDATION_BASIC case, the loopback number of bars to look for consolidation
  • Consolidation Range percent - applicable for CONSOLIDATIO_RANGE_PERCENT, the percent between the high and low in the range to consider consolidation
  • Plot consolidation - enables plotting of the consolidation (only for debug purposes)
  • Breakout: (enable, low, high) - the definition of the breakout from the previous consolidation range, the price should be between to determine the breakout as successfull
  • Upper wick: (enable, percent) - defines the percent of the upper wick compared to the whole candle to allow breakout (if the wick is too big part of the candle we can consider entering the position riskier)
  • RSI: (enable, length, overbought) - general settings for RSI TA
  • Volume (enbale, percentage increase, average volume filter en, loopback bars) - percentage of increase of the volume to consider for a breakout. There are two modes - percentage increase compared to the previous bar, or percentage against the average volume for the last loopback bars.
Note that there are many different configuration that you can play with, and I believe this is the strength of the strategy, as it can provide a single solution for different cases and scenarios.
My advice is to try and play with the different options for different markets based on the approach you want to implement and try turning features on/off and tuning them further.

TTS SETTINGS (NEEDED IF USED TO BACKTEST WITH TTS):
The TempalteTradingStrategy is a strategy script developed in Pine by jason5480, which I recommend for quick turn-around of testing different ideas on a proven and tested framework
I cannot give enough credit to the developer for the efforts put in building of the infrastructure, so I advice everyone that wants to use it first to get familiar with the concept and by checking
by checking jason5480's profile www.tradingview.com/u/jason5480/
The TTS itself is extremely functional and have a lot of properties, so its functionality is beyond the scope of the current script -
Again, I strongly recommend to be thoroughly explored by everyone that plans on using it.
In the nutshell it is a script that can be feed with buy/sell signals from an external indicator script and based on many configuration options it can determine how to execute the trades.
The TTS has many settings that can be applied, so below I will cover only the ones that differ from the default ones, at least according to my testing - do your own research, you may find something even better :)
The current/latest version that I've been using as of writing and testing this script is TTSv48
Settings which differ from the default ones:
  • Deal Conditions Mode - External (take enter/exit conditions from an external script)
  • 🔌Signal 🛈➡ - BreakoutTrendFollowing: 🔌Signal to TTS (this is the output from the indicator script, according to the TTS convention)
  • Order Type​​ - STOP (perform stop order)
  • Distance Method​​ - HHLL (HigherHighLowerLow - in order to set the SL according to the strategy definition from above)

The next are just personal preferences, you can feel free to experiment according to your trading style
  • Take Profit Targets - 0 (either 100% in or out, no incremental stepping in or out of positions)
  • Dist Mul|Len Long/Short- 10 (make sure that we don't close on profitable trades by any reason)
  • Quantity Method - EQUITY (personal backtesting preference is to consider each backtest as a separate portfolio, so determine the position size by 100% of the allocated equity size)
  • Equity %         - 100 (note above)
Release Notes:
updated the plot shapes to be better associated with price action been attached to bars
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

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.

Want to use this script on a chart?