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 Mizzouman1, Today, 07:35 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by RubenCazorla, Today, 09:07 AM
        2 responses
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by i019945nj, 12-14-2023, 06:41 AM
        7 responses
        82 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by timmbbo, 07-05-2023, 10:21 PM
        4 responses
        158 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by tkaboris, Today, 08:01 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X