Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
modified collection
Collapse
X
-
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.
-
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
-
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
-
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
Last edited by franatas; 06-19-2023, 11:05 AM.
Comment
-
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
-
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
-
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
-
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
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
579 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment