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

Help with modifying the Stock ZigZag indicator.

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

    Help with modifying the Stock ZigZag indicator.

    Howdy.

    I am wanting to use the stock zigzag indicator as it filters out swings below a certain size set by the user.

    I want to achieve several things.
    1. Have it start over each session
    2. Have it End at the end of the session
    3. Output the swing sizes with time stamps


    1.) I have gotten working by initializing and adding at the beginning of the OnBarUpdate() with:
    Code:
    			
    if (Bars.FirstBarOfSession) //Starting over at the beginning setting it to Open
    			{
    				zigZagHighSeries.Set(Open[0]);
    				zigZagHighZigZags.Set(Open[0]);
    				zigZagLowSeries.Set(Open[0]);
    				zigZagLowZigZags.Set(Open[0]);
    				return;
    			}
    2.) I am unsure how to do this. I used a similar 'if' statement, but setting it to the OHLC of the last bar of the session doesn't seem to work.

    Here is a picture explaining it.
    Attached Files

    #2
    forrestang,

    I am happy to assist you.

    Could you please clarify what you are trying to do? Do you want this indicator to have a gap between when a session closes and when it opens?

    I look forward to assisting you.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_AdamP View Post
      forrestang,

      I am happy to assist you.

      Could you please clarify what you are trying to do? Do you want this indicator to have a gap between when a session closes and when it opens?

      I look forward to assisting you.
      Many thanks Adam! Yes, there should be a gap, as I am wanting to simply track the swings for EACH session as opposed to the whole. The picture I posted in my prior post is an example of how I have it halfway working.

      But if I could show you how exactly it would work, allow me to attach another picture. Note though that this was done with Paint, so the swings aren't sized or anything, but just to show that I would like to have the thing start over with each session, and simply function the way it normally would within that session....
      Attached Files

      Comment


        #4
        forrestang,

        You could try adding the following code :

        Code:
        if (Bars.LastBarOfSession) //Starting over at the beginning setting it to Open
        			{
        				zigZagHighSeries.Set(Close[0]);
        				zigZagHighZigZags.Set(Close[0]);
        				zigZagLowSeries.Set(Close[0]);
        				zigZagLowZigZags.Set(Close[0]);
        				return;
        			}
        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Hmmm,

          I tried that initially, but for some reason it doesn't change anything?

          Comment


            #6
            When you add it to your indicator, are you getting results like the image attached? It will still draw a line between the closing price and open price but it should be closer to what you expect. What session template are you using? You can check by right clicking the chart > go to DataSeries.
            Attached Files
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Thanks.

              Turns out it was working fine but the plot on the chart confused me a tad I suppose. Looks like you don't even need the last statement of LastBars since it is restarted each session.

              I just checked and printed out the value for the last swing point, and I can in fact see that it is the correct value, even though it appears the line just gets plotted that way in a straight line.

              Next thing I need to do is print these values out in sequential order, with ± values. I.e. if the swing high moved 50 tics off of a low, print the +50 and a time stamp.
              Attached Files

              Comment


                #8
                forrestang,

                I am happy that it works for you.

                Please let me know if I may be of further assistance.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_AdamP View Post
                  forrestang,

                  I am happy that it works for you.

                  Please let me know if I may be of further assistance.
                  Do you have any idea how to get those values of the swing points, and the time the swing point occurred?

                  Comment


                    #10
                    Hi forrestang,

                    You may be able to do something like is shown in this post:


                    ZigZag has a similar method available with:
                    ZigZag(DeviationType deviationType, double deviationValue, bool useHighLow).HighBar(int barsAgo, int instance, int lookBackPeriod)

                    It loops through swing points on the last bar and prints values.The valuable part of this is the barsAgo value, so this can be plugged in either High[ ] or Time[ ].

                    The way it is written currently, It prints the most recent swings first. To reverse this, you would start the counter at a higher initial value and decrement with -- rather than increment ++.

                    I'm not sure how this would be used to capture zig zags on a session basis but it may give you enough to play with.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_RyanM View Post
                      Hi forrestang,

                      You may be able to do something like is shown in this post:


                      ZigZag has a similar method available with:
                      ZigZag(DeviationType deviationType, double deviationValue, bool useHighLow).HighBar(int barsAgo, int instance, int lookBackPeriod)

                      It loops through swing points on the last bar and prints values.The valuable part of this is the barsAgo value, so this can be plugged in either High[ ] or Time[ ].

                      The way it is written currently, It prints the most recent swings first. To reverse this, you would start the counter at a higher initial value and decrement with -- rather than increment ++.

                      I'm not sure how this would be used to capture zig zags on a session basis but it may give you enough to play with.
                      Apologies, I'm not sure I understand what to do with the above?

                      What I would like to do is simply go through an plot the distance between swing high to swing low, and the time that the swing points where put in place.

                      Is that what I should use the above for?

                      Comment


                        #12
                        Similar to this ZigZag that plots the distance on the chart between the swing points.

                        I am wanting to recover values like these from the standard NT zz indie. I want this because every other swing indie I have seen calculates the span based on number of bars. Where the standard zz in ninja does it soley by distance traveled, or 'reversal size.'
                        Attached Files

                        Comment


                          #13
                          Yeah, it can do that. You can use the loop to iterate through instances of swing/zig zag. As long as you start from the same point (the last bar on chart in my example), then you can make comparisons with the values returned with each separate instance.
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            I'm not sure what you mean, or how which variables contain those values, or how I would print them? It seems everything I'm checking and printing out to see what value is contained, it's not the swing point?

                            I think once I find that, I can figure out how to plot the swings for each session.

                            Comment


                              #15
                              Sorry, if the loop adds confusion here. You can use it to get values for multiple instances at once. Here is a basic example, that gets the time of the two most recent zig zag highs, and then creates a TimeSpan object based on the difference.


                              Code:
                              if (CalculateOnBarClose)
                              {
                              	if (Count - 2 == CurrentBar)
                              	{
                              		int zzHigh1 =  Math.Max(0, ZigZag(DeviationType.Points, 0.5, false).HighBar(0, 1, Bars.BarsSinceSession));
                              		int zzHigh2 =  Math.Max(0, ZigZag(DeviationType.Points, 0.5, false).HighBar(0, 2, Bars.BarsSinceSession));
                              									
                              		TimeSpan myTimeSpan = Time[zzHigh1] - Time[zzHigh2];
                              					
                              		Print(myTimeSpan.ToString());
                                        }
                              }
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kevinenergy, 02-17-2023, 12:42 PM
                              117 responses
                              2,765 views
                              1 like
                              Last Post jculp
                              by jculp
                               
                              Started by Mongo, Today, 11:05 AM
                              5 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by SightCareAubetter, Today, 12:55 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post SightCareAubetter  
                              Started by traderqz, Today, 12:06 AM
                              8 responses
                              16 views
                              0 likes
                              Last Post traderqz  
                              Started by SightCareAubetter, Today, 12:50 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post SightCareAubetter  
                              Working...
                              X