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 pechtri, 06-22-2023, 02:31 AM
      9 responses
      122 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by frankthearm, 04-18-2024, 09:08 AM
      16 responses
      64 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by habeebft, Today, 01:18 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by benmarkal, Today, 12:52 PM
      2 responses
      13 views
      0 likes
      Last Post benmarkal  
      Started by f.saeidi, Today, 01:38 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X