• 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

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:	1
Size:	23.9 KB
ID:	1049231



    This image shows random markings on past bars.

    Click image for larger version

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



    The code bit.

    Click image for larger version

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

    Finally here is a small test script.

    SwingTest.zip

    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?
      JoshNinjaTrader 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.

                https://ninjatrader.com/support/foru...2747&type=full

                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 deblanka, Today, 08:56 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post deblanka  
                      Started by Boonfly8, Yesterday, 12:30 PM
                      7 responses
                      18 views
                      0 likes
                      Last Post sledge
                      by sledge
                       
                      Started by Sohal, Today, 05:02 AM
                      2 responses
                      9 views
                      0 likes
                      Last Post techmint  
                      Started by danitralla, Today, 03:33 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post danitralla  
                      Started by yeshujbp, Today, 12:37 AM
                      0 responses
                      14 views
                      0 likes
                      Last Post yeshujbp  
                      Working...
                      X