Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot apply indexing with [] to an expression of type `object'

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

    Cannot apply indexing with [] to an expression of type `object'

    I'm attempting something very simple:

    double myVariable = (variable1[0] + variable1[1] + (variable1[2] + variable1[3] + variable1[4]) / 5

    I get 'Cannot apply indexing with [] to an expression of type `double''.

    How can I fix this?

    Thank you.

    #2
    Hello Imalil,

    Thank you for writing in.

    Likely the issue you are having is you are trying to designate a bar index on variable1 which is a type double, not a data series. This means you cannot reference 2 bars ago since it only contains 1 number at any given time. If you’d like to store values to a data series so you could reference their value say 2 bars ago, you would need to create a variable data series and assign values to it.

    Please see DataSeries Class Section of our Helpguide,


    Note, this would not be possible to do in the strategy wizard however would be rather easy to accomplish if you went to Unlock Code and followed the format in the link above.

    I have provided a link on using the NinjaScript Editor as well,


    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    557 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X