Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why in the world does this not work?

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

    Why in the world does this not work?

    This makes no sense to me. Can someone explain why I am not getting a match?

    For every barclose I'm doing this:

    Code:
    Print("HighStop is: -" + highStop + "-    High[0] is: -" + High[0] + "-");
                    
                    if (High[0] == highStop)
                        Print("We have a  match");
                    else
                        Print("We DO NOT have a match");
    Here is the partial Output that should of triggered it to print "We have a match":

    HighStop is: -29.89- High[0] is: -29.86-
    We DO NOT have a match
    HighStop is: -29.89- High[0] is: -29.89-
    We DO NOT have a match
    HighStop is: -29.89- High[0] is: -29.89-
    We DO NOT have a match
    HighStop is: -29.89- High[0] is: -29.89-
    We DO NOT have a match
    A screen grab of the backtest is attached. As you can see, the 29.89 was clearly hit as a high. But it didn't trigger "We have a match". Can someone explain why? I'm I misunderstanding the use of High[0]?

    Thanks
    Attached Files

    #2
    I'm not seeing anything wrong with your code. Do you have a complete script that replicates this issue that I can test on my end?

    Located in (MY)Documents\NinjaTrader 7\bin\Custom (indicator/strategy folder)

    Is this a multi series script?

    What instrument is this?
    LanceNinjaTrader Customer Service

    Comment


      #3
      I tried to recreate the problem by simplifying it down to a bare bones strategy. And of course, it worked as it should.

      So, I went back to my original strategy and changed

      Code:
      if (High[0] == highStop)
            PrintWithTimeStamp("We have a match");
      
      to 
      
      if (High[0] == 29.89)
             PrintWithTimeStamp("We have a match");
      That worked as it should. I also tested the following and it worked fine...

      Code:
      highStop = 29.89;
      if (High[0] == highStop)
             PrintWithTimeStamp("We have a match");
      So, it appears that highStop's value is not what it appears. Is there any reason why I can print highStop to the output window, but it is somehow a floating point precision off? Or something odd like that?

      Comment


        #4
        In this case it does sound like it is a rounding issue.

        Try doing this

        highStop = Math.Round(highStop, 2);

        and let me know if this fixes the issue.
        LanceNinjaTrader Customer Service

        Comment


          #5
          That worked. Thanks Lance.

          I realize now that even though I was already rounding the highStop value, the value was being adjusted at a later time and I neglected to round it again. Didn't even bother to check because I was certain I had already done it. woops.


          Thanks again.

          Comment


            #6
            Glad I could help.

            Let me know if I can further assist.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ScottWalsh, 04-16-2024, 04:29 PM
            7 responses
            34 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cls71, Today, 04:45 AM
            0 responses
            3 views
            0 likes
            Last Post cls71
            by cls71
             
            Started by mjairg, 07-20-2023, 11:57 PM
            3 responses
            214 views
            1 like
            Last Post PaulMohn  
            Started by TheWhiteDragon, 01-21-2019, 12:44 PM
            4 responses
            546 views
            0 likes
            Last Post PaulMohn  
            Started by GLFX005, Today, 03:23 AM
            0 responses
            3 views
            0 likes
            Last Post GLFX005
            by GLFX005
             
            Working...
            X