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.

    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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        566 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X