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

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:

    Loop over elements with the foreach keyword. Compare other loops and review errors.


    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          ok thanks i'll try those

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Tim-c, Today, 02:10 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Taddypole, Today, 02:47 PM
          0 responses
          2 views
          0 likes
          Last Post Taddypole  
          Started by chbruno, 04-24-2024, 04:10 PM
          4 responses
          50 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          10 responses
          399 views
          1 like
          Last Post beobast
          by beobast
           
          Started by lorem, Yesterday, 09:18 AM
          5 responses
          25 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X