Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

ZigZag Issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    ZigZag Issue

    I wish to track the Zigzag high pivot points for trend analysis. I have a custom indicator which creates and plots the ZigZag, and as well, I manually plot ZigZag(Close, Percent, .08, false).

    The screen plot of the ZigZag indicator and the pivot points of the identical internal ZigZag mostly agree, however there are additional data points in the internal indicator. Bars (1364) and (1365) at a price of 55.02 do not belong. This problem persists throughout the sessions bars.



    Code:
    private ZigZag aZZ;   // in variables region
    
    aZZ = ZigZag(DeviationType.Percent , zzDev, false);  // in the OnStartUp call
    
    Print("\n ("+CurrentBar.ToString()+ ") - " + aZZ.ZigZagHigh[0]);  // in OnBarUpdate
    Code:
     (1359) - 55.22
     (1360) - 55.22
     (1361) - 55.22
     (1362) - 55.22
     (1363) - 55.22
     (1364) - 55.02
     (1365) - 55.02
     (1366) - 55.09
     (1367) - 55.09
     (1368) - 55.09
     (1369) - 55.09
     (1370) - 55.09
    Attached Files

    #2
    Looks to me like the prices that dont fit below are the initial Highs which are subsequently re-painted and therefor not visible once the indicator has fully loaded.

    The best way to read only the points that you see is to create a loop and look backwards

    I wrote this code ages ago, its a void that stores my ZZ vals in arrays.... It is referencing my own slightly modified version of the ZZ indicator but from memory i think the parameters are the same for the generic ZZ...

    Hope it helps..

    void LoadZZs(int id, double dev, int lookback)
    {
    //Print("LoadZZ");
    LookBackNotEnough = false;

    int cnt = 0;

    for (int z = 0; z <5; z++)
    {
    for (int x = 1; x <10; x++)
    {

    LookBackNotEnough = false;

    zzLB[id,x] = ZigZagGK(DeviationType.Points, dev, true).LowBar(0,x,lookback);
    zzHB[id,x] = ZigZagGK(DeviationType.Points, dev, true).HighBar(0,x,lookback);

    if (zzHB[id,x] < 0 || zzLB[id,x] < 0)
    {
    LookBackNotEnough = true;
    lookback *= 2;
    break;
    }
    zzHigh[id,x] = High[zzHB[id,x]];
    zzLow[id,x] = Low[zzLB[id,x]];

    }

    if (!LookBackNotEnough)
    break;

    }


    bool LowFirst = false;
    }

    Comment


      #3
      thank you marty087. I will give this a try.

      Comment


        #4
        Hello marty087,

        Thank you for providing the code in your previous post.

        caliope: Please let us know if this code does not resolve your issue. If it does not resolve your issue, can you please provide a specific example of why the price on bars 1364 and 1365 do not belong and what is expected?
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Thanks Zachary: I have been away, hence the delayed response on my side.

          I have used the following indicator ( testZZ ) to create the attached 2min plot of Boeing. This plots the ZigZagHigh overlay on the price. In addition I have the identical ZigZag indicator overlayed on the price plot. (DeviationType.Percent, 0.08, false).

          Although the testZZ plot is delayed by one bar, it is well behaved until 9:04 AM. From 9:04 until 9:30, the behavior is erratic, seemingly wanting to draw intermediate highs??

          Any thoughts on this.

          thanks


          Code:
              public class testZZ : Indicator
              {
                  #region Variables
                  // Wizard generated variables
                      private double dev = 0.08; // Default setting for Dev
                  // User defined variables (add any user defined variables below)
          			private ZigZag aZZ;
                  #endregion
          
                  /// <summary>
                  /// This method is used to configure the indicator and is called once before any bar data is loaded.
                  /// </summary>
                  protected override void Initialize()
                  {
                      Add(new Plot(Color.FromKnownColor(KnownColor.SlateBlue), PlotStyle.Line, "Plot0"));
                      Overlay				= false;
                  }
          		
                  protected override void OnStartUp(){
          
          			ClearOutputWindow();
          			aZZ = ZigZag(DeviationType.Percent , Dev, false);
          		}	
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                  if(CurrentBar > BarsRequired){
                      Plot0.Set( aZZ.ZigZagHigh[0]);
          			Print("\n ("+CurrentBar.ToString()+ ") - " + aZZ.ZigZagHigh[0] );
          		}
                  }
          Attached Files

          Comment


            #6
            Hello caliope,

            I am not entirely clear of the erratic behavior.

            I've added a Print statement with a ZigZag() method call, rather than the use of aZZ, to see if both values match.

            Code:
            Print(ZigZag(DeviationType.Percent , Dev, false).ZigZagHigh[0]);
            Print("\n ("+CurrentBar.ToString()+ ") - " + aZZ.ZigZagHigh[0] );
            The values from both Print statements match. Can you please clarify what values are expected? Does your indicator plot not match the values outputted to the Output Window?
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Thanks Zachary:

              Yes, the print statements do match, but do not reflect the expected behavior of the ZigZagHigh[].

              Please consider the attached plot of 2 min bars of BA from yesterday/today. The brown trace is a plot of ZigZagHigh[0]. The expected result is to plot the most recent ZigZagHigh[0] of 136.68 from the period between the high pivots:
              (12:10 hrs, 136.68) and
              (13:50 hrs, 137.36).

              In this instance, I expect ZigZagHigh[0] to return the value of last Swing high of 136.68 in the interval 12:10 to 13:50 hrs, then update to the next swing high of 137.36 at 13:50 hrs. Instead, the ZigZagHigh[] series appears to update on each red bar retracement per the attached plot.

              thanks

              Comment


                #8
                Hello caliope,

                Just to clarify, are you trying to have your indicator match the plots of the ZigZag indicator itself or are you only trying to get the high values of the ZigZag indicator?

                If you would like your indicator to match the ZigZag indicator, you would want to use Plot0.Set(aZZ[0]);
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Zachary:

                  I only want the Swing High values.

                  thanks

                  Comment


                    #10
                    Hello caliope,

                    If you are wishing to only obtain the Swing high values, I would suggest using the Swing indicator instead: http://ninjatrader.com/support/helpG...nt7/?swing.htm

                    There is an example on the help guide page linked above that shows how to print the high price of the most recent swing high.
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      Zachary:

                      My poor choice of words. I would like the pivot highs, based on Close. I am aware of the Swing indicator and have used it previously.

                      I have even attempted using Close[ ZigZag().HighBar() ] as a workaround to capture the pivot highs. It reproduces exactly the same results as presented in the attached BA (2min) plot.

                      I have run this testZZ indicator on enough symbols and bar types to know that this is a consistent issue.

                      to Summarize:
                      the testZZ indicator simply produces a plot of the last ZigZig high ZigZagHigh[0] using the provided @ZigZag indicator with NT 7.

                      The expected result is that a horizontal line be drawn between pivot highs with a step change at a new pivot high reflecting new values.

                      The actual result is that there are many intermediate values being stored in the ZigZagHigh[] DataSeries between the pivot highs.

                      Could I ask that you please

                      1. confirm that the expected result I mentioned above is true
                      2. run the testZZ indicator on your system to confirm the results I am witnessing.


                      thanks
                      Attached Files

                      Comment


                        #12
                        Hello caliope,

                        Unfortunately, intermediate values are expected. These values may have been the highs at one point, but as more data comes in, this is not the case any longer. Please note that these values are not removed from the ZigZagHigh DataSeries when this occurs.

                        The ZigZag indicator determines how the zig zag will be plotted based on its historical data; the indicator may be redrawn and look different as more data comes in.

                        You can verify this by using a DrawDot() in the "if (addHigh || updateHigh)" conditional in the ZigZag indicator. Example:
                        Code:
                        DrawDot(CurrentBar.ToString(), true, 1, Close[1], Color.Yellow);
                        You will see that while there are yellow dots at the high points, there are other dots at other points as well.

                        You can even witness this through Market Replay. If you add the modified ZigZag indicator, you will see that the dots are drawn on every high point and remain even if the point on the zig zag itself changes.

                        Plotting the ZigZagHigh DataSeries also mimics the occurrence, following every single high value that occurs.
                        Zachary G.NinjaTrader Customer Service

                        Comment


                          #13
                          thank you Zachary for the great explanation.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by quantismo, 04-17-2024, 05:13 PM
                          3 responses
                          25 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by ScottWalsh, 04-16-2024, 04:29 PM
                          7 responses
                          34 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by cls71, Today, 04:45 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post cls71
                          by cls71
                           
                          Started by mjairg, 07-20-2023, 11:57 PM
                          3 responses
                          214 views
                          1 like
                          Last Post PaulMohn  
                          Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                          4 responses
                          547 views
                          0 likes
                          Last Post PaulMohn  
                          Working...
                          X