Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Range bar issue with ninjascript

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

    Range bar issue with ninjascript

    It seems range bar Close and Open sometimes mean different price points for drawn bars on the screen and for the ninjascript. I noticed this disparency in my trading strategy results vs screen verification so I made a simple wizard script to test it out as follows:

    ...
    // Condition set 1
    if (Close[0] > Low[0]
    && Close[1] > Low[1]
    && Close[0] == Close[1] + 4 * TickSize)
    {
    BarColor = Color.Black;
    }
    // Condition set 2
    if (Close[0] < High[0]
    && Close[1] < High[1]
    && Close[0] == Close[1] + -4 * TickSize)
    {
    BarColor = Color.Black;
    }
    ...

    Running this on 6 Range chart marks the correct bars as black. BUT, there are several bars it doesn't mark as defined.

    Why?

    Thanks.

    #2
    Hello gain247,
    A Range bar is based on a specified tick price range. The bar will plot until the price range is broken.


    Your code particularly the below logic filter prevents the bar to be colored.
    Code:
    Close[0] == Close[1] + 4 * TickSize
    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      C'moon, this is much more detailed issue than how range bar is defined, I've traded them over 3 years. The issue I described is not that trivial, lol.

      Close[0] == Close[1] + 4 * TickSize

      does the opposite you said. It colors the bar Black WHEN the latest closed bar (0) closes 4 ticks above the Close of the previous bar (1).

      Please use the same code on your wizard and test it out on 6 Range chart on CL 09-12. Then I can point out the issue bars and we can maybe dig into the real issue here.

      Thanks.

      Comment


        #4
        Hello gain247,
        To assist you further can you post a screenshot depicting the scenario.

        To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

        For detailed instructions please visit the following link

        How to take a screenshot on your smartphone, tablet, notebook or desktop computer



        I look forward to assisting you further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Here is the screenshot. Black bars are marked by the script and I boxed 2 bars which should have also been marked, but were not...
          Attached Files

          Comment


            #6
            And here is more - see only 1 black bar vs 6 bars which were NOT marked Black as they should have... You starting to see the real issue?
            Attached Files

            Comment


              #7
              I can't be certain looking on my phone. But are you sure those are .04 exactly?


              Anyways, printing out the variables involved and looking in the output window log should lead to quicker findings.



              Originally posted by gain247 View Post
              And here is more - see only 1 black bar vs 6 bars which were NOT marked Black as they should have... You starting to see the real issue?

              Comment


                #8
                yes sledge, bar Closes are exactly .04 apart

                Comment


                  #9
                  Hello gain247,
                  If you round the values like the below code then can you get the right bar color

                  Code:
                  Instrument.MasterInstrument.Round2TickSize(Close[1] + 4 * TickSize)
                  I look forward to assisting you further.
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    Upon further review,

                    It looks like there are more conditions than you have coded for.


                    Originally posted by gain247 View Post
                    And here is more - see only 1 black bar vs 6 bars which were NOT marked Black as they should have... You starting to see the real issue?

                    Comment


                      #11
                      Sorry, I don't understand why I should "round the tick value"... are there 'half ticks'?

                      Comment


                        #12
                        Well, I modified the test script using the Round2TickSize and holy cow, it seems to work :-)

                        Now, why in the world did that worked? Are there really partial ticks so that I always have to round
                        any tick value to the nearest full tick? Ie, do I have to use this Round2TickSize on EVERY function/condition where I compare ANY Close/Open values of same or different bars?

                        Thanks.

                        Comment


                          #13
                          Using print statements and the output window would show why.


                          Originally posted by gain247 View Post
                          Well, I modified the test script using the Round2TickSize and holy cow, it seems to work :-)

                          Now, why in the world did that worked? Are there really partial ticks so that I always have to round
                          any tick value to the nearest full tick? Ie, do I have to use this Round2TickSize on EVERY function/condition where I compare ANY Close/Open values of same or different bars?

                          Thanks.

                          Comment


                            #14
                            Hi sledge, I've looked at print statements on these situations and they don't show any partial ticks, just same exact tick values as the corresponding bars on the screen. That's why I've been so puzzled as the bars on the screen AND print statements don't sometimes match with the strategy logic execution (or lack of) in certain bar sequences. For that purpose I did a very simple example strategy below to pinpoint some bar close price value issues, and it seems that sometimes (quite frequently) the real Close of the bar is not an exact tick value, but maybe tiny fraction higher/lower. On the screen the tick values are automatically by exact tick increment, but it seems in the world of programming tick is not an exact tick.

                            Comment


                              #15
                              Hello gain247,
                              You may be running into the floating point precision issue. Please refer here to know more
                              JoydeepNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              1 response
                              17 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by benmarkal, Yesterday, 12:52 PM
                              3 responses
                              23 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by helpwanted, Today, 03:06 AM
                              1 response
                              20 views
                              0 likes
                              Last Post sarafuenonly123  
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              244 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Working...
                              X