NexusFi: Find Your Edge


Home Menu

 





Improve current ZigZag indicator in NT8


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 1 posts (7 thanks)
    2. looks_two StoxFox with 1 posts (1 thanks)
    3. looks_3 oliviam with 1 posts (0 thanks)
    4. looks_4 trendisyourfriend with 1 posts (0 thanks)
    1. trending_up 4,828 views
    2. thumb_up 9 thanks given
    3. group 10 followers
    1. forum 5 posts
    2. attach_file 2 attachments




 
Search this Thread

Improve current ZigZag indicator in NT8

  #1 (permalink)
 sinpeople 
Singapore
 
Experience: Beginner
Platform: TDAmeritrade
Trading: Options On Futures
Posts: 44 since Aug 2017
Thanks Given: 4
Thanks Received: 10

Hi folks,

I am looking for an improved version of ZigZag.

The ZigZag, which comes with NT8, only calculates ZigZag points 1 bar ago. I need the following improvements.
1) Eager to update ZigZag points of new high to current bar, if the zigzag trend is up and current bar is at least 1 tick above the last zigzag high. Or update zigzag point of new low to current bar, if the zigzag trend is down and current bar is at least 1 tick below last zigzag low.
2) Lazy to add new zigzag low point after a zigzag uptrend is identified. New zigzag low point is only added after N consecutive bars are below last high, and the difference is larger than a predefined threshold. (if it's still within the threshold after N bars, wait further until it moves higher to update the last zigzag high, or wait it moves down to hit the threshold to add a zigzag low point). Lazy to add new zigzag high point, after a zigzag down trend is identified, is an opposite but similar case.

I believe these 2 improvements will filter out most of those noises at zigzag turning point.

But I have just setup visual studio to put break points in NinjaScripts. There are still quite a lot for me to learn to make the above improvements. Anyone can help me?

Thank you.

Best Regards
David WANG

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #2 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,175
Thanks Received: 6,020

A much easier way to filter some of the noise for a zig zag indicator is to display a new swing pivot (High or Low) when price closes above or below the previous bar high/low. This would prevent a swing pivot to form when a group of bars drift higher or lower without closing above or below the previous bar.

Reply With Quote
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



sinpeople View Post
Hi folks,

I am looking for an improved version of ZigZag.

The ZigZag, which comes with NT8, only calculates ZigZag points 1 bar ago. I need the following improvements.
1) Eager to update ZigZag points of new high to current bar, if the zigzag trend is up and current bar is at least 1 tick above the last zigzag high. Or update zigzag point of new low to current bar, if the zigzag trend is down and current bar is at least 1 tick below last zigzag low.
2) Lazy to add new zigzag low point after a zigzag uptrend is identified. New zigzag low point is only added after N consecutive bars are below last high, and the difference is larger than a predefined threshold. (if it's still within the threshold after N bars, wait further until it moves higher to update the last zigzag high, or wait it moves down to hit the threshold to add a zigzag low point). Lazy to add new zigzag high point, after a zigzag down trend is identified, is an opposite but similar case.

I believe these 2 improvements will filter out most of those noises at zigzag turning point.

But I have just setup visual studio to put break points in NinjaScripts. There are still quite a lot for me to learn to make the above improvements. Anyone can help me?

Thank you.

Best Regards
David WANG


Hi David,

There are at least three necessary improvements for any zigzag indicator:

1. select minimum deviation based on volatility (average range or average true range), this is required for portfolio backtests
2. use both horizontal and vertical condition (swing strength and minimum deviation) for determining swing highs and lows
3. allow for determining swing highs and lows based on high/low or bar closes


Minimum deviation

The minimum deviation is the amount by which price needs to retrace from the current swing high or low, before a new swing leg is added in the opposite direction. The zig zag that ships with NinjaTrader only allows for setting the minimum deviation in points or percent. In case that you wish to run strategy backtests over different instruments, any mnimum deviation set in points and percent cannot be compared over different instruments and you will not be able to run a portfolio backtest for any strategy using the zigzag indicator. In order to let the strategy run on different instruments and obtain comparable values, you would need to measure the minimum deviation against bar volatility. This can best be achieved by setting the minimum deviation in multiples of the average range (AR) or average true range (ATR).

Horizontal and vertical condition for determining swing points

NinjaTrader ships with two different indicators, the Swing indicator and the ZigZag indicator. It is important to understand that both indicators are repainting indicators. A new swing high or low cannot be identified immediately, but you need to wait until the required conditions have been met. Once this is the case the swing high or low will be identified with hindsight knowledge.

- the Swing indicator draws the line from the swing high or low after N bars, where N is the selected swing strength
- the Zigzag indicator draws a preliminary swing high or low, which is not yet final, as the current swing leg may always be extended

Actually, for the Swing indicator, when you set the swing strength to 5 bars, it is required that the high point of the swing high bar be higher than the 5 prececing highs and the 5 following highs. This explains that you need to wait for 5 bars, before a swing high can be identified. Likewise, for the Zigzag indicator, you need to wait that the minimum deviation is exceeded, before a preliminary high becomes a final high when a down leg is added to it. In the first case the delay is determined by the horizontal lag (5 bars) whereas in the second case the delay is due to a vertical lag (minimum deviation).
It is possible to combine the two approaches to build a zigzag that takes into account both conditions, for example that a new leg is added when both a minimum deviation of 2.5 ATRs has been exceeded and when the new high or low point has taken out the 5 prior highs or lows, when the swing strength is set to 5. When combining the two approaches, you may not want to apply the right side of the swing strenght condition, but may only check the N prior bars for higher highs or lows and then draw a new confirmed swing point when the minimum deviation has been reached.

Zigzag based on highs and lows or closes

The zigzag can be built from highs and lows or just from the bar closes. Obviously, when it is built from highs and lows, the swing legs should update intra-bar.
Only when the zigzag is built from the closes, you need to wait until the actual bar close before extending the current swing leg, adding a new leg in the opposite direction or doing nothing.

It is quite difficult to work with Zigzag indicators because of their repainting properties. The last leg is only a preliminary leg, while the second but the last leg is alreadyfrozen.
The same applies to the last swing point, as the current leg may further be extended. The last swing point only becomes a final swing high or low, once a new swing leg has been added in the opposite direction.



NQ 06-21 (5 Minute) 2021_05_03 (11_48_35)

Reply With Quote
  #4 (permalink)
 hedgeplay 
Austin Texas / US
 
Experience: Intermediate
Frequency: Several times daily
Duration: Seconds
Posts: 176 since Dec 2019
Thanks Given: 145
Thanks Received: 211

FatTails that is a great post.


Just to expand the conversation a little further these two recent good postings byTraderGB possibly offer additional ways of looking at improving the classic ZigZag/Swing indicators.

HedgePlay






Reply With Quote
Thanked by:
  #5 (permalink)
joergky
Berlin, Germany
 
Posts: 9 since Jun 2023
Thanks Given: 8
Thanks Received: 5


Fat Tails View Post
Hi David,

There are at least three necessary improvements for any zigzag indicator:

1. select minimum deviation based on volatility (average range or average true range), this is required for portfolio backtests
2. use both horizontal and vertical condition (swing strength and minimum deviation) for determining swing highs and lows
3. allow for determining swing highs and lows based on high/low or bar closes


Minimum deviation

The minimum deviation is the amount by which price needs to retrace from the current swing high or low, before a new swing leg is added in the opposite direction. The zig zag that ships with NinjaTrader only allows for setting the minimum deviation in points or percent. In case that you wish to run strategy backtests over different instruments, any mnimum deviation set in points and percent cannot be compared over different instruments and you will not be able to run a portfolio backtest for any strategy using the zigzag indicator. In order to let the strategy run on different instruments and obtain comparable values, you would need to measure the minimum deviation against bar volatility. This can best be achieved by setting the minimum deviation in multiples of the average range (AR) or average true range (ATR).

Horizontal and vertical condition for determining swing points

NinjaTrader ships with two different indicators, the Swing indicator and the ZigZag indicator. It is important to understand that both indicators are repainting indicators. A new swing high or low cannot be identified immediately, but you need to wait until the required conditions have been met. Once this is the case the swing high or low will be identified with hindsight knowledge.

- the Swing indicator draws the line from the swing high or low after N bars, where N is the selected swing strength
- the Zigzag indicator draws a preliminary swing high or low, which is not yet final, as the current swing leg may always be extended

Actually, for the Swing indicator, when you set the swing strength to 5 bars, it is required that the high point of the swing high bar be higher than the 5 prececing highs and the 5 following highs. This explains that you need to wait for 5 bars, before a swing high can be identified. Likewise, for the Zigzag indicator, you need to wait that the minimum deviation is exceeded, before a preliminary high becomes a final high when a down leg is added to it. In the first case the delay is determined by the horizontal lag (5 bars) whereas in the second case the delay is due to a vertical lag (minimum deviation).
It is possible to combine the two approaches to build a zigzag that takes into account both conditions, for example that a new leg is added when both a minimum deviation of 2.5 ATRs has been exceeded and when the new high or low point has taken out the 5 prior highs or lows, when the swing strength is set to 5. When combining the two approaches, you may not want to apply the right side of the swing strenght condition, but may only check the N prior bars for higher highs or lows and then draw a new confirmed swing point when the minimum deviation has been reached.

Zigzag based on highs and lows or closes

The zigzag can be built from highs and lows or just from the bar closes. Obviously, when it is built from highs and lows, the swing legs should update intra-bar.
Only when the zigzag is built from the closes, you need to wait until the actual bar close before extending the current swing leg, adding a new leg in the opposite direction or doing nothing.

It is quite difficult to work with Zigzag indicators because of their repainting properties. The last leg is only a preliminary leg, while the second but the last leg is alreadyfrozen.
The same applies to the last swing point, as the current leg may further be extended. The last swing point only becomes a final swing high or low, once a new swing leg has been added in the opposite direction.



NQ 06-21 (5 Minute) 2021_05_03 (11_48_35)

I am looking for a way to have the zig zag indicator show me the VALUE (size in points or ticks) of each move it draws. That should be doable somehow, shouldn´t it? I cannot seem to find a way to do it though. Can you help?

Reply With Quote
  #6 (permalink)
 
StoxFox's Avatar
 StoxFox 
N. California
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ, CL
Posts: 36 since Oct 2019
Thanks Given: 8
Thanks Received: 36

Here's a screenshot of the ZigZag indicator that comes with ZombiePack9, found here:


Reply With Quote
Thanked by:




Last Updated on August 8, 2023


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts