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 TraderG23, 12-08-2023, 07:56 AM
    9 responses
    382 views
    1 like
    Last Post Gavini
    by Gavini
     
    Started by oviejo, Today, 12:28 AM
    0 responses
    1 view
    0 likes
    Last Post oviejo
    by oviejo
     
    Started by pechtri, 06-22-2023, 02:31 AM
    10 responses
    125 views
    0 likes
    Last Post Leeroy_Jenkins  
    Started by judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    59 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Yesterday, 06:52 PM
    4 responses
    36 views
    0 likes
    Last Post ScottWalsh  
    Working...
    X