Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Add-On Development

Add-On Development General NinjaScript development questions.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 02-08-2018, 01:24 PM   #1
ronhb107
Senior Member
 
Join Date: Apr 2016
Posts: 108
Thanks: 0
Thanked 2 times in 2 posts
Default Submission rejected???

I get this error msg when trying to Submit the TrailStop order (the current market position is Short): "Buy stop or buy stop limit order can't be placed below the market affected Order: Buy 5 StopMarket @ 0"

NOTE: there is a 3-tick separation in the /ES between the TrailStop and its triggering price level.

Going thru the Output window shows the price for the TrailStop order has a proper price (which is not zero) above the Stop1 price (which, when filled, created a market Short position and triggered the Submit of the TrailStop order). What am I doing wrong here?

This error also occurs if I use a Strategy (vs. an Indicator) for my AddOn code. I have attached the Indicator code.
Attached Files
File Type: zip RBManageOCOorderIndicator.zip (5.2 KB, 4 views)
Last edited by ronhb107; 02-08-2018 at 01:30 PM.
ronhb107 is offline  
Reply With Quote
Old 02-08-2018, 01:43 PM   #2
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 8,443
Thanks: 125
Thanked 1,869 times in 1,745 posts
Default

Hello ronhb107,

What is the specific line of code causing the error?

What is the print that is printing the price just before the order is placed?

What is the output from the print?
NinjaTrader_ChelseaB is offline  
Reply With Quote
Old 02-08-2018, 02:02 PM   #3
ronhb107
Senior Member
 
Join Date: Apr 2016
Posts: 108
Thanks: 0
Thanked 2 times in 2 posts
Default

I am now using a price a tick away from the Entry price (just to see if being within the Entry and Stop1 was causing the problem) and the problem persists.

Here's the Output screen where the rejection occurs...

Code:
ClearOrders   account: Sim101  Orders count: 11
startAt: 2/8/2018 2:54:04 PM
ClearOrders  -  Order name: Entry OrderState: Filled  Price: 2623.75  Quantity: 1  Filled: 1  Time: 02/08/2018 14:54:04.870
ClearOrders  -  Order name: Stop1 OrderState: Filled  Price: 2622.75  Quantity: 6  Filled: 6  Time: 02/08/2018 14:54:10.230
ClearOrders - Submit trailStop.Quantity: 5
OnOrderUpdate - OrderName: TrailStop Price: 2624.25  Quantity: 5  Filled Qty: 0  OrderState: Submitted  Time: 02/08/2018 14:54:10.300
OnOrderUpdate - OrderName: TrailStop Price: 2624.25  Quantity: 5  Filled Qty: 0  OrderState: Rejected  Time: 02/08/2018 14:54:10.303
ClearOrders  -  Order name: Target1 OrderState: CancelSubmitted  Price: 2624.5  Quantity: 1  Filled: 0  Time: 02/08/2018 14:54:10.239
ClearOrders  -  Order name: stopTarget OrderState: Working  Price: 2622.25  Quantity: 5  Filled: 0  Time: 02/08/2018 14:54:05.053
ClearOrders  -  Order name: TrailStop OrderState: Rejected  Price: 2624.25  Quantity: 5  Filled: 0  Time: 02/08/2018 14:54:10.300
ClearOrders count: 11
And here is the code snippet where the rejection occurs...

Code:
if (order.Name == "Stop1")
						{
							isStop1Filled = order.OrderState.Equals(OrderState.Filled);
							// submit a Trailing Stop
							if (isStop1Filled && !isTrailingStop)
							{
								isTrailingStop = true;
								Print("ClearOrders - Submit trailStop.Quantity: " + stopTarget.Quantity);
								account.Submit(new[] { trailStop });
							}
						}
ronhb107 is offline  
Reply With Quote
Old 02-08-2018, 03:22 PM   #4
ronhb107
Senior Member
 
Join Date: Apr 2016
Posts: 108
Thanks: 0
Thanked 2 times in 2 posts
Default Submission rejected???

Found the error. It is now working correctly.

One last point: when the TrailStop is submitted, it leaves a Yellow marker on the Chart which persists after the trade is closed. How can this be avoided (since it cannot be removed from the Chart)?

Thanks,
Ron
Attached Files
File Type: zip RBManageOCOorderIndicator.zip (5.3 KB, 2 views)
ronhb107 is offline  
Reply With Quote
Old 02-08-2018, 04:26 PM   #5
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 8,443
Thanks: 125
Thanked 1,869 times in 1,745 posts
Default

Hello Ron,

There would be a red order line marker if Chart Trader is open and the order is working.

If the order fills this would put an execution marker on the chart.

Are you referring to the execution markers?


Regarding the invalid price, I'm not seeing in the code that you are checking the order's stop price is at least 1 tick less than bid. Likely your price is an invalid price. Also, you should check that the new price of the order is a valid price, one line before order submission so that the price doesn't have time to change either.
Last edited by NinjaTrader_ChelseaB; 02-08-2018 at 04:28 PM.
NinjaTrader_ChelseaB is offline  
Reply With Quote
Old 02-08-2018, 04:38 PM   #6
ronhb107
Senior Member
 
Join Date: Apr 2016
Posts: 108
Thanks: 0
Thanked 2 times in 2 posts
Default Submission rejected???

Hi Chelsea:

Actually, the problem was with the CreateOrder(). See below

Also, I've attached a pic of the markers/flags on the Chart that the TrailStop generates but cannot be removed.

Code:
								if (stopOrder.IsLong)
								// CreateOrder(Instrument instrument, OrderAction action, OrderType orderType, OrderEntry orderEntry, 
								//	TimeInForce timeInForce, int quantity, double limitPrice, double stopPrice, string oco, string name, DateTime gtd, CustomOrder customOrder)
								//  See: https://ninjatrader.com/support/helpGuides/nt8/en-us/?onorderupdate.htm
								{
									stopTarget = account.CreateOrder(stopOrder.Instrument, OrderAction.Sell, OrderType.Limit, OrderEntry.Automated, TimeInForce.Day, 
										stopTargetQty, stopOrder.StopPrice + stopTargetSpread, 0, "", "stopTarget", Core.Globals.MaxDate, null);
									
									trailStop = account.CreateOrder(stopOrder.Instrument, OrderAction.SellShort, OrderType.StopMarket, OrderEntry.Manual, TimeInForce.Day, 
										stopTargetQty, 0, stopOrder.StopPrice - stopTargetSpread, "", "TrailStop", Core.Globals.MaxDate, null);
								}
								else if (stopOrder.IsShort)
								{
									stopTarget = account.CreateOrder(stopOrder.Instrument, OrderAction.Buy, OrderType.Limit, OrderEntry.Automated, TimeInForce.Day, 
										stopTargetQty, stopOrder.StopPrice - stopTargetSpread, 0, "", "stopTarget", Core.Globals.MaxDate, null);
									
									trailStop = account.CreateOrder(stopOrder.Instrument, OrderAction.BuyToCover, OrderType.StopMarket, OrderEntry.Manual, TimeInForce.Day, 
										stopTargetQty, 0, stopOrder.StopPrice + stopTargetSpread, "", "TrailStop", Core.Globals.MaxDate, null);
								}
Thanks,
Ron
Attached Images
File Type: jpg Price Markers on Chart from TrailStop.jpg (128.0 KB, 8 views)
ronhb107 is offline  
Reply With Quote
Old 02-08-2018, 05:02 PM   #7
NinjaTrader_ChelseaB
NinjaTrader Customer Service
 
NinjaTrader_ChelseaB's Avatar
 
Join Date: Dec 2012
Location: Denver, CO
Posts: 8,443
Thanks: 125
Thanked 1,869 times in 1,745 posts
Default

Hello Ron,

These orders are orange because they are stuck.

This often happens when OCO is improperly used.

Please send an email to platformsupport [at] ninjatrader [dot] com so that I may request your log and trace files so that I may read the OCO IDs used.
NinjaTrader_ChelseaB is offline  
Reply With Quote
Old 02-09-2018, 09:39 AM   #8
ronhb107
Senior Member
 
Join Date: Apr 2016
Posts: 108
Thanks: 0
Thanked 2 times in 2 posts
Default

Hi Chelsea:

I've sent the requested files to support.

Btw, I am not using OCO. I suspect these orders are "stuck" because they were in an Initialized state, and then ended in CancelPending state (it never reached the Cancel state when I cancelled all orders). This may be a bug in NT8.

Also, I am 'requesting' that a Trail Stop method be added to the AddOn group of methods, similar to SetTrailStop(). One line of code to save numerous lines and hours of work. This seems a reasonable request since the code already exists in the Strategy area; simply port if over to the AddOn area.

Thanks,
Ron

PS: problem resolved by not using CreateOrder() for the trailStop until Stop1 is triggered. At that point trailStop is also Submitted. See attached Strategy.
Attached Files
File Type: zip RBManageOCOorderStrategy.zip (4.9 KB, 2 views)
Last edited by ronhb107; 02-09-2018 at 11:23 AM.
ronhb107 is offline  
Reply With Quote
Old 02-09-2018, 02:49 PM   #9
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,359
Thanks: 774
Thanked 1,951 times in 1,880 posts
Default

Hello ronhb107,

Thank you for your response.

I will forward your request to our development team for possible implementation in a future release.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-13-2018, 03:41 PM   #10
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,359
Thanks: 774
Thanked 1,951 times in 1,880 posts
Default

Hello ronhb107,

Thank you for your patience.

This request has been assigned the internal tracking id of SFT-3028.

Please let me know if you have any questions.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-23-2018, 02:40 PM   #11
ronhb107
Senior Member
 
Join Date: Apr 2016
Posts: 108
Thanks: 0
Thanked 2 times in 2 posts
Default Order Rejected

This is a new problem, where an order is rejected and an OCO id is the cause.

Running Sim101, an ATM tried to place a Stop1 order but was rejected because it tried to reuse an OCO id; except, I did not use an OCO (I generally don't).

This is occurring under a Strategy which manages the manual order.

I have attached a pic of the Control Center > Log and also the Strategy.

Please let me know if you need other info.

Thanks,
Ron
Attached Images
File Type: jpg Rejected Order.jpg (839.4 KB, 3 views)
Attached Files
File Type: zip RBManageOCOorderStrategy.zip (5.9 KB, 2 views)
ronhb107 is offline  
Reply With Quote
Old 02-23-2018, 04:04 PM   #12
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,359
Thanks: 774
Thanked 1,951 times in 1,880 posts
Default

Hello ronhb107,

Thank you for your update on this matter.

I will review and follow up with you as soon as possible.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-26-2018, 10:09 AM   #13
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,359
Thanks: 774
Thanked 1,951 times in 1,880 posts
Default

Hello ronhb107,

Thank you for your patience.

I cannot reproduce the error or any behavior with the recent strategy you attached. Can you detail the steps needed to reproduce the behavior?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-26-2018, 01:26 PM   #14
ronhb107
Senior Member
 
Join Date: Apr 2016
Posts: 108
Thanks: 0
Thanked 2 times in 2 posts
Default Order Rejected

Patrick, I will try to reproduce this and get back to you if the problem persists.

My strategy code has changed since then.

Ron
ronhb107 is offline  
Reply With Quote
Reply

Tags
rejection

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Indicator / Strategy Submission GrumpyTrader Version 8 Beta 1 08-04-2015 11:42 AM
Rejected order when Stop & Target submission uses ByStrategyPosition pstrusi Platform Technical Support 2 12-17-2013 08:39 AM
Submission of order woohooboy Strategy Development 1 05-09-2013 06:31 AM
Order submission poeds Platform Technical Support 2 10-11-2012 10:08 AM
entry submission outside of OnBarUpdate binwang2 General Development 1 03-06-2010 01:31 PM


All times are GMT -6. The time now is 02:59 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.