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

Intraday Intesity problems / calculation returns NaN

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

    Intraday Intesity problems / calculation returns NaN

    Hi,

    I am trying to code an Intraday Intensity oscillator, involving only some very simple arithmetic - however, the calculation is failing. I have been adding parts of the calculation into a test script to pinpoint where the issue is, and it appears to be with the following division for 'tempval3':

    double tempval1 = ((2*Close[0]) - High[0] - Low[0]);
    double tempval2 = (High[0]-Low[0]);
    double tempval3 = tempval1/tempval2;
    temp.Set(tempval2);
    Print(tempval3);
    I_Intensity.Set(temp[0]);

    I can plot tempval1, no problems. The same applies to tempval2, but no plot shows for tempval3.

    In the output window, I notice that tempval3 is returning lots of -1 and 1 values, and also NaN occasionally.

    Any ideas why this could be - as far as I can see I am only asking for the most basic of arithmetic here?

    Thanks in advance

    Julian

    #2
    Hello Julian,
    Thanks for writing in and I am happy to assist you.

    In case High and Low are equal you are then dividing tempval1 with 0 (zero). In such case you will get NaN.

    You can filter your code with

    Code:
    if (double.IsNaN(tempval3))
    {
       //do something
    }
    Please use the Print() function to debug the code throughly. Please go through this post which discusses how to debug in NinjaTrader http://www.ninjatrader.com/support/f...ead.php?t=3418

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thanks - my sheer stupidity on this one. Yesterday was a long day...

      Comment


        #4
        Hello Julian,
        Glad you could figure it out.
        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by PaulMohn, Today, 12:36 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by yertle, Yesterday, 08:38 AM
        8 responses
        36 views
        0 likes
        Last Post ryjoga
        by ryjoga
         
        Started by rdtdale, Today, 01:02 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by alifarahani, Today, 09:40 AM
        3 responses
        16 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by RookieTrader, Today, 09:37 AM
        4 responses
        19 views
        0 likes
        Last Post RookieTrader  
        Working...
        X