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

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 ZenCortexCLICK, Today, 04:58 AM
        0 responses
        1 view
        0 likes
        Last Post ZenCortexCLICK  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        172 responses
        2,279 views
        0 likes
        Last Post sidlercom80  
        Started by Irukandji, Yesterday, 02:53 AM
        2 responses
        17 views
        0 likes
        Last Post Irukandji  
        Started by adeelshahzad, Today, 03:54 AM
        0 responses
        4 views
        0 likes
        Last Post adeelshahzad  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X