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
33
indicator
132
strategy
171

Recent Snippets

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) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Implementing Time and Day Restrictions in Trading Algorithms
strategy
This code snippet demonstrates how to set restrictions on trading activities based on specific days of the week and [...]
Implementing Partial Position Closure Based on Price Retracement in ProBuilder
strategy
This code snippet demonstrates how to partially close a trading position when the price retraces to a certain level in [...]
Logo Logo
Loading...