• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ZigZag Indicator Customization Help

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

    ZigZag Indicator Customization Help

    Hello,

    I've been working on making a couple of updates to the ZigZag indicator and I've gotten everything I need to work except for one thing - I have no idea how to modify the plotting/drawing mechanism of the indicator and was hoping someone with better programming skills than myself could help me out.

    The changes I made basically include sometimes waiting to print a zigzag until other conditions are met and in some cases, the process takes a few more bars and requires that the zigzag be drawn 'x' number of bars ago. The problem is that the zigzag is always printed 2 bars ago and I can't figure out where I can modify this in the cases that I need to wait a few bars.

    I've attached a chart image here with an example. The first zigzag required no modification and thus printed in the appropriate spot. The second, however, required a few bars of wait time but is now printing 5 bars later than I want it to (white arrow shows where I'd like it to print). I have a variable that tracks how many bars ago it should be, I just don't know where to put it!

    To say it another way, I basically need to find a way to sometimes say "print this zigzag 'x' bars ago" instead of the default 2 bars ago.

    Any help on this would be much appreciated!

    Thanks,
    Fiddich

    #2
    Hello Fiddich,

    Use an integer variable to hold the number of bars ago.

    The use this variable as the index for the series.

    private int myInt;

    myInt = 5;

    Print(Close[myInt]);

    This is just a quick example of how an integer variable would be supplied as a barsAgo index.

    Below is a public link to a forum post with helpful information about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for the response. I'm all set with the integer variable and can track how many bars ago I need to draw the indicator but still have an issue.

      My problem is that I don't know where to put that integer. Can you tell me specifically where this goes (which series name?) so that the indicator gets drawn myInt bars ago? I've tried many things but nothing seems to change where that zigzag high or low is drawn.

      Thanks a lot.

      Fiddich

      Comment


        #4
        Hello Fiddich,

        Declare the private integer in the scope of the indicator class. For example the #region Variables.

        Then use the variable when calling a series.
        Close[myInt]

        Close is a series. If myInt has a value of 5, this would return the Close price from 5 bars ago.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          Perhaps I'm not being clear. I have already declared and tracked the integer that notes how many bars ago to draw the zigzag high.

          If you look at my original post, the zigzag isn't drawn in the correct spot (see the image please). I'm trying to figure out which specific series within the ZigZag indicator code is responsible for drawing the line that connects zigzag highs and lows. That way, I can insert my variable into that series and get it to draw the zigzag high further back than it currently is in the image.

          Would you be able to help me with that please?

          Thanks, Fiddich

          Comment


            #6
            Hello Fiddich,

            Have you printed the values for each series to the output window?

            Are you finding any of the printed values match what you are visually looking for on the chart?

            Below is a link to a forum post that demonstrates using prints to understand behavior.
            http://ninjatrader.com/support/forum...979#post510979
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              Yes I have printed out all the series values in the output window but still can't quite figure out how to move the drawing of that line.

              I believe it might have something to do with the lastSwingIdx variable but when I try to find what line(s) of code actually plots the line, I draw a blank, because the code that uses lastSwingIdx ("zigZagHighZigZags" + "zigZagLowZigZags") seem to store the zigZag values, not their x axis location on the chart from what I can tell.

              I looked at the AddPlot at the top of the indicator also and it uses an NT custom resource "NinjascriptIndicatorNameZigZag" which doesn't give me a hint in terms of how that plot is updated.

              Any help on this would be appreciated.

              Thanks.

              Comment


                #8
                Hello fiddich,

                Below is a public link to the help guide on the ZigZag indicator.
                https://ninjatrader.com/support/help...-us/zigzag.htm

                Please provide the output from the output window and the prints you have used to print the information. Then include a screenshot of the chart showing a bar where the values are not the expected values.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Output of Print Statements:

                  lastSwingPrice = 1195.4
                  zigZagHighSeries[0] = 0
                  zigZagHighSeries[1] = 0
                  lastSwingPrice = 1226.6
                  zigZagHighSeries[0] = 1226.6
                  zigZagHighSeries[1] = 1226.6
                  lastSwingPrice = 1208
                  zigZagHighSeries[0] = 1226.6
                  zigZagHighSeries[1] = 1226.6
                  zigZagHighZigZags[0] = 0
                  zigZagHighZigZags[1] = 1220.8
                  zigZagHighSeries[0] = 0
                  zigZagHighSeries[1] = 1226.6
                  zigZagHighSeries[2] = 1226.6
                  zigZagHighSeries[3] = 1226.6
                  Value[0] = 0
                  Value[1] = 1220.8
                  lastSwingPrice = 1220.8
                  zigZagHighSeries[0] = 1220.8
                  zigZagHighSeries[1] = 1220.8
                  lastSwingPrice = 1201
                  zigZagHighSeries[0] = 1220.8
                  zigZagHighSeries[1] = 0
                  lastSwingPrice = 1218.6
                  zigZagHighSeries[0] = 1218.6
                  zigZagHighSeries[1] = 1220.8
                  lastSwingPrice = 1198.6
                  zigZagHighSeries[0] = 1218.6
                  zigZagHighSeries[1] = 1218.6
                  zigZagHighZigZags[0] = 0
                  zigZagHighZigZags[1] = 1223.9
                  zigZagHighSeries[0] = 0
                  zigZagHighSeries[1] = 1218.6
                  zigZagHighSeries[2] = 1218.6
                  zigZagHighSeries[3] = 1218.6
                  Value[0] = 0
                  Value[1] = 1223.9
                  lastSwingPrice = 1223.9
                  zigZagHighSeries[0] = 1223.9
                  zigZagHighSeries[1] = 1223.9
                  lastSwingPrice = 1203.4
                  zigZagHighSeries[0] = 1223.9
                  zigZagHighSeries[1] = 0
                  lastSwingPrice = 1221.7
                  zigZagHighSeries[0] = 1221.7
                  zigZagHighSeries[1] = 0
                  lastSwingPrice = 1190.2
                  zigZagHighSeries[0] = 1221.7
                  zigZagHighSeries[1] = 0
                  lastSwingPrice = 1218.2
                  zigZagHighSeries[0] = 1218.2
                  zigZagHighSeries[1] = 1221.7
                  zigZagHighSeries[0] = 1218.2
                  zigZagHighSeries[1] = 1218.2
                  lastSwingPrice = 1191.9
                  zigZagHighSeries[0] = 1218.2
                  zigZagHighSeries[1] = 0
                  lastSwingPrice = 1251.9
                  zigZagHighSeries[0] = 1251.9
                  zigZagHighSeries[1] = 0
                  lastSwingPrice = 1219.3
                  zigZagHighSeries[0] = 1251.9
                  zigZagHighSeries[1] = 1251.9
                  lastSwingPrice = 1245.2
                  zigZagHighSeries[0] = 1245.2
                  zigZagHighSeries[1] = 0
                  lastSwingPrice = 1202.5
                  zigZagHighSeries[0] = 1245.2
                  zigZagHighSeries[1] = 1245.2
                  lastSwingPrice = 1236.8
                  zigZagHighSeries[0] = 1236.8
                  zigZagHighSeries[1] = 0
                  lastSwingPrice = 1216.8
                  zigZagHighSeries[0] = 1236.8
                  zigZagHighSeries[1] = 1236.8

                  ---
                  Various print statements within the code that I'm using for the high zigZags:

                  Print("zigZagHighZigZags[CurrentBar - lastSwingIdx] = "+zigZagHighZigZags[CurrentBar - lastSwingIdx]);
                  Print("CurrentBar = "+CurrentBar);
                  Print("lastSwingIdx = "+lastSwingIdx);

                  Print("zigZagHighZigZags[0] = "+zigZagHighZigZags[0]);
                  Print("zigZagHighZigZags[1] = "+zigZagHighZigZags[1]);
                  Print("zigZagHighSeries[0] = "+zigZagHighSeries[0]);
                  Print("zigZagHighSeries[1] = "+zigZagHighSeries[1]);
                  Print("zigZagHighSeries[2] = "+zigZagHighSeries[2]);
                  Print("zigZagHighSeries[3] = "+zigZagHighSeries[3]);

                  Print("Value[0] = "+Value[0]);
                  Print("Value[1] = "+Value[1]);

                  Print("lastSwingPrice = "+lastSwingPrice);

                  Print("zigZagHighSeries[0] = "+zigZagHighSeries[0]);
                  Print("zigZagHighSeries[1] = "+zigZagHighSeries[1]);
                  ---

                  First attachment provides one example. The high is correct value-wise but is plotted 2 bars back once it's confirmed in the code. I need it to align with the bar that it matches the high with, 5 bars previous to where it's currently printed. As mentioned, I have the bar # tracked in a variable but just don't know where to put it so that the plot aligns with the zigZag high.

                  Second attachment shows 2 examples of the issue, where the zigzag needs to be drawn further back than it is. It also shows an example of one being OK because that zigZag high didn't require waiting more bars to confirm per the updated rules I added.

                  Please let me know if you need anything further. Thanks.


                  Attached Files

                  Comment


                    #10
                    Hello fiddich,

                    Are you calling the ZigZag indicator multiple times using different parameters?
                    Each each of the series a different indicator instance?


                    If you are storing the indicator instance to a variable I would be expecting something like:

                    In scope of class:
                    private ZigZag myZigZag;

                    In State.DataLoaded:
                    myZigZag = (DeviationType.Points, .5, bool false);

                    In OnBarUpdate:
                    Print(myZigZag.ZigZagHigh[0]);
                    Print(myZigZag.ZigZagLow[0]);


                    Which instance is using the same parameters as the one on the chart?

                    The bar that highlighted by the mouse on the chart is the 10/25 bar as shown your screenshot. However, this bar does not have a swing on it.

                    However, the output does not include any time dates as I demonstrated in the videos I have provided you on how to use prints to make comparisons with.
                    How do you know which bar is which in the output?

                    The databox is not included in the screenshot. What is the swing value that is appearing in the databox for the bar with the mouse over it?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,

                      I'm not calling the ZigZag indicator in a strategy. This is a custom version of the indicator itself, so I don't have a statement such as "myZigZag = (DeviationType.Points, .5, bool false);"

                      The print statements I have are from within the indicator code itself and I printed those in an attempt to try and figure out where in that code the plotting is being done.

                      To summarize again, I made a few custom adjustments to the ZigZag indicator code (as a new Indicator). The adjustments are minor but in a nut shell, it waits for the lows of a bar to be broken before it can be confirmed as a zigzag high (vice versa for zigzag lows).

                      So in the screenshot, the misaligned zigzags belong to bars that didn't have their lows broken until later, and that's what my problem is. I can't figure out how to get the indicator to note the high retroactively. Instead, it just plots the high 1 bar before the bar that breaks the low and thus is misaligned.

                      Comment


                        #12
                        Hello ,

                        I was misunderstanding.

                        I thought you had made some changes to the ZigZag indicator and now you are having trouble calling that indicator from another script.

                        "To say it another way, I basically need to find a way to sometimes say "print this zigzag 'x' bars ago" instead of the default 2 bars ago."

                        I had understood this as you are trying to call the ZigZag x bars ago using a barsAgo index while calling the indicator.


                        It sounds more like you are wanting assistance with custom logic in the custom indicator.

                        Are you trying to move the plot value from one bar to another?
                        You can set that new bar to the old bars value and then Reset() the old bar so this no longer has a value.

                        Is your logic triggering true on a bar and you are wanting this to be true on a later bar?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          "Are you trying to move the plot value from one bar to another?"
                          Yes, I need to move the plot back (see the screenshots in previous posts where the plot occurs after the actual swing high).


                          "You can set that new bar to the old bars value and then Reset() the old bar so this no longer has a value."
                          How/where would I do that within the ZigZag indicator code? That's where I'm having the main problem.

                          "Is your logic triggering true on a bar and you are wanting this to be true on a later bar?"
                          Sort of. My logic triggers true later than the normal version of ZigZag would in some cases, thus I need to somehow tell it "plot and print a zigzag high 5 bars ago" but I'm not sure where to do that. It always just plots the value one bar before the bar that triggers the true logic.

                          Thanks for your continued help Chelsea.

                          Comment


                            #14
                            Hello fiddich,

                            To set the current plot value to the value of 2 bars ago and reset the plot value of 2 bars ago.

                            mySeries[0] = mySeries[2];
                            mySeries.Reset(2);

                            To set a plot value 5 bars ago to a currently caculated value.

                            int myNewCalculatedValue = 1000;
                            Values[0][5] = myNewCalculatedValue;

                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chelsea,

                              I've been messing around with what you provided but unfortunately still can't quite get there. When I tried to add the '[5]' to the Value within the ZigZag code, I received an error that you can't apply indexing to an expression of type double.

                              Would you know where in the code of ZigZag I would need to apply the above in order to change the plot to a bar further back?

                              I've been looking within the "if (addHigh || addLow || updateHigh || updateLow)" section, as I believe it's done there but am not entirely sure. Any chance you could provide an example of it working within ZigZag? Then I think I would be good to go.

                              Thanks again for your help.

                              if (addHigh || addLow || updateHigh || updateLow)
                              {
                              if (updateHigh && lastSwingIdx >= 0)
                              {
                              zigZagHighZigZags[CurrentBar - lastSwingIdx] = 0;
                              Value.Reset(CurrentBar - lastSwingIdx);
                              }
                              else if (updateLow && lastSwingIdx >= 0)
                              {
                              zigZagLowZigZags[CurrentBar - lastSwingIdx] = 0;
                              Value.Reset(CurrentBar - lastSwingIdx);
                              }

                              if (addHigh || updateHigh)
                              {
                              zigZagHighZigZags[1] = saveValue;
                              zigZagHighZigZags[0] = 0;

                              currentZigZagHigh = saveValue;
                              zigZagHighSeries[1] = currentZigZagHigh;
                              Value[1] = currentZigZagHigh;
                              }
                              else if (addLow || updateLow)
                              {
                              zigZagLowZigZags[1] = saveValue;
                              zigZagLowZigZags[0] = 0;

                              currentZigZagLow = saveValue;
                              zigZagLowSeries[1] = currentZigZagLow;
                              Value[1] = currentZigZagLow;
                              }

                              lastSwingIdx = CurrentBar - 1;
                              lastSwingPrice = saveValue;
                              }

                              zigZagHighSeries[0] = currentZigZagHigh;
                              zigZagLowSeries[0] = currentZigZagLow;

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ralett, Today, 11:44 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Spencer  
                              Started by DMDINAZ, Today, 11:03 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by sukhob, Today, 10:14 AM
                              4 responses
                              10 views
                              0 likes
                              Last Post sukhob
                              by sukhob
                               
                              Started by beaacontreras, Today, 09:27 AM
                              1 response
                              20 views
                              0 likes
                              Last Post NinjaTrader_PatrickG  
                              Started by fxSol, 03-17-2019, 04:17 AM
                              5 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_ChristopherS  
                              Working...
                              X