• 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

Incorrect values

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

    Incorrect values

    Hello,
    In my code I am comparing the [1] and [0] value of a line.
    if(downward_impulse && Signal_Line[1] == -100 && Signal_Line[0] > -100)
    {
    DrawDot("MyDot" + CurrentBar, true, 0, High[0] + .1, Color.Green);
    }
    The dot is not printing in the proper place. According to the data box and the Output window the statement is true when [1] and [0] are -100, which obviously is not according to code. I thought perhaps that the the Data box and Output Window were not printing all the decimal places, but when Signal line != -100 the Data box and Output Window are printing number out to the 13th decimal place. Can someone give me an idea why this statement is printing true when the it's actually false? Thanks.
    Last edited by CaptainAmericaXX; 07-11-2016, 08:06 PM.

    #2
    Hello,

    Thank you for the question.

    It would be hard to say without seeing the output from the indicator, but it certainly could be related to comparing float numbers.
    Could you try a print like the following and provide the output?

    Code:
    Print("downward_impulse " + downward_impulse  + " Signal_Line[1] " + Signal_Line[1] + " Signal_Line[0] " + Signal_Line[0]); 
    if(downward_impulse && Signal_Line[1] == -100 && Signal_Line[0] > -100)
    {
    Print("condition true");
    DrawDot("MyDot" + CurrentBar, true, 0, High[0] + .1, Color.Green);
    }
    If this is related to floating point math, You could try a different type of condition like the ones listed here to see if this is related to the floating point values.

    If the value of Signal_Line[1] and Signal_Line[0] are both exactly equal to -100 I don't see how the condition could become true because the check is for greater than and not equal to.



    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 07-12-2016, 08:24 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse,
      Thanks for your help on this. I did as you suggested and provided the output. The condition is indeed printing true when it's clearly untrue. Weird! The only part of the condition that is consistent is the bool. I have never used floats before so I'm uncertain how to proceed that way, but if it's a float issue I don't understand why the output is showing -100. or -50. etc. What do you think?
      Attached Files

      Comment


        #4
        Hello,

        Thank you for the reply.

        Could you try the following check to see if this may be floating point related, I am unable to see what may be making the condition true with the values being printed.

        Code:
        if(downward_impulse && Math.Abs(Signal_Line[1]  - -100) == 0 && Math.Abs(Signal_Line[0] - -100) > 0){
        
        }
        This compares if there is any remaining value from the subtraction of the target value. This is one suggested way to check a floating point number, due to how these numbers are stored in memory, in certain cases == statements may become true when they are not actually true.

        Please try this, if this condition is able to prevent the condition from becoming true incorrectly, this is likely related to the values the indicator was producing.

        If the condition is still becoming true incorrectly, I would likely need to be able to run the script in order to better understand why. If that is the case, I would ask if you could either upload a sample to the forum, or if not please email me at our platformsupport[at]ninjatrader[dot]com for further assistance.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Jesse thanks for your help so far. I figured out what was wrong, but I don't know why it's happening or how to fix it. It has to do with my indicator. Although the line is printing correctly, in the If() the Close[0] is getting compared to the value of the indicator [1] (which is correct) instead of the indicator value[0]. Here is the code of the indicator:
          Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "Signal_Line"));
          double signal_line= ROC(SMA(8),10)[0];
          if(downward_impulse && Signal_Line[1] == -100 && Signal_Line[0] > -100)
          {
          DrawDot("MyDot" + CurrentBar, true, 0, High[0] + .1, Color.Green);
          Print("!!!Condition true!!!");
          }
          Signal_Line.Set(signal_line);
          [Browsable(false)]
          [XmlIgnore()]
          public DataSeries Signal_Line
          {
          get { return Values[0]; }
          }
          Any ideas? Thanks
          Last edited by CaptainAmericaXX; 07-13-2016, 11:22 PM.

          Comment


            #6
            Hello,

            I am not sure I understand the reply completely as the syntax does not seem to match what you have described.

            Originally posted by CaptainAmericaXX View Post
            in the If() the Close[0] is getting compared to the value of the indicator [1] (which is correct) instead of the indicator value[0].
            The syntax seems to be the syntax we have already been looking at, but I do not see Close[0] used or compared here.

            I had also noted one other item, had you intended to Set the series after you had used it instead of before using it?

            You are checking if(downward_impulse && Signal_Line[1] == -100 && Signal_Line[0] > -100)

            But you are setting the value of Signal_Line after this condition, was this intentional?

            Signal_Line.Set(signal_line);

            The most updated value would need to be set Before this condition if you had intended to use the Current value of double signal_line= ROC(SMA(8),10)[0];

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Jesse,
              My apologies for pasting the .Set in the wrong place and not being specific in my explanation. You are correct there is no Close[0] in the if(). Some how before Signal_Line is instantiated with Signal_Line.Set(signal_line); it is receiving the value of Close[0] and this value is being used in the condition. The code is simple. I showed you the major portions. Nowhere am I making Signal_Line = Close[0] yet it is happening. After Signal_Line is set the indicator is accurate, but somehow Close[0] is still getting figured in the CurrentBar, but the PreviousBar is getting the indicator value. The condition is being set to true because the PreviousBar is -100 and the CurrentBar is 45.whatever which of course is greater.
              My question to you is: with Close[0] being nowhere in my code, how is Signal_Line being given that value? I've included an output readout. Thanks.
              Edit: I discovered the answer to my question. I was printing the value of Signal_Line before it was set, therefor I believe it was grabbing the Default Input which was Close[0] and printing that.
              Unfortunately I'm still having issues with the code. I believe it is a floating point issue. I'm studying the info you gave me. I'll figure it out. Thanks for your help!
              Attached Files
              Last edited by CaptainAmericaXX; 07-14-2016, 08:53 PM.

              Comment


                #8
                Hello,

                Thank you for the reply, that explains the situation much more clearly thank you.

                The reason you are seeing the Close[0] price is actually what I had noted in the prior message.

                You are assigning the value of the Plot after checking it meaning that a "dummy" (the Close price value) is used.

                In this case, you would need to first set the plots value for the current bar because you need to use it afterwords. If the Current bars value is not what you need, you could shift the bars ago back by 1 index to get the previous bars while still setting the Current plot value.

                Please try the following to see if this corrects the output for you:

                Code:
                double signal_line= ROC(SMA(8),10)[0];
                
                Signal_Line.Set(signal_line);
                
                if(downward_impulse && Signal_Line[1] == -100 && Signal_Line[0] > -100)
                {
                DrawDot("MyDot" + CurrentBar, true, 0, High[0] + .1, Color.Green);
                Print("!!!Condition true!!!"); 
                }
                The value for the plot is calculated, the plot is set, then the plot is accessed to get a value for another condition.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Parmenides48, 04-09-2019, 03:32 AM
                8 responses
                43 views
                0 likes
                Last Post brucerobinson  
                Started by NinjaCustomer, Today, 01:48 AM
                0 responses
                2 views
                0 likes
                Last Post NinjaCustomer  
                Started by aligator, Yesterday, 10:11 PM
                0 responses
                2 views
                0 likes
                Last Post aligator  
                Started by psquare, Yesterday, 03:11 PM
                4 responses
                20 views
                0 likes
                Last Post psquare
                by psquare
                 
                Started by ballboy11, Yesterday, 03:20 PM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X