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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    156 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    90 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    139 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    130 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    107 views
    0 likes
    Last Post CarlTrading  
    Working...
    X