The Volatility-Based Gap Pattern Recognition in TradingView
Coding the Volatility-Based Gap Pattern Scanner in TradingView
Candlestick patterns are a great addition to market analysis. Some may even consider them vital in research and trading. This article presents the Volatility-Based Gap pattern and shows how to code a scanner in TradingView that detects it.
For the complete collection of candlestick patterns in detail with back-tests and technical strategies, you can check out my newest book with O’Reilly Media. The book features a huge number of classic and modern candlestick patterns as it dwelves into the realm of technical analysis with different trading strategies. The book comes with its own GitHub and is dynamic in nature as it is continuously updated and questions are answered on the O’Reilly platform promptly.
Mastering Financial Pattern Recognition
Amazon.com: Mastering Financial Pattern Recognition eBook : Kaabar, Sofien: Kindle Storeamzn.to
The Volatility-Based Gap Pattern
When the opening price of a financial instrument differs significantly from the closing price of the previous day without any trading activity taking place in between, it is referred to as a gap. A gap or empty space is created as a result on the price chart.
Gaps can happen for a number of reasons, including:
News or announcements that have an impact on the market, which could result in a pause in trading when it resumes.
Market sentiment which may bring a sudden change in market attitude, such as panic selling or purchasing.
Technical elements such as stop-loss orders and limit orders.
Because they might reveal information about the market’s strength and direction, gaps are crucial for traders. After an upswing or downtrend, there may be a gap that indicates the trend will continue. On the other hand, a gap that develops following a time of consolidation can forecast a future reversal. In this article, we will create a simple gap scanner based on the average true range (ATR), a volatility indicator. The main hypothesis is that the gaps found signal reversals (for simplicity).
The bullish Volatility-Based Gap occurs whenever the open price is lower than the previous close price by at least the value shown in the previous 3-period ATR. The following Figure shows a theoretical illustration of the bullish Volatility-Based Gap.
The bearish Volatility-Based Gap occurs whenever the open price is higher than the previous close price by at least the value shown in the previous 3-period ATR. The following Figure shows a theoretical illustration of the bearish Volatility-Based Gap.
Coding the Scanner in TradingView
The conditions of the pattern are relatively easy to code especially in a straightforward and simple coding language such as Pine Script, TradingView’s native language.
The aim of the scanner is to detect the Volatility-Based Gap patterns using the following indications:
A green arrow for bullish Volatility-Based Gap signals.
A red arrow for bearish Volatility-Based Gap signals.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sofien-Kaabar
//@version=5
indicator("Price Pattern - Volatility-Based Gap", overlay = true)
threshold = input(defval = 3, title = 'Threshold')
bullish_gap = (close[1] - open) > ta.atr(threshold)
bearish_gap = (open - close[1]) > ta.atr(threshold)
plotshape(bullish_gap, style = shape.triangleup, color = color.green, location = location.belowbar, size = size.small)
plotshape(bearish_gap, style = shape.triangledown, color = color.red, location = location.abovebar, size = size.small)
The following Figure shows a signal chart after the code has been applied and executed.
The following Figure shows another signal chart.
The following Figure shows another signal chart.
Summary
To sum up, what I am trying to do is to simply contribute to the world of objective technical analysis which is promoting more transparent techniques and strategies that need to be back-tested before being implemented. This way, technical analysis will get rid of the bad reputation of being subjective and scientifically unfounded.
I recommend you always follow the the below steps whenever you come across a trading technique or strategy:
Have a critical mindset and get rid of any emotions.
Back-test it using real life simulation and conditions.
If you find potential, try optimizing it and running a forward test.
Always include transaction costs and any slippage simulation in your tests.
Always include risk management and position sizing in your tests.
Finally, even after making sure of the above, stay careful and monitor the strategy because market dynamics may shift and make the strategy unprofitable.