Program 70 | Flexible Zig Zag functions

Flexible Zig zag functions with Fibonacci detection option

The Program 70 package that consists of two functions and three demonstration show me studies that call one or the other function. These new functions allow a user to build zig zags from a calculated series, such as a moving average (Zig zags on this site have, thus far, been built using high price pivots and low price pivots. These new functions allow you to replace using price high and price low with other calculated values.)

The programs are summarized in the following table:

FunctionDisplay Zig-Zag linesCalculate Fibonacci relationshipsDemonstration programsFree for Gold Pass members
_ZigZagDisplayYESNO_ZigZagDisplayTestYES
_ZigZagYESYES_ZigZagTestSimple
_ZigZagTest
NO

The two functions, _ZigZagDisplay and _ZigZag,  include the same core zig zag functionality, but the _ZigZag function also includes algorithms to detect whether ratios of the price increase/decrease consecutive zig zags are equal to (or close to) a Fibonacci ratio.

Calling the _ZigZagDisplay function (the function that doesn’t include the Fibonacci detection)

The _ZigZagDisplay function is called as follows:

// Enter the value to be checked here:
HiVal = AverageFC( H, 9 ); // The HIGH value
LoVal = AverageFC( L, 9 ); // The LOW value

// Call the _ZigZagDisplay function
Value1 = _ZigZagDisplay( HiVal, LoVal, 3 {Left strength of pivots},
3 {Right strength of pivots}, 0.2 {RetracePerc}, "White" {ZigZagColUp},
"Orange" {ZigZagColDn}, "White" {ColorOfText}, 3 {Thickness},
"Ariel" {Font}, 18 {FontSize} );

HiVal. This could be replaced with High (to use high price pivots) or another calculation like AverageFC( H, 4 ).

LoVal. This could be replaced with Low (to use low price pivots) or another calculation like AverageFC( L, 4 ).

HiVal and LoVal can both be set to the same values. I demonstrate this in the video below.

RetracePerc is the percentage above or below a ‘running’ pivot that pivot must be formed to start a new zig zag

ZigZagColUp and ZigZagColDn are the colors of up and down zig zag lines respectively (see the program web page for available colors)

ColorOfText is the color of number label

Thickness is the thickness of the lines drawn on the chart

Font is the font for text objects

FontSize is the font size for text objects

_ZigZagDisplayTest applied to a chart

Calling the _ZigZag function (the function that includes the Fibonacci detection)

// Call the _ZigZag function
Value1 = _ZigZag( HiVal, LoVal, LStrength, RStrength,
RetracePerc, ZigZagColUp, ZigZagColDn, CheckForFib,
Tolerance, ColorOfText, LineThickness, Font, FontSize,
MaxVectorCount, UpMoves, DnMoves, HiZZ, LoZZ );

With the following inputs:

HiVal. This could be replaced with High (to use high price pivots) or another calculation like AverageFC( H, 4 ).

LoVal. This could be replaced with Low (to use low price pivots) or another calculation like AverageFC( L, 4 ).

HiVal and LoVal can both be set to the same values. I demonstrate this in the video below.

LStrength is the left strength of the pivots

RStrength is the right strength of the pivots

RetracePerc is the percentage above or below a ‘running’ pivot that pivot must be formed to start a new zig zag

ZigZagColUp and ZigZagColDn are the colors of up and down zig zag lines respectively (see the program web page for available colors)

If CheckForFib is set to TRUE the function will look for Fibonacci releationships between the ratio of the last up and down zig zags. If a match is found the zig zag line is drown with a thickness of LineThickness. The ratio is printed near the end of the last zig zag.

Both Fibonacci retracements and extensions (projections) are looked for. The following ratios are compared in the calculation:

  • 38.2
  • 61.8
  • 100.0
  • 138.2
  • 161.8

Tolerance is used in the Fibonacci calculation. It is the percentage tolerance calculating a range above and below last change.

ColorOfText is the color of number label

Font is the font for text objects

FontSize is the font size for text objects

MaxVectorCount is the maximum number of elements in the UpMoves, DnMoves, HiZZ, and LoZZ vectors that are returned if CheckForFib is set to TRUE.

In this example the HiVal is set to AverageFC( H, 9 ) and the LoVal to AverageFC( L, 9 ). Notice how the pivots coincide with the respective pivots for the moving averages (the moving averages are plotted using a separate indicator). Click the image to see a larger version.

In this image the setup is the same as the previous chart except that both HiVal qnd LoVal are set to AverageFC( H, 9 ) hence all the pivots occur on the higher average. Click the image to see a larger version.

Data returned by the _ZigZag function

If CheckForFib is set to TRUE the function populates and returns 4 vectors:

UpMoves. Each time a new up move is confirmed it is added to the UpMoves vector. Once the vector reaches MaxVectorCount and a new element is added, the oldest element is deleted.

DnMoves. Each time a new down move is confirmed it is added to the DnMoves vector. Once the vector reaches MaxVectorCount and a new element is added, the oldest element is deleted.

HiZZ. Each time a new high pivot occurs its bar number is stored in the HiZZ vector.  Once the vector reaches MaxVectorCount and a new element is added, the oldest element is deleted.

LoZZ. Each time a new low pivot occurs its bar number is stored in the LoZZ vector.  Once the vector reaches MaxVectorCount and a new element is added, the oldest element is deleted.

The _ZigZagDisplayTest show me study calling the _ZigZagDisplay function

Vars: double HiVal( 0 ), double LoVal( 0 );
// Enter the value to be checked here:

HiVal = AverageFC( H, 9 ); // The HIGH value

LoVal = AverageFC( L, 9 ); // The LOW value

// Call the _ZigZagDisplay function

Value1 = _ZigZagDisplay( HiVal, LoVal, 3 {Left strength of pivots}, 3 {Right strength of pivots}, 0.2 {RetracePerc}, "White" {ZigZagColUp}, "Orange" {ZigZagColDn}, "White" {ColorOfText}, 3 {Thickness}, "Ariel" {Font}, 18 {FontSize} );

The _ZigZagTest show me study to call the _ZigZag function

// Namespaces
using elsystem ;
using elsystem.collections ;

Input: double RetracePerc( 0.2 ), // Percentage above running pivot that pivot must be formed to start a new zig zag
int LStrength( 3 ), // Left pivot strength
int RStrength( 3 ), // Right pivot strength

bool CheckForFib( false ), // Perform check for Fibonacci ratios
double Tolerance( 10 ), // Percentage tolerance when calculating how close ratio is to Fib ratio

string ZigZagColUp( "DarkGreen" ), // Color of up zig zag line (see the program web page for available colors)
string ZigZagColDn( "Orange" ), // Color of up zig zag line
string ColorOfText( "Black" ), // Color of number label
int LineThickness( 4 ), // Thickness of line if new zig zag if close to a Fibonacci ratio
int MaxVectorCount( 100 ), // The maximum number of elements in the UpMoves, DnMoves, HiZZ, and LoZZ vectors
string Font( "Ariel" ), // Font for text objects
double FontSize( 16 ); // Font size for text objects

Vars: double HiVal( 0 ),
double LoVal( 0 ),

Vector UpMoves( Null ),
Vector DnMoves( Null ),
Vector HiZZ( Null ),
Vector LoZZ( Null );

// First piece of code that is run when applied to a chart or is reinitialized
Once
begin
UpMoves = new Vector;
DnMoves = new Vector;
HiZZ = new Vector;
LoZZ = new Vector;
end ;

// Enter the value to be checked here:
HiVal = AverageFC( H, 9 ); // The HIGH value
LoVal = AverageFC( L, 9 ); // The LOW value

// Call the _ZigZag function
Value1 = _ZigZag( HiVal, HiVal, LStrength, RStrength, RetracePerc, ZigZagColUp, ZigZagColDn, CheckForFib, Tolerance, ColorOfText, LineThickness, Font, FontSize, MaxVectorCount, UpMoves, DnMoves, HiZZ, LoZZ );
Fibonacci data for zig-zag lines printed for zigzag pivot

A close up of the text information drawn on the chart when a Fibonacci ratio match is found

When the function is called it calculates and draws zig zag lines on the chart together with text at the zig zag pivots. The text shows the vertical height of each zig zag leg. With the _ZigZag function, if the CheckForFib input is set to true and the vertical ratio of two most recent zig zag lines is close to a Fibonacci ratio, text is also displayed to show which Fibonacci ratio it is close to and the zig zag line is drawn with a heavier weight (also specified by a user input: LineThickness.)

Accessing data in the returned vectors

The UpMoves vector contains the last MaxVectorCount up moves. The most recent can be accessed using UpMoves.items[0] astype double the second most recent can be accessed using UpMoves.items[1] astype double etc

The DnMoves vector contains the last MaxVectorCount down moves. The most recent can be accessed using DnMoves.items[0] astype double

The HiZZ vector contains the bar numbers of the last MaxVectorCount high zig zag pivots. The most recent can be accessed using HiZZ.items[0] astype int, the second most recent can be accessed using HiZZ.items[1] astype int etc

The LoZZ vector contains the bar numbers of the last MaxVectorCount low zig zag pivots. The most recent can be accessed using LoZZ.items[0] astype int

Before attempting to access an element of a vector it is important to check that the element exists by taking a count of the vector. This is achieved by using LoZZ.Count.

The function does not contain a mechanism for regulating the number of text objects on the chart.

Make sure that ‘Show empty daily trading periods for traditional chart types’ and ‘Show empty intraday session periods for traditional chart types’ are not selected. These can be found by clicking View – Chart Analysis Preferences

tutorial103-chart-analysis-prefs

If these are selected, the chart includes blank bars which ‘confuse’ the bar number for BNPoints. For example, in the following daily chart of IBM, the ‘Show empty daily trading periods for traditional chart types’ is selected. The chart looks like the following (notice how the pivots and the lines do not line up correctly):

The legacy version of program 65 applied to a 60 minute @ES chart.

The legacy version of program 65 applied to a 60 minute @ES chart.

In the following chart all settings are identical apart from “Show empty intraday session trading periods for traditional chart types” is deselected.

es-60min-program65-2

Note that vectors do not store a history. In other words, you cannot look back 5 bars and see what the vector was storing then (like you could with an array).

Program 70 was developed for TradeStation 9.5 and above and is not compatible with MultiCharts because of some of the drawing technology used.

Program download

The UNPROTECTED functions (i.e. the TradeStation EasyLanguage is fully functional and you can see the source code) and three associated showme studies that demonstrate how to call the function are available for for IMMEDIATE download for $49- by clicking the ‘add to cart’ button.

After download the program can be opened, you will be able to see the program code and modify it. After purchase you will be redirected to a download page, so don’t close the browser.

The programs included in the download ELD are:

  • _ZigZagDisplay (a function)
  • _ZigZagDisplayTest (a showme study that calls _ZigZagDisplay)
  • _ZigZag (a function)
  • _ZigZagTestSimple (a showme study that calls _ZigZag)
  • _ZigZagTest (a showme study that calls _ZigZag)

If you are a Gold Pass member make sure you enter the special coupon code to get 20% discount off these prices. Alternatively _ZigZagDisplay is available at no cost in the Gold Pass area below.

Video demonstration of program 70


Program 70 was developed for TradeStation 9.5 and above and is not compatible with MultiCharts.

Gold Pass area

This content is for members only.

Color options

AliceBlueDarkSlateGrayLightSalmonPaleVioletRed
AntiqueWhiteDarkTurquoiseLightSeaGreenPapayaWhip
AquaDarkVioletLightSkyBluePeachPuff
AquamarineDeepPinkLightSlateGrayPeru
AzureDeepSkyBlueLightSteelBluePink
BeigeDimGrayLightYellowPlum
BisqueDodgerBlueLimePowderBlue
BlackFirebrickLimeGreenPurple
BlanchedAlmondFloralWhiteLinenRed
BlueForestGreenMagentaRosyBrown
BlueVioletFuschiaMaroonRoyalBlue
BrownGainsboroMediumAquamarineSaddleBrown
BurlywoodGhostWhiteMediumBlueSalmon
CadetBlueGoldMediumOrchidSandyBrown
ChartreuseGoldenrodMediumPurpleSeaGreen
ChocolateGrayMediumSeaGreenSeashell
CoralGreenMediumSlateBlueSienna
CornflowerBlueGreenYellowMediumSpringGreenSilver
CornsilkHoneydewMediumTurquoiseSkyBlue
CyanHotPinkMediumVioletRedSlateBlue
DarkBlueIndianRedMidnightBlueSlateGray
DarkBrownIndigoMintCreamSnow
DarkCyanIvoryMistyRoseSpringGreen
DarkGoldenrodKhakiMoccasinSteelBlue
DarkGrayLavenderNavajoWhiteTan
DarkGreenLavenderBlushNavyTeal
DarkKhakiLawnGreenOldLaceThistle
Dark MagentaLemonChiffonOliveTomato
DarkOliveGreenLightBlueOliveDrabTurquoise
DarkOrangeLightCoralOrangeViolet
DarkOrchidLightCyanOrangeRedWheat
DarkRedLightGoldenrodYellowOrchidWhite
DarkSalmonLightGrayPaleGoldenrodWhiteSmoke
DarkSeaGreenLightGreenPaleGreenYellow
DarkSlateBlueLightPinkPaleTurquoiseYellowGreen

For zig zag based programs see:

Program 70 | Flexible Zig Zag functions
Program 70 | Flexible Zig Zag functions
Price: $49.00
Program 67 Zig Zag Fibonacci
Program 67 Zig Zag Fibonacci
Price: $39.95
Program 65 | Zig zag function with Fibonacci ratio detection
Program 65 | Zig zag function with Fibonacci ratio detection
Price: $49.00
Program 26 | Zig zag repeated change | Gold Pass download
Program 26 calculates zig-zag patterns and calculates the difference between each high and the next low, and the difference between each low and the next high. The values are 'drawn' on the chart to the appropriate number of decimal places. In addition, the program compares each downward zig zag with the previous downward zig zag. If the new downward zig zag is with a user defined tolerance of the previous downward zig zag, the thickness of the current downward zig zag is increased to a user defined value. Similarly, if the new upward zig zag is with a user defined tolerance of the previous upward zig zag, the thickness of the current upward zig zag is increased to a user defined value.
Price: $59.95
Program 14 | Analyzing zig-zags to find when turning points occur most often
Program 14 is a ShowMe study that calculates zig zag patterns and stores the times at which the turning points occur in an array. Each time a new turning point is confirmed the time at which it occurred is compared with those already in the array. If the time is already in the array its 'significance index' is incremented by one. A user input determines how many lines should be drawn and the program sorts the array and draws vertical lines on the times where the most number of turning points occurred previously.
Price: $74.95
File type :
Program 8 | Zig zag conflux
This program finds turning points in price action using the zig zag method. Once a new turning point is found, its price level is compared with price levels already stored in an array (if any). If the new level is within a user-specified tolerance of an existing line then the two lines are 'combined' by increasing the 'significance index' and updating the date and time associated with the level.
Price: $69.95
Program 1 | Fibonacci Zig Zag Confluence
This Fibonacci-Confluence show-me study works by drawing percentage based zig zag lines and each time a new zig zag line is confirmed, Fibonacci levels are calculated. An array is created which stores Fibonacci levels. If a new Fibonacci level is found to be within a certain tolerance of an existing Fibonacci level stored in the array, it is 'merged' with the existing line. This is done by increasing the thickness parameter of the line. Lines are extended to the right if their thickness parameter is greater than an input value. The maximum thickness of a line plotted is TradeStation line thickness 4.
Price: $74.95

Please note that any screen shots on this site are examples and are not meant to imply that any of these programs will generate profitable trades.

THESE INDICATORS, SHOW ME STUDIES, STRATEGIES AND OTHER PROGRAMS HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES.

TO THE BEST OF MARKPLEX CORPORATION’S KNOWLEDGE, ALL OF THE INFORMATION ON THIS PAGE IS CORRECT, AND IT IS PROVIDED IN THE HOPE THAT IT WILL BE USEFUL. HOWEVER, MARKPLEX CORPORATION ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE, RESULTING FROM THE USE OF THIS INFORMATION AND/OR PROGRAM(S) DESCRIBED, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION AND/OR PROGRAMS DESCRIBED IS AT YOUR OWN RISK.

ANY EASYLANGUAGE OR POWERLANGUAGE TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (AND PARTS THEREOF) AND ASSOCIATED TECHNIQUES REFERRED TO, INCLUDED IN OR ATTACHED TO THIS TUTORIAL OR PROGRAM DESCRIPTION ARE EXAMPLES ONLY, AND HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES. MARKPLEX CORPORATION. DOES NOT RECOMMEND THAT YOU USE ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (OR ANY PARTS THEREOF) OR TECHNIQUES. THE USE OF ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS AND TECHNIQUES DOES NOT GUARANTEE THAT YOU WILL MAKE PROFITS, INCREASE PROFITS, OR MINIMIZE LOSSES.

Disclaimer The information, materials, products and services on this Web site are made available subject to the following terms and conditions. Markplex Corporation reserves the right to change these terms and conditions at its sole discretion. This Web site and any downloads, videos, tutorials, programs and information contained herein is presented solely for educational, informational, and/or entertainment use and under no circumstances should be used for actual trading. We at Markplex Corporation are not Broker/Dealers, Financial Advisers or Registered Analysts. No offer or solicitation to buy or sell securities, securities derivatives, futures products or off-exchange foreign currency (forex) transactions of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given or in any manner endorsed by Markplex Corporation. You are fully responsible for any investment or trading decisions you make. Futures and options trading has a large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures and options markets. This Web site is neither a solicitation nor an offer to buy and/or sell futures or options. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this Web site. Past performance, whether actual or indicated by historical tests of strategies, is no guarantee of future performance or success. No warranties of profitability are being made or given. There is a possibility that you may sustain a loss equal to or greater than your entire investment regardless of which asset class you trade (equities, options futures or forex); therefore, you should not invest or risk money that you cannot afford to lose. CFTC RULE 4.41 - Hypothetical or simulated performance results have certain inherent limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not actually been executed, the results may have under- or over-compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown. Screen shots on this site are examples and are not meant to imply that any of the programs or tutorials available on this Web site will generate profitable trades. EasyLanguage or PowerLanguage trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions (and parts thereof) and associated techniques referred to, included in or attached to this tutorial or program description are examples only, and have been included solely for educational, informational, and entertainment use. Markplex Corporation does not recommend that you use any such trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions (or any parts thereof) or techniques. The use of any such trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions and techniques does not guarantee that you will make profits, increase profits, or minimize losses. Markplex Corporation assumes no liability for any damages, direct or otherwise, resulting from the use of this information and/or program(s) described, and no warranty is made regarding its accuracy or completeness. Use of this Web site including the information, tutorials and/or programs included on it is at your own risk. You shall indemnify and hold Markplex Corporation harmless from any and all liability, loss, trading losses, costs, damage, or expense, including attorneys' fees you or third party may suffer (other than damage to your tangible property or injuries to employees occurring during the course of work) as a result of claims, demands, costs, or judgments arising out of third party and any other claims based on Markplex Corporation's performance, including, but not limited to losses resulting from the use of Markplex Corporation developed software, programs, web sites, tutorials, or the TradeStation charting and/or trading platform. Any testimonials on this Web site may not be representative of the experience of other clients and are not indicative of future results or success.
This Web site contains or may contain references and links to other companies and/or their Web sites, none of which is under the control of Markplex Corporation. Markplex Corporation makes no representations, warranties or endorsements whatsoever about any other Web sites to which you may have access through the Markplex Corporation Web site, or any products or services of those other companies, even if the products or services of those other companies or their Web sites are described or offered on the Markplex Corporation Web site or integrated with Markplex Corporation's products or services. TradeStation®, EasyLanguage® and PowerEditor® are registered trademarks of TradeStation Technologies, Inc. Other brand and product names which appear on this site are the trademarks or service marks of their respective owners, including: Microsoft® is a registered trademark in the United States Microsoft®Excel® is a registered trademark of Microsoft® Neither TradeStation Technologies nor any of its affiliates has reviewed, certified, endorsed, approved, disapproved or recommended, and neither does or will review, certify, endorse, approve, disapprove or recommend, any product or service that offers training, education or consulting regarding the use of EasyLanguage.

By continuing to use and navigate our sites, services, applications, tools or messaging, you are agreeing to our Terms and Conditions and the use of cookies, web beacons and similar technologies as described in our Privacy Policy and Privacy Policy on the use of cookies.