(See the attached images)
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!
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
NinjaTrader
I need to prevent strategy from being thrown at me.
Collapse
X
-
I need to prevent strategy from being thrown at me.
By means of a strategy that I develop, I place orders Buy Stop Limit, and Sell Stop limit, but sometimes the market is faster than the code to place the order, and when that happens, it shows me the following two messages, and it removes me the strategy, my question is, how can I do that if that happens, it doesn't take away my strategy ?, because when this happens I lose time while I activate it again, clicking on the check.
(See the attached images)Tags: None
-
Hello AdSeque,
Thank you for your post.
It is possible to tell your strategy to remain running when an order error is encountered. Setting RealTimeErrorHandling to IgnoreAllErrors will allow your strategy to keep running when errors like these are encountered (the popups will still appear to let you know an error was encountered).
However, setting RealtimeErrorHandling to IgnoreAllErrors can have serious adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method. You would need to monitor for any rejected orders and then resubmit or otherwise handle the rejection.
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
-
Hello AdSeque,
Thank you for your reply.
This error can be seen for a number of reasons both within a strategy and when manually placing OCO (One Cancels Other) linked orders. In a strategy, we would usually see this in cases where a stop and profit target are submitted together for an order but one is rejected. Since these would be OCO linked to each other so that if one is filled the other one is cancelled, one getting rejected causes the other to not be accepted since there's an OCO id for the orders to link them together but the other order doesn't exist now.
Basically, it's an additional error telling you that it couldn't place the profit target when you have an initial error in which your stop was rejected.
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
Comment
-
Hello AdSeque,
Thank you for your reply.
There wouldn't be a way to completely avoid this - in a fast moving market there's always the chance the market will move far enough so quickly that in the time between you placing the order and it arriving to the broker that it could be on the wrong side of the market and be rejected. Turning on IgnoreAllErrors will simply allow you to handle what occurs in the script when a rejection is seen. For example, you could monitor in OnOrderUpdate and if your stop and target get rejected you could then attempt to resubmit the orders at a new price. Moving your stop and target further from the current price in the first place may reduce the chances of this occurring.
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
Comment
-
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
// check if the current order matches the orderName passed in "EnterLong"()
// Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
// This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
if (order.Name == "BuyOrder")
BuyOrder = order;
// if entry order exists
if (BuyOrder != null && BuyOrder == order)
{
Print(order.ToString());
if (order.OrderState == OrderState.Cancelled)
{
// Do something here
BuyOrder = null;
}
}
//
if (order.Name == "SellOrder")
SellOrder = order;
// if entry order exists
if (SellOrder != null && SellOrder == order)
{
Print(order.ToString());
if (order.OrderState == OrderState.Cancelled)
{
// Do something here
SellOrder = null;
}
}
}
---------------------------------------------------------------------------------------------------------------
Following the example of the tutorial, what this does is cancel the order, but the strategy would continue to work, if it meets the criteria again?
Comment
-
Hello AdSeque,
Thank you for your reply.
This code would not cancel an order - this would check to see if an order is in a cancelled state and if so reset the order object to null. Further, these errors are likely coming through as OrderState.Rejected, so you would want to check for that state and then try resubmitting an order at a new price, or simply closing the open unprotected position directly by submitting an order to close it.
Also, unless you have changed the RealTimeErrorHandling in State.SetDefaults to IgnoreAllErrors the strategy would be stopped on a rejection.
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by PaulMohn, Today, 03:49 AM
|
0 responses
6 views
0 likes
|
Last Post
by PaulMohn
Today, 03:49 AM
|
||
Started by inanazsocial, Today, 01:15 AM
|
1 response
9 views
0 likes
|
Last Post Today, 02:18 AM | ||
Started by rocketman7, Today, 02:12 AM
|
0 responses
10 views
0 likes
|
Last Post
by rocketman7
Today, 02:12 AM
|
||
Started by dustydbayer, Today, 01:59 AM
|
0 responses
4 views
0 likes
|
Last Post
by dustydbayer
Today, 01:59 AM
|
||
Started by trilliantrader, 04-18-2024, 08:16 AM
|
5 responses
23 views
0 likes
|
Last Post Today, 12:32 AM |
Comment