Detecting and Visualizing Triangle Breakouts in Trading Charts

20 Oct 2022
0 comment
0 attachment

This ProBuilder code snippet is designed to identify and visualize triangle breakout patterns in trading charts. Triangle breakouts are significant as they often indicate potential bullish or bearish movements. The code detects these patterns and draws segments and arrows to highlight the breakout points.


defparam drawonlastbaronly = false
cp = 1
if high[cp] >= highest[(cp)*2+1](high) then
    LLH = 1
else
    LLH = 0
endif
if LLH = 1 then
    High1 = High2[1]
    High1bar = High2bar[1]
    High2 = high[cp]
    High2bar = barindex[cp]
endif
if low[cp] <= lowest[(cp)*2+1](low) then
    LLL = -1
else
    LLL = 0
endif
if LLL = -1 then
    Low1 = Low2[1]
    Low1bar = Low2bar[1]
    Low2 = low[cp]
    Low2bar = barindex[cp]
endif
triangle = High1>High2 and Low1 abs(High2-Low2)
oscillationH1L1H2L2= High1bar< Low1bar and Low1bar< High2bar and High2bar0 and barindex-startbar<=5 then
    drawarrowup(barindex,low-averagetruerange[14]/2) coloured(0,255,0)
endif
lowerline = low2-aL*(barindex-low2bar)
if close crosses under lowerline and lowerline>0 and barindex-startbar<=5 then
    drawarrowdown(barindex,high+averagetruerange[14]/2) coloured(255,0,0)
endif
Return

This code snippet performs the following steps:

  • Detection of High and Low Points: It identifies the highest and lowest points within a specified lookback period, which are potential pivot points for forming triangles.
  • Triangle Formation Conditions: Checks if the identified points can form a triangle pattern based on their relative positions and amplitude conditions.
  • Visual Representation: If a triangle pattern is detected, the code draws segments connecting these points, extending them for visualization purposes.
  • Breakout Detection: Calculates the equations of the lines forming the upper and lower boundaries of the triangle and checks if the price breaks these lines within a specified number of bars.
  • Breakout Visualization: Draws arrows at the breakout points to indicate a potential entry or exit signal.

This example is useful for understanding how to programmatically detect and visualize complex chart patterns like triangles, which are commonly used in technical analysis of financial markets.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/etendre-drawray-sur-x-barres/#post-137968

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...