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

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,
    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    3 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Working...
    X