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 fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,406 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        98 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        9 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X