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

Setting Values for a DataSeries variable

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

    Setting Values for a DataSeries variable

    Hi Ninjas,

    I have a technical doubt here assigning values to a DataSeries variable.

    I know one method to do it is using variable.Set() ; but I've done this too that seems to work quite well: variable[0]= X .

    My technical doubts:

    1. The second method is totally right or it't not much "orthodox" having risk of errors?
    2. Are equally fast both of them, or is there any of them faster ?


    Thanks a lot for any hint

    #2
    Hello,

    Both methods are perfectly acceptable, and neither method should have a noticeable impact on speed or performance. I would say that you might favor .Set() when you wish to set the most recent index, and favor variable[0] = x when you wish to set a historical index, but it's really a matter of personal preference, and how you like to format your code.

    Please let me know if I can assist further.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Originally posted by pstrusi View Post
      Hi Ninjas,


      2. Are equally fast both of them, or is there any of them faster ?


      Thanks a lot for any hint
      It really depends on how the code is optimized by the compiler.

      If the compiler is smart enough to remove the overhead of the function call, then both will be the same. If the compiler makes the function call, there are stacks to push and other stuff, and will be more expensive time wise.

      I guess you could test both ways and time them.

      You might be able to make it more extreme, and use a for loop of say 10,000 or even more (just don't get too big), for every tick and call SET or use the variable assignment.

      The should show 1 is faster or both are the same (because the .set is being optimized to just be an assignment).

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by usazencort, Today, 01:16 AM
      0 responses
      1 view
      0 likes
      Last Post usazencort  
      Started by kaywai, 09-01-2023, 08:44 PM
      5 responses
      603 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      6 responses
      23 views
      0 likes
      Last Post xiinteractive  
      Started by Pattontje, Yesterday, 02:10 PM
      2 responses
      22 views
      0 likes
      Last Post Pattontje  
      Started by flybuzz, 04-21-2024, 04:07 PM
      17 responses
      230 views
      0 likes
      Last Post TradingLoss  
      Working...
      X