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

SwingHighBar produces odd results

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

    SwingHighBar produces odd results

    After all bars are loaded, I wish to go back and mark all the highs with a blue dot.


    The first image shows all is well

    Click image for larger version

Name:	Good Dots.png
Views:	176
Size:	23.9 KB
ID:	1049231



    This image shows random markings on past bars.

    Click image for larger version

Name:	Bad Dots.png
Views:	170
Size:	24.1 KB
ID:	1049232



    The code bit.

    Click image for larger version

Name:	Swing Test Code Bit.png
Views:	172
Size:	19.5 KB
ID:	1049233

    Finally here is a small test script.

    [ATTACH]n1049234[/ATTACH]

    I cannot figure out why I cannot access swings in the distant past while the recent ones work fine.


    Last edited by TikDaddy; 02-24-2019, 01:52 PM.

    #2
    Here is the indicator.

    SwingTest.zip

    Comment


      #3
      Hello TikDaddy,
      Thanks for your post.

      It looks like none of your images were successfully posted and I won't be able to help very much with the logic in your custom method MarkAllHighs(). Why don't you simply use OnBarUpdate() for drawing your dots at the highs?
      Josh G.NinjaTrader Customer Service

      Comment


        #4
        I see the images when I view the page so I don't know whats up with that.

        When I build the script to use OnBarUpdate the SwingHighBar function works correctly. When I run it using the MarkAllHighs method, only the most recent bars are correct. This strikes me as odd because the script marks the bars starting from the very oldest, and then works it way up to the newest. Why are only the newest ones correct when it uses the same logic for all of them.

        My ultimate goal is not simply to mark the bars; I only wrote the script to illustrate the problem I am having applying the SwingHighBar on bars in the distant past.

        Here is the main snippet of interest.


        private void MarkAllHighs()
        {
        for( int i = Bars.Count-strength ;i > 0;i--)
        {
        hBar = Swing(strength).SwingHighBar(i, 1, strength*2);

        if(hBar >0 && hBar != oldhBar)
        {
        Draw.Dot(this,"EntDot"+Time[i],false,hBar,High[hBar],Brushes.Blue);
        oldhBar = hBar;
        }
        }
        }

        What I need to know is if there is anything special I must do to correctly use SwingHighBar function on bars in the distant past.



        Last edited by TikDaddy; 02-22-2019, 06:19 PM.

        Comment


          #5
          The problem was easily fixed by setting MaximumBarsLookBack to "Infinite". I noticed that after the 256th bar is where the trouble would start, and that indicated the problem immediately.
          I was aware of that setting but I did not think it would apply here because I was easily able to reference Highs and Lows at any point on the chart and so I presumed ( wrongly ) that SwingHighBar would also be able to if I gave the correct index values.

          Overall a simple solution and all is well.

          Comment


            #6

            Some additional notes:

            The "SwingTest" script was meant to illustrate the problem I was having with the SwingHighBar function and was fixed by switching the lookback period to "infinite." However, when I went back to my main Project script, I found that I had already made that change while troubleshooting it so it was clear that I had a little bit more to do.

            So the actual cure was to add this line to my State.Configure section:

            Swing(strength).MaximumBarsLookBack=MaximumBarsLoo kBack.Infinite

            Now I am able to reference swings that occurred anywhere on my chart if I need to.

            Hopefully this will help someone else.

            Comment


              #7
              Originally posted by TikDaddy View Post
              I see the images when I view the page so I don't know whats up with that.
              ..
              I don't see the them either.
              Did you skip step to upload your images to ninja server, I think your link point to images on your own computer.

              Comment


                #8
                As a test, I disconnected the workstation which holds the images and I am now using a laptop. I can still see the images.

                So,still on the laptop, I right click the image and "Copy Image Address" and this is the result.



                Interesting.

                Comment


                  #9
                  here is what I see clicking your your link
                  Click image for larger version  Name:	savepic.png Views:	1 Size:	30.1 KB ID:	1049218
                  here are step by step, hope it help
                  Click image for larger version  Name:	savepic2.png Views:	1 Size:	85.5 KB ID:	1049219

                  Comment


                    #10
                    Wow that is strange! When I click that link, I see ( still on my laptop ) an image of the original chart, as if it uploaded perfectly.
                    Last edited by TikDaddy; 02-24-2019, 01:41 PM.

                    Comment


                      #11
                      I went back and attempted a repair of the original post. I didn't think the system would allow that after this much time has passed but it seemed to go well.

                      Can anyone confirm if the images in the original post are visible ?
                      Last edited by TikDaddy; 02-25-2019, 08:01 AM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by fiddich, Today, 05:25 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post fiddich
                      by fiddich
                       
                      Started by gemify, 11-11-2022, 11:52 AM
                      6 responses
                      803 views
                      2 likes
                      Last Post ultls
                      by ultls
                       
                      Started by ScottWalsh, Today, 04:52 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post ScottWalsh  
                      Started by ScottWalsh, Today, 04:29 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post ScottWalsh  
                      Started by rtwave, 04-12-2024, 09:30 AM
                      2 responses
                      22 views
                      0 likes
                      Last Post rtwave
                      by rtwave
                       
                      Working...
                      X