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 Haiasi, 04-25-2024, 06:53 PM
          2 responses
          16 views
          0 likes
          Last Post Massinisa  
          Started by Creamers, Today, 05:32 AM
          0 responses
          5 views
          0 likes
          Last Post Creamers  
          Started by Segwin, 05-07-2018, 02:15 PM
          12 responses
          1,786 views
          0 likes
          Last Post Leafcutter  
          Started by poplagelu, Today, 05:00 AM
          0 responses
          3 views
          0 likes
          Last Post poplagelu  
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,407 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Working...
          X