Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NinjaScript 8 - Does it allow Negative Index and has Double.NaN been fixed?

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

    NinjaScript 8 - Does it allow Negative Index and has Double.NaN been fixed?

    Trying to bring over some TOS (Thinkorswim Thinkscript) to Ninja Trader so that I can use this output to do a whole bunch of other logic.....but I need this Indicator first.

    Questions:
    1) Can I use Negative Indexing? (not [1] or [0] but [-1] or [-i])

    2) Can I use Double.NaN for a Double field to not plot a value? (I do not want a "0"...I want a NaN/Null)

    All my code was working correctly until I added this section of code below. After adding this I get no Compile errors....but nothing draws/calculates on my indicator any more.

    Any Answers to my questions and any Suggestions?

    if (HighPoint[0] > 0 && Offset[0] > 1) {
    for (int i = 1; i < Offset[0]; i++) {
    tH[0] = PriceH[0];
    if (!double.IsNaN(tH[0]) && !NewState[-i]) {
    if (NewMax[-i] && PriceH[-i] == tH[0]) {
    LastH[0] = double.NaN;
    } else {
    LastH[0] = tH[0];
    }
    } else {
    LastH[0] = double.NaN;
    }
    }
    } else {
    LastH[0] = double.NaN;
    }
    Last edited by BigT4X; 03-11-2022, 01:32 PM.

    #2
    Hello BigT4X,

    negative indexing is not something that is used in NinjaScript, you would use 0 or positive numbers to represent BarsAgo.

    If you wanted to not plot a value you would just not assign a value to the plot, it will be considered an invalid data point and won't be rendered. double.NaN is only shown when a number that is NaN is calculated, that otherwise wouldn't be something you can just set to a plot.



    Comment


      #3
      Regarding Negative Indexing.....so no other way to do "BarsAhead" (future bars)? Or instead lets say re-calculate past bars when a new valid data point comes in.......and remove the old one? Looking for ideas on this.

      Regarding NaN....(or assigning Null to a Double).....I saw another post requesting this. Status on this upgrade? It is available in other multiple platforms.... Does Nullable Double (Available in C#) work in Ninjascript? Any other ideas on this?

      Comment


        #4
        Hello BigT4X,

        There is no concept of bars ahead, the script is always processing the most recent data point in the series so you can only look backwards or set the current value. You can recalculate and reset past values, you would use a BarsAgo to set a plot value like plotName[5] = someValue;


        For double.nan I am not certain what you are trying to achieve with that, if you don't want a value you would just not set a value. That makes an invalid plot value for that bar and its not rendered. If you wanted to know its an invalid plot value you can use the method to check for that.


        Double.Nan is otherwise not a number that could be plotted, thats only represented in the UI if not a number is calculated.


        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        602 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        347 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        559 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X