Detecting Double Top and Bottom Patterns

Detecting Double Top and Bottom Patterns

Introduction

Double Top and Double Bottom patterns are technical analysis figures that indicate potential reversal points in an asset’s price direction. Accurately identifying these patterns can offer traders opportunities for market entry and exit with high success potential.

In this article, we will explore how to use an indicator developed to automatically detect these patterns on the chart, making it easier to identify these critical reversal points.

What is the Double Top / Bottom Indicator?

The Double Top / Bottom indicator aims to automatically detect these patterns on the chart. This indicator is especially useful for traders looking to identify potential reversal points in the market without the need to manually search for these patterns. The indicator scans the chart for formations that meet the criteria of a Double Top or Double Bottom and visually marks them on the chart for easy identification.

Indicator Configuration

The Double Top / Bottom indicator allows the customization of several parameters to suit the specific needs of each trader. Below are the input parameters of the indicator:

  • prd: Period used to search for pivots. This value determines how many bars will be considered to identify the highs and lows on the chart. The default value is 5.
  • tol: Tolerance for pattern validation. This parameter defines the tolerance range within which the peaks must be to be considered part of the same pattern. The default value is 15.
  • showPivot: Option to show detected pivots on the chart.
  • Show2Bot: Option to show Double Bottom patterns on the chart.
  • Show2Top: Option to show Double Top patterns on the chart.
  • ShowShort: Option to show short (sell) signals on the chart.
  • ShowLong: Option to show long (buy) signals on the chart.

These parameters allow adjusting the indicator’s behavior to suit different trading strategies and market conditions.

Calculating Pivots

The first step of the indicator is to identify the high and low pivots on the chart. These pivots are used to determine the market direction and to identify potential Double Top and Double Bottom patterns.

Identifying Pivots

The high (ph) and low (pl) pivots are identified using the maximum and minimum values within the defined period (prd). This calculation is performed using the following lines of code:

Calculating Market Direction

The market direction is determined based on changes in these pivots. If a new high pivot is detected and there is no recent low pivot, the direction is assumed to be bullish. If a new low pivot is detected and there is no recent high pivot, the direction is assumed to be bearish.


This approach allows the indicator to dynamically adapt its behavior based on changes in market prices.

Constructing the Zigzag

The next step in the development of the indicator is the construction of the zigzag, which connects the identified high and low pivots on the chart. This algorithm is crucial for forming the basis of the Double Top and Double Bottom pattern analysis.

Storing Relevant Points

The indicator uses arrays to store the relevant points of the zigzag. Each time a change in market direction is detected, a new point is added to the zigzag. The code below shows how this operation is performed:

The $zigzag array stores the pivot values, while the $zigzagidx array stores the corresponding bar indices. This structure allows the indicator to track price movements and determine key turning points.

Detecting Double Top Patterns

A Double Top pattern is a bearish reversal formation that occurs after an uptrend. A Double Top pattern is considered to have occurred when specific price conditions are met.

Calculating Validation Levels

To validate a Double Top pattern, two levels are calculated: TopHigh and BotHigh. These levels are used to determine if the identified peaks are close enough to be considered part of the same pattern.

Pattern Validation

Once the levels are calculated, the indicator validates whether the pattern meets the Double Top conditions. If a valid pattern is detected, it is visually marked on the chart, and short entry signals are generated.

Generating Short Signals

The indicator also includes logic to generate sell signals when a Double Top pattern is confirmed. These signals help traders make informed decisions on when to exit long positions or enter short positions.

Detecting Double Bottom Patterns

A Double Bottom pattern is a bullish reversal formation that occurs after a downtrend. This pattern is considered valid when specific price conditions are met, similar to the Double Top but in the opposite direction.

Calculating Validation Levels

To validate a Double Bottom pattern, two levels are calculated: topLow and botLow. These levels are used to determine if the identified valleys are close enough to be considered part of the same pattern.

Pattern Validation

Once the levels are calculated, the indicator validates whether the pattern meets the Double Bottom conditions. If a valid pattern is detected, it is visually marked on the chart, and long entry signals are generated.

Generating Long Signals

The indicator also includes logic to generate buy signals when a Double Bottom pattern is confirmed. These signals help traders make informed decisions on when to exit short positions or enter long positions.

Chart Visualization

The Double Top / Double Bottom indicator includes several visualization functions to mark the pivots and detected patterns directly on the chart. This provides a clear visual representation and helps traders quickly identify critical reversal points.

Drawing Pivots

For each identified pivot, the indicator draws a point on the chart. This is done using the drawpoint function.

Drawing Patterns

When a Double Top or Double Bottom pattern is detected, the indicator draws a rectangle around the relevant peaks or valleys. This helps to clearly visualize the pattern formation on the chart.

Buy and Sell Signals

In addition to the patterns, the indicator draws arrows on the chart to signal entry and exit points based on the signals generated by the Double Top and Double Bottom patterns.

Indicator Code

Below is the complete code for the indicator in ProBuilder:

Conclusion

The Double Top / Double Bottom indicator is a powerful tool for detecting reversal patterns in the market. With its ability to visualize these patterns on the chart and provide entry and exit signals, it can be a valuable addition to any trader’s toolkit.

Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

  1. Javier Goberna • 120 days ago #

    Hola Iván muchas gracias por todo tu trabajo y por tus videos. Estoy dado de alta en la plataforma y en breve voy a cambiar del banco donde estoy a vuestra plataforma. ¿Me podrás echar un cable? ¿Podré usar tus programaciones para operar? Gracias de antemano.

    • Iván • 116 days ago #

      Hola javier
      gracias! es importante realizar buenos backtest antes de lanzarse al mercado y aplicar una correcta gestión de capital para no pillarse los dedos.

  2. achel • 9 days ago #

    I have an error with “fillcolor” – How to solve this? / J’ai une erreur avec “fillcolor” – Comment résoudre ceci?

    • Iván • 9 days ago #

      Hi! This is because you are not with V12. Just delete fillcolor

avatar
Register or

Likes

avatar avatar
Related users ' posts
Iván
1 month ago
elcortijoverde Gracias Iván,...sigo tus videos en Youtube. Ya estoy con la V12 y se descarga, pero algo est...
elcortijoverde Bueno, ya aparecen las velas, pero ahora, cada fin de vela aparece un nuevo pronóstico y no ...
Roger Gracias por compartir, pero no tengo ninguna predicción. @Ivan @elcortijoverde ¿qué modifica...
ARNAUD20 J'ai, télécharger le logiciel : falling-and-rising-3-methods.itf : rien se passe sur le grap...
DeathMetal C'est un modèle assez rare, essayez-le sur un petit laps de temps, par exemple 5 minutes et ...
philippe59139 Bravo super travail
Goldotor Thank you for sharing this indicator. That's a great work.
Stefano1234 there is an error: Define the variable: prd, showBreak, showPattern, showPvts
romanelli4 molto interessante e grazie ma come faccio a trasformarlo in trading system? grazie per l...
joguemon Buenas, he instalado el screener pero no me aparecen los números que indicas...tengo que mon...
enriquem Hola, No, los numeros no aparecen, Proscreener no permite rotular, Lo que devuelve el sc...
PeytoLake Hi Enriquem, How do I change the timeframe from 'Daily' to "5 min"? Thank you.
robertogozzi I suggest that you open a new topic in the ProScreener support forum. Thank you.
massimo.g. questo screener si può usare anche sul mercato Azinario ?
robertogozzi Like my screener https://www.prorealcode.com/prorealtime-market-screeners/abcd-pattern-scree...
aldtrading Thanks for your work. I'm using V11 and nothing is drawn on the chart, I believe this is ...
robertogozzi It works on v10.3, v11 and v12. You are likely to have added it BELOW your chart (like RSI),...
Wolf I don't know why the indicator does not work for me. It gives me an error about RETURN... ...
sergibilbo Great job thanks!!!
druby I was glancing through the code and noticed that the variable name, Middle' has been used. I...
robert123 hi there, how do you get the images of the knights etc into your code....and is there anywhe...
swapping hello robert123, on this site -> https://fr.piliapp.com/symbol/
Dadoo Incredible workLeo. Thankyou to share you time and knowledge
tommygtb what does the criteria mean in the box on the screen is it the time frame the screener sear...
Saberi2023 Hello dear Can you please write it also in java script?
parthapersonal Great job Leo. Dear Zen83, how do you, "return them into the very last line"?
steve_ Hi! This thread is quite old, but let’s try… I’m new with Prorealcode and I’ve just di...
steve_ Hi! I've created a topic in french (translatable with Google function) here : https://www.p...
simonsanchezj How do you modify this for a 7-10 day period? Thanks
gabri I am not sure I understand what you mean?

Top