• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 sdauteuil, Today, 11:02 PM
      1 response
      2 views
      0 likes
      Last Post sdauteuil  
      Started by Jschmelz, Today, 04:45 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Marco  
      Started by sisenberg, Today, 08:06 PM
      1 response
      8 views
      0 likes
      Last Post sisenberg  
      Started by priceisking, Today, 07:44 PM
      0 responses
      5 views
      0 likes
      Last Post priceisking  
      Started by saltminer, Today, 06:06 PM
      0 responses
      5 views
      0 likes
      Last Post saltminer  
      Working...
      X