I am having a very strange issue with some of my limit orders in my backtests of this strategy. The general logic is as follows:
1. Search for levels and add new ones to list
2. Place orders for levels that currently do not have an order attached
3. Profit
This is working great for most levels, but there are some (can't find a distinction to separate working from not) that simply don't get placed. Here is what I have tried and a bit of the code:
1. Enabled order traces.
An order that is not working:
Entered internal SubmitOrderManaged() method at 2024-09-26 7:51:08 AM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=20338.50 StopPrice=0 SignalName='ShortSignal20339.25' FromEntrySignal=''
An order that IS working:
Entered internal SubmitOrderManaged() method at 2024-09-26 7:51:08 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=20209.00 StopPrice=0 SignalName='LongSignal20208.25' FromEntrySignal=''
2. Order state logging.
An order that is not working prints nothing.
An order that IS working prints:
Order submitted: LongSignal20208.25
Order accepted: LongSignal20208.25
Order working: LongSignal20208.25
3. Other logging.
Here is the relevant order management code (same for buys):
foreach (int levelIndex in masterSellEvaluated[1])
{
try
{
PrintDebug("This is the master list: " + masterSellLevels);
PrintDebug("LEVEL IN MASTER LIST: " + masterSellLevels[levelIndex]);
masterSellLevels[levelIndex].order = EnterShortLimit(0, true, Quantity, masterSellLevels[levelIndex].lowPrice - (FrontrunTicks * TickSize), masterSellLevels[levelIndex].signalName);
if (masterSellLevels[levelIndex].order == null)
{
PrintError("abc123 FAILED AT: " + (masterSellLevels[levelIndex].lowPrice - (FrontrunTicks * TickSize)));
}
else
{
PrintInfo("ENTERED SHORT LIMIT AT: " + (masterSellLevels[levelIndex].lowPrice - (FrontrunTicks * TickSize)));
PrintDebug("The level in the master list: name - " + masterSellLevels[levelIndex].signalName + " | order details - " + masterSellLevels[levelIndex].order + " , " + masterSellLevels[levelIndex].order.LimitPrice + " , " + masterSellLevels[levelIndex].order.OrderAction);
}
}
catch (Exception e)
{
if(LogErrors)
Print("Error submitting order: " + e.Message);
}
}
Removal of expired levels comes after the submitting, so indexes are not broken. It is the correct level being modified.
The following is printed after the order trace message...
An order that is not working prints:
abc123 FAILED AT: 20338.5
An order that IS working prints:
ENTERED LONG LIMIT AT: 20209
The level in the master list: name - LongSignal20208.25 | order details - orderId='NT-00046-1028' account='Backtest' name='LongSignal20208.25' orderState=Working instrument='NQ 12-24' orderAction=Buy orderType='Limit' limitPrice=20209 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-09-25 13:02:38' gtd='2099-12-01' statementDate='2024-10-08' , 20209 , Buy
I simply don't understand how I can explicitly set the order of a level and then in the next line of code it is null? Makes no sense when the order trace says that it got placed.
And no it does not have to do with the current price being unfit for limit orders. Close at placement of the working order was Close: 20224.5 and at non working order was Close: 20296.25
It is also not only sells that have the issue, both long and short have working and non working.
If anyone has any idea, please let me know. I am completely stumped and discouraged. Also, thanks for taking the time to read through and help me out <3

Comment