• 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

Collection modified

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

    Collection modified

    I use BarRequest to load data from a specific different TradingHours than the primary bars.

    Now I use a method to manipulate real time bar event. (OnRequestUpdate)
    In that method I use the for (int i = e.MinIndex; i <= e.MaxIndex; i++) loop
    to do stuff and I call OnRender() to update the chart.

    In OnRender() I display stuff based on price and I loop through dictionaries.

    I sometimes see a flickering of the chart and get the error message : Collection was modified after the enumerator was instantiated...

    I do a ForceRefresh() after the for loop because primary bars are always closed when this second bar series is active.

    I was wondering if I get this error because new data comes in before the ForceRefresh() finish its job !

    How should I approach this whole problem ?

    Thank you !

    #2
    Hello,

    Thank you for the post.

    In this case, the exception is generally telling you what is happening. As the collection is being modified, the loop statement cannot continue correctly. Generally, this occurs with foreach loops over collections. Often this can be resolved by using a for loop with an index instead. You may try to just replace any foreach loops you are using on collections that may be modified. As I have not seen your code this would be an educated guess based on the exception.

    Also, you noted "and I call OnRender() to update the chart."

    Do you mean that you are physically calling the OnRender override or just mean that you have implemented OnRender?

    It would not be advised to call OnRender yourself, but you could do an action like ForceRefresh or Add a dummy drawing object and then remove it immediately after on the next line of syntax to cause OnRender to be called.

    Another item could be if the script hits an exception and you have it in a try catch, that may be one reason for this to flicker. An exception should generally stop the script completely so you can correct the problem instead of just catching it. If you are using try-catch, you may try removing it and then resolve the exceptions, that may correct it also.

    Without seeing the syntax it would be hard to say exactly what is happening in the script. What I could suggest would be to reduce the code and find what specifically is throwing errors and first correct that. If that does not solve the problem, you could then comment out code until you see it stop and work forward to find the cause.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      How would you "Add a dummy drawing object and then remove it immediately after on the next line of syntax to cause OnRender to be called."

      Thanks

      Comment


        #4
        Hello KINGKODA,

        You would do exactly that, you would call the draw syntax to create an object and then on the following line remove it using RemoveDrawObject() with the tag you used.

        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment

        • Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by SharonSS, Today, 07:21 PM
          0 responses
          2 views
          0 likes
          Last Post SharonSS  
          Started by bmccoard, Today, 06:48 PM
          0 responses
          5 views
          0 likes
          Last Post bmccoard  
          Started by omololu, Today, 05:10 PM
          0 responses
          10 views
          0 likes
          Last Post omololu
          by omololu
           
          Started by fut_practic, Today, 05:01 PM
          0 responses
          8 views
          0 likes
          Last Post fut_practic  
          Started by persoguillermo, Today, 04:38 PM
          0 responses
          4 views
          0 likes
          Last Post persoguillermo  
          Working...
          X