Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

updating Order list on realtime

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

    updating Order list on realtime

    Hello. I have a List containing various stop orders. I'm trying to set it up so that if a strategy shuts down and then restarts all those orders are changed from historical to realtime. In the State = State.Realtime, I have written:

    foreach (Order o in StopList)
    stopList(o) = GetRealtimeOrder(o)

    but the compiler doesn't like that. I feel like this should be straightforward but clearly I don't understand either how Lists work or how the GetRealtimeOrder works. Can you help me?

    Thanks

    #2
    Hello stewarco,

    Thanks for the note.

    When you use a foreach loop, you do not need to reference the list again in the loop body, it will iterate each value in the List object. I do not have the full context here, but you can do this to make it work:

    Code:
    foreach (Order o in StopList)
    o = GetRealtimeOrder(o)
    Here is a publicly available link that includes some examples of using foreach:



    Please let me know if I can assist further.

    Comment


      #3
      follow up

      thanks. I'll review the link you provided, and I had tried the language you suggested, but I get the Error message "Cannot assign to 'o' because it is a 'foreach iteration variable'. any idea what's going on there?

      Comment


        #4
        Hello stewarco,

        Thanks for the reply.

        Sorry I did not catch that. You can not mutate the actual iteration object while doing a foreach. You will either have to use a regular for loop like so:

        Code:
        for(int i = 0; i < myList.Count; ++i)
        			{
        				Print(myList[i]);
        			}
        Or you can use the List class IndexOf method to get the index from the object being iterated.

        https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx - IndexOf

        There are also other solutions, like this change method described in this post:

        In one place i am using the list of string in that case the i am able to change the value of the string as code given below, foreach(string item in itemlist.ToList()) { item = someValue; //I am...


        Please let me know if I can assist further.

        Comment


          #5
          ok thanks i'll try those

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          43 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          20 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          30 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          48 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          38 views
          0 likes
          Last Post CarlTrading  
          Working...
          X