Program 65 | Zig zag function with Fibonacci ratio detection

Zig zag function with Fibonacci detection

Program 65 consists of a new zig zag function and a companion show me study that demonstrates how to call the function. Both programs are included in the download.

Zig zag and Fibonacci ratios on 66 tick @YM chart

Program 65 applied to a 66 tick @YM chart

Program 65 applied to a 5 minute @YM chart

Program 65 applied to a 5 minute @YM chart

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

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

The function also returns 4 vectors:

  • 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

    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.

Calling the function

The function is called as follows:

Value1 = _Program65( RetracePerc, Tolerance, ZigZagColUp, ZigZagColDn, ColorOfText, LineThickness, UpMoves, DnMoves, HiZZ, LoZZ, MaxVectorCount, Font, FontSize );

With the following inputs and color options:

Inputs

RetracePerc( 0.2 ), // Percentage above running pivot that pivot must be formed to start a new zig zag
Tolerance( 10 ), // Percentage tolerance calculating a range above and below last change
ZigZagColUp( “AliceBlue” ), // Color of up zig zag line (see the program web page for available colors)
ZigZagColDn( “Orange” ), // Color of up zig zag line
ColorOfText( “Yellow” ), // Color of number label
LineThickness( 3 ), // Thickness of line if new zig zag if close to a Fibonacci ratio (valid options are 0, 1, 2, 3, 4, 5, and 6)
MaxVectorCount( 100 ), // The maximum number of elements in the UpMoves, DnMoves, HiZZ, and LoZZ vectors
Font( “Ariel” ), // Font for text objects
FontSize( 16 ); // Font size for text objects

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

Technical lessons

Legacy drawing objects

I created an earlier version of the program using both legacy drawing objects AND the more recently introduced drawing objects. I am including this ‘legacy’ program with the download (with the associated calling program) as you may be interested to see how to write code for either of these two technologies or to replace one technology with another.

Drawing legacy trendlines

Legacy trend lines are drawn using the following syntax:

Value1 = TL_New( StartDate, StartTime, StartPrice, EndDate, EndTime, EndPrice );

 

Dates use YYMMDD or YYYMMDD format (three digits are used to express the year 2000 and later), and times use 24-hour format, HHMM.

The problem with it is that on certain charts several bars might have the same HHMM stamp which can lead to unexpected results on tick and seconds charts.

In the following image the legacy drawing tools (the thinner lines) have difficulty positioning a drawing object accurately when more than one bar shares the same minute based time signature. The new drawing tools position the line accurately.

The legacy version of program 65 applied to a 33 tick IBM chart. Note that the new object based drawing objects position text accurately, whereas the legacy drawing objects are a few bars different,

The legacy version of program 65 applied to a 33 tick IBM chart. Note that the new object based drawing objects position text accurately, whereas the legacy drawing objects are a few bars different,

New drawing objects

To draw lines with the new drawing objects we create a pair of BNPoint objects using a bar number and price. The trend line is created and styled and then added to the chart.

Two potential ‘gotchas’
Gotcha 1

A BNPoint refers to the absolute bar index (zero-based) of the collection of bars in a chart. This is not the same as the BarNumber function or CurrentBar reserved word which count the number of bars available for analysis after MaxBarsBack. So to create a BNPoint for the current bar (BarNumber) would be:

NewBar = BarNumber + MaxBarsBack – 1;

Gotcha 2

Another issue that can cause what appear to be spurious results are the ‘Show empty daily trading periods for traditional chart types’ and ‘Show empty intraday session periods for traditional chart types’ settings. 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 download

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

An UNPROTECTED version (i.e. the TradeStation EasyLanguage is fully functional and you can see the source code) and associated unprotected function is 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.

In addition I am including with a download a bonus show me study and function that include drawing object functionality in both the legacy and new drawing object types.

After purchase you will be redirected to a download page, so don’t close the browser. You will also receive an automated email with the download link and instructions for accessing the bonuses.

If you are a Gold Pass member make sure you enter the special coupon code to get 20% discount off these prices.

 Video demonstration of program 65 | introduction and using on a chart

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

For zig zag based programs see:

Program 14 | GOLD PASS DOWNLOAD | 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
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.