Identifying and Plotting Zigzag Highs and Lows in ProBuilder

03 Aug 2015
0 comment
0 attachment

This code snippet is designed to identify and plot the last zigzag highs and lows on a price chart using the ProBuilder programming language. The zigzag pattern is a technical analysis tool used to filter out smaller price movements, making trends easier to spot.

zz = zigzagpoint[15]
lookback = 100

if islastbarupdate then
    //find last zigzag tops & bottoms
    a=0
    unset($zz)
    for i = lookback-1 downto 0
        itop = zz[i+1]>zz[i+2] and zz[i]zz[i+1]
        if itop then
            $zz[a]=zz[i+1]
            $zzbar[a]=barindex-(i+1)
            $zztype[a]=1
            lasttop = $zz[a]
            a=a+1
        endif
        if ibottom then
            $zz[a]=zz[i+1]
            $zzbar[a]=barindex-(i+1)
            $zztype[a]=-1
            lastbottom = $zz[a]
            a=a+1
        endif
    next

    //plot the zigzag tops & bottoms
    if a>0 then
        for i = 0 to a-1
            if $zztype[i]=1 then //is that a top?
                drawpoint($zzbar[i],$zz[i],3) coloured("cyan")
            else //nope! that's a bottom
                drawpoint($zzbar[i],$zz[i],3) coloured("crimson")
            endif
        next
endif

return lasttop, lastbottom

The code snippet above performs the following steps:

  • Initialization: Sets the zigzag sensitivity and lookback period.
  • Check for Last Bar Update: Ensures that the code executes only on the last update of the bar, optimizing performance.
  • Identify Zigzag Tops and Bottoms: Iterates backwards through the price data to find points where a zigzag top or bottom occurs based on the defined conditions.
  • Store Points: Stores the identified zigzag points, their corresponding bar indices, and whether they are tops or bottoms.
  • Plot Points: Plots the identified points on the chart using different colors for tops and bottoms.
  • Return Values: Returns the last identified top and bottom points for further use or analysis.

This code is useful for traders or analysts who want to visually identify significant price points and trends in financial markets using automated methods.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/zigzag-dysfonctionnement/page/2/#post-201122

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...