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 barsAgo

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

    ZigZag barsAgo

    Hi I've been trying to define previous highs and lows by using ZigZag's inbuilt barsAgo function but haven't been able to succeed. Here is the link for the definition in case anyone's interested



    Attached is a simple strategy that plots the ZigZag indicator and prints with bars ago numbers for the previous highs and lows. My understanding is on each bar you can tell "how many bars ago you had the previous high, or the one before that, etc..) I'm applying this to a CL 07-19 contract 200 volume chart in case you want to replicate the case.

    In the attached image, you'll see I marked the Bar at 18:51:59. According to the Print, while at that bar, the previous high was 7 bars ago which seems correct, but the print says the high before that was 12 bars ago which seems incorrect.

    Could you please tell me where i'm going wrong here?

    Thanks
    M
    Attached Files

    #2
    Hello mntemel,
    Thanks for your post.

    We would need to see the code for your Print() to know what was happening specifically
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh, I attached the strategy in my initial post, you can see the print code which is in it.

      Thanks
      M

      Comment


        #4
        M,

        Your screenshot shows a chart with a NinjaScript Output window displaying what is supposedly your codes output. We would need to see some code along with that output to know why you are getting these specific results
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Josh, there are two attachments in my post, 1) Screenshot 2) ZigZag.cs which is the strategy where all the code is. Do I have to share the code in a different way?

          Comment


            #6
            mntemel,

            Sorry, I missed it underneath the image. Posting the .cs file is fine. You can also format it directly into your comment.

            Code:
            Print(Time[0].ToString()                
                             +" - first_high_barsAgo:"+first_high_barsAgo
                             +" - second_high_barsAgo:"+second_high_barsAgo
                             +" - first_low_barsAgo:"+first_low_barsAgo
                             +" - second_low_barsAgo:"+second_low_barsAgo
                             );
            The 7 bars ago High is from the current bar. The 12 Bars ago High would be relative to the most recent zig zag high on your chart and not from the Current Bar. This would be expected output.
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              Thanks for looking into this Josh, so in that case the bars between first high and the second high should be 12 bars, but that doesn't seem to be the case in that chart.

              Comment


                #8
                mntemel,

                It is indeed the case in your screenshot. I have attached a modified version of your screenshot to illustrate.
                Attached Files
                Josh G.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Josh, but 7 and 12 were printed at 18:51:59 (the bar I marked with the white arrow).

                  Comment


                    #10
                    mntemel,

                    ZigZag lines change in real time, so it only really matters with what you can see on the chart in your screenshot.
                    Last edited by NinjaTrader_JoshG; 05-23-2019, 03:49 PM.
                    Josh G.NinjaTrader Customer Service

                    Comment


                      #11
                      Josh, 7 and 12 at 18:51:59 was just an example line I gave, it wasn't the last print in the output. Here attached you'll see the last print was at 18:54:34 with first high 7 and second high 9 bars ago. So according to what you just said these numbers should match the ZigZag on the chart right now.
                      Attached Files

                      Comment


                        #12
                        Hello mntemel,

                        Thanks for your reply.

                        The ZigZag indicator will redraw and I suspect that is what is causing the confusion. To help visualize this, add a Draw.Dot() statement like:

                        Draw.Dot(this, "test"+CurrentBar, true, first_high_barsAgo, High[first_high_barsAgo]+3 * TickSize, Brushes.Gold);

                        Once added, rerun the strategy and you will see what looks like orphan dots that indicate where a high once existed but no longer does. Please note that this code will place many dots (one per bar) and they will be placed on top of each other so this is only for diagnostics and I would remove the code once you have satisfied the performance.

                        Additional comments to help. Please do not name a strategy or indicator using the name of an exiting strategy or indicator as this can be confusing. In this case you named the strategy ZigZag which is the same as the indicator, you could use something like ZigZagtest instead. Please keep the filename, the class name and the name= field as the same name, again this will help you to avoid confusion.
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Paul,

                          Thanks for picking this up. I understand that ZigZag repaints the first high bars ago and first low bars ago locations and they are always moving until the price makes a new turn. But what I don't understand is even the second high bars ago and second low bars ago locations are moving. I followed your advice and put draw dot command in my bars ago test strategy. I'm attaching the strategy for your reference. Here you'll see I'm drawing a dot on "second" high bars ago and "second" low bars ago locations. I'm also attaching a screenshot, you'll see these locations keep moving as well, meanwhile ZigZag is printing its lines where you can see the highs and lows.

                          I was using this ZigZag's BarsAgo function up until your v.17 update, since then I'm not able to define the highs and lows. Could you please show me how exactly I need to use the ZigZag BarsAgo to define the past highs and lows so that I can integrate it in my strategy.

                          thanks
                          M
                          Attached Files

                          Comment


                            #14
                            Hello M,

                            From the help guide:
                            "The ZigZag indicator highlights trends based on user defined threshold values and helps filtering the noise in price charts, it's not a classical indicator but more a reactive filter showing extreme price points. In processing it's calculations it can update it's current direction and price extreme point based on newly incoming data, the current developing leg should be thought of temporary until a new leg in opposite direction has been set."


                            In other words, it will continue to update until that leg is set. Once a leg is set, and a new leg is forming, the previous set legs no longer update.

                            Below is a link to a short video that demonstrates.


                            In the video we see the green dot marking the most recently fully set high, and the blue dot marking the second most recently set high.
                            We print the time of the bar these dots are over. The most recent high is at 6:48 and the previous is at 6:43.
                            In real-time we see that as new bars are appearing on the chart, the barsAgo values increase as the dots need to be drawn further back to mark the bar, however the time of those bars remains the same.
                            The time of the dots remain the same until the current zigzag leg finishes building and is set at 7:07. At that moment, as the building leg is set the most recent high is updated to the 7:06 bar and the second most recent is moved to 6:48 as expected.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chelsea, thanks for taking the time to record the video, I tried to replicate your code but I'm not getting the same output, do you mind sharing the code?

                              Also, in your video we see that ZigZag is making two highs in a row without making a low, that's not the behavior you see when you use ZigZag as an indi, do you think there might be a bug there?

                              THanks
                              M

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Javierw.ok  
                              Started by timmbbo, Today, 08:59 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post bltdavid  
                              Started by alifarahani, Today, 09:40 AM
                              6 responses
                              41 views
                              0 likes
                              Last Post alifarahani  
                              Working...
                              X