Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

modified collection

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

    modified collection

    I don't quite understand what this error is
    Attached Files

    #2
    Hello franatas,

    That is a general C# error that can happen when trying to add or remove items from a collection that is use. The error shows that it is coming from one of your scripts in the OnBarUpdate section of its code. You would have to find a situation which causes that error so you can test the code inside that script to get a better idea of why that's happening.

    Comment


      #3
      I think the error occurs when trying to cancel an order that has just been executed or is in the queue, any ideas to avoid it?

      Comment


        #4
        if (Position.MarketPosition == MarketPosition.Flat && CurrentBar > Velaentrada)
        {
        if (OrdenEntrada != null)
        {
        CancelOrder(OrdenEntrada);
        }

        if (OrdenStop != null)
        {
        CancelOrder(OrdenStop);
        }

        if (OrdenProfit != null)
        {
        CancelOrder(OrdenProfit);
        }
        }
        This is where I think the problem is, and another thing that is happening to me is that the analyzer does not cancel on the next candle and executes positions after this candle​

        Comment


          #5
          Hello franatas,

          Are you saying that you tried to cancel a filled order and see that happening or was the order still working? If you tried to cancel a filled order you would need to make sure that you are using OnExecutionUpdate to check for that filled order to reset your order variables.

          Generally this type of logic would executed separately, it would not be common to submit a entry which is waiting to fill and also have targets actvie at that point. Most commonly you would have an entry condition that submits an entry, if that entry is waiting to fill the targets would be submitted later from OnExecutionUpdate once the entry fills. If you need to cancel the entry you would just cancel that by its self because the targets would not have been submitted yet.

          Comment


            #6
            I have been doing debugging and I am not sure but I think the problem is that at the end of a candle it cancels the order that is placed, but if the fact occurs that at the opening of the next candle it has to open another operation it sends the order and it automatically cancels it too, being an error here since CurrentBar > VelaEntrada at this moment are already the same and should not cancel the new order
            if (ContratosSell >= 1)
            {
            EnterShortStopLimit(0, true, ContratosSell, PrecioEntrada - 2 * TickSize, PrecioEntrada, "CORTOS");
            Velaentrada = CurrentBar;
            ContadorRelleno = 0;
            }​
            but I think that canceling this new one that is being sent at the same moment is what produces the error, and on the other hand this cancellation logic does not occur in the analyzer, since in it it does not cancel the old order and therefore It doesn't try to open the new one either.

            candle 1 gives entry and candle 2 must break the low, if it does not, at close it must cancel, but here it does it wrong and does not cancel
            On the contrary, the 3 gives the input and the 4 at rmper the maximum opens the input, it is correct,
            This logic executes it well in demo but not in the analyzer​

            Attached Files
            Last edited by franatas; 06-19-2023, 11:05 AM.

            Comment


              #7
              no se si me explique bien, espero se entienda el problema, que son dos en realidad

              Last edited by franatas; 06-19-2023, 11:06 AM.

              Comment


                #8
                Hello franatas,

                Yes that could be the problem, in that case you are trying to submit the same order that you are also cancelling. To avoid that you would need to either leave the order active instead of cancelling it and resubmitting it or cancel it and then wait for confirmation that it was cancelled in OnOrderUpdate before allowing another entry.
                Last edited by NinjaTrader_Jesse; 06-19-2023, 11:33 AM.

                Comment


                  #9

                  there it is, let's see tomorrow if the error is resolved, thank you very much and about the problem of different behavior in parser?​

                  Comment


                    #10
                    Hello franatas,

                    I am not sure what you are referring to with a parser, can you provide more detail on what question you still have?

                    Comment


                      #11
                      In the screenshot I describe what it should do and does not do, the code is programmed so that on the next candle of the signal, if the trade has not been opened at the break of the max, it cancels the order, in the demo it does it well but in the analyzer opens operations two and three candles later, that is, it does not cancel the operation to the following candle

                      Comment


                        #12
                        Hello franatas,

                        Are you using OnEachTick or OnPriceChange as the calculate setting for the strategy? In a backtest the strategy is run OnBarClose, that could explain differences you see in when your conditions become true.

                        Comment


                          #13
                          I use OnEachTick and stop/tick in the configuration, but the cancellation is candle close
                          if (Position.MarketPosition == MarketPosition.Flat && CurrentBar > Entry Candle)
                          {
                          if (EntryOrder != null)
                          {
                          CancelOrder(EntryOrder);
                          }

                          if (SellContracts >= 1)
                          {
                          EntryCandle = CurrentBar;
                          EnterShortStopLimit(0, true, ContractsSell, EntryPrice - 2 * TickSize, EntryPrice, "SHORT");
                          FillCounter = 0;
                          }​​

                          Comment


                            #14
                            Hello franatas,

                            If you use OnEachTick you would need to test the strategy in realtime, a backtest always uses OnBarClose.

                            In a backtest you would also see executions or order changes on the following bar from where the condition was true.

                            You could add a 1 tick secondary series and execute your logic from that series if you wanted to simulate using OnEachTick while doing a backtest, that would let you run logic for each tick.

                            Comment


                              #15
                              when the modified collection error occurs, the strategy closes even having this configuration: RealtimeErrorHandling.IgnoreAllErrors;
                              Is there a way to keep the strategy active?​

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              581 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              338 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              554 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              552 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X