Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Getting Pending Order Cancel From Strategy
Collapse
X
-
Hello samish18,
With the script you have provided, you are ensuring that the order is not in an accepted state.
You will need to instead check the order is in a working or accepted state.
if (myEntryOrder != null && (myEntryOrder.OrderState == OrderState.Accepted || myEntryOrder.OrderState == OrderState.Working))
CancelOrder(myEntryOrder);Chelsea B.NinjaTrader Customer Service
Comment
-
Hello samish18,
There are differences between real-time and backtest.
To understand specifically what is causing differences with your script, it would be necessary to write the information the script is processing to text file and compare the output.
Below is a link to a support article with direction.
Chelsea B.NinjaTrader Customer Service
Comment
-
Hello samish18,
If the results are different, then either the data (bar type, interval, range from first to last bar) or the logic is different.
Writing the values out to file tells us what is different and why the results are different.
This relates to your script because you are getting different number of trades.Chelsea B.NinjaTrader Customer Service
Comment
-
Hello samish18,
The article linked in post # 19 provides an example script that writes information to text file and a video demonstrating how the information can be used to see what values, order times, execution prices, etc., are specific different between backtest and real-time and why.
The example is using the C# StreamWriter class to write to file.
This also discusses using TickReplay and 1-tick intra-bar granularity.
The values should be written to file one line above the conditions that submit the order, and should include the time of the bar and all values used in the condition set along with labels for each value and comparison operator (so we know how the values are being compared).
Further in OnOrderUpdate / OnExecutionUpdate the order.ToString()/execution.ToString() should be written as well, to see the order objects update and the fill times and prices.
The start bar date and time and end bar date and time must be the same. If you don't plan to test for an entire session in real-time, you can test over a small amount of time defined in a custom trading hours template. This is demonstrated in the video linked from the article.
Run this in real-time, then backtest over the exact same data, and provide the output from each.
I'll be happy to assist with analyzing the output and spotting what is causing differences.Chelsea B.NinjaTrader Customer Service
Comment
-
I am now getting an error: Sim101, Order 'abc...' can't be submitted: The OCO ID 'xyz...' cannot be reused. Please use a new OCO ID and then the following message "Strategy submitted an order theat generated the following error 'Order Rejected'. Strategy sent cancel requests, attempted to close the position and terminated itself." How may I fix this issue?
Comment
-
Hello samish18,
This would depend on why the order was rejected.
What was the full error message?
May I have you copy and paste this? (Click on the error message on the Log tab of the Control Center and press Ctrl + c to copy then Ctrl + v to paste in your next post)
Chelsea B.NinjaTrader Customer Service
Comment
-
Hello samish18,
Is there one more error appearing on the Log tab of the Control Center?
The OCO rejected order is due to the order using an OCOID that was already used by a previous order that is either rejected, filled, or cancelled.
As you are using the managed approach, this is likely from a Set method like SetStopLoss() and SetProfitTarget().
My guess is that a stop was submitted with an invalid stop price.Chelsea B.NinjaTrader Customer Service
Comment
-
Hello samish18,
We would want to confirm the issue first.
May I have a screenshot of the Log tab of the Control Center showing buy limit order that was rejected OCO scrolled to the center?
With set methods, you would need to ensure the stop price is below the bid for a sell or above the ask for a buy
double stopPrice = Low[0];
if (stopPrice >= GetCurrentBid())
stopPrice = GetCurrentBid() - TickSize;
SetStopLoss(CalculationMode.Price, stopPrice);
And that these are reset using a number of ticks before calling an entry order method.
SetStopLoss(CalculationMode.Ticks, 20);
EnterLong();Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, 03-13-2026, 05:17 AM
|
0 responses
86 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
151 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
79 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
52 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
59 views
0 likes
|
Last Post
|

Comment