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 kaywai, 09-01-2023, 08:44 PM
    5 responses
    601 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by xiinteractive, 04-09-2024, 08:08 AM
    6 responses
    22 views
    0 likes
    Last Post xiinteractive  
    Started by Pattontje, Yesterday, 02:10 PM
    2 responses
    16 views
    0 likes
    Last Post Pattontje  
    Started by flybuzz, 04-21-2024, 04:07 PM
    17 responses
    230 views
    0 likes
    Last Post TradingLoss  
    Started by agclub, 04-21-2024, 08:57 PM
    3 responses
    17 views
    0 likes
    Last Post TradingLoss  
    Working...
    X