![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Dec 2007
Posts: 310
Thanks: 0
Thanked 5 times in 3 posts
|
My strategy enters trades in the following way, enter at market using EnterLong()/EnterShort(), place my stop/targets 10 ticks above/below the entry using SetStopLoss()/SetProfitTarget(), and does a custom trail by calling SetStopLoss() again.
Most of the time this strategy works fine, but once in a while the orders will get rejected and the strategy will terminate itself saying that one of my orders is on the wrong side of the market. Here is the data for one of these errors. The should have entered at market at 83.54, stop/target +/- 10 ticks. It got filled at 83.48 and the stop should have been at 83.38, target at 83.58, trail 12 ticks Error: "Sell stop or sell Stop limit orders can't be placed above the market. affected order: Sell 1 Stop @ 83.53" Output Window: ########## New Trade (08Aug11 12:21:13) ########## --- Started BuyMarketReverse CL 09-11.122113 - BuyMarketReverse 1 @ 83.54 --- >>> OrdeUpdate: Order='1109fd872ae34055880bbe6aefeeef3b/Sim101' Name='BuyMarketReverse CL 09-11.122113' State=PendingSubmit Instrument='CL 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='1109fd872ae34055880bbe6aefeeef3b' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeUpdate: Order='1109fd872ae34055880bbe6aefeeef3b/Sim101' Name='BuyMarketReverse CL 09-11.122113' State=Accepted Instrument='CL 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='1109fd872ae34055880bbe6aefeeef3b' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeUpdate: Order='1109fd872ae34055880bbe6aefeeef3b/Sim101' Name='BuyMarketReverse CL 09-11.122113' State=Working Instrument='CL 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='1109fd872ae34055880bbe6aefeeef3b' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeUpdate: Order='1109fd872ae34055880bbe6aefeeef3b/Sim101' Name='BuyMarketReverse CL 09-11.122113' State=Filled Instrument='CL 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=1 Fill price=83.48 Token='1109fd872ae34055880bbe6aefeeef3b' Gtd='1/1/0001 12:00:00 AM' <<< Order Filled at: 83.48 >>> OrdeExecution: Execution='c6e90dae4c404858b8b527c224c4d254' Instrument='CL 09-11' Account='Sim101' Name='BuyMarketReverse CL 09-11.122113' Exchange=Default Price=83.48 Quantity=1 Market position=Long Commission=0 Order='1109fd872ae34055880bbe6aefeeef3b' Time='8/8/2011 12:21:13 PM' <<< >>> PositionUpdate <<< ### Standard Position Opened @ 83.4800 **NT** Strategy 'A0_TradeManager/f35c6b9b33db4301979131b11304ad4e' submitted an order that generated the following error 'OrderRejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself. 8/8/2011 12:21:13 PM CancelAllOrders: BarsInProgress=0 >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=PendingSubmit Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<< @@@ Long Trail to 83.36 < 83.48 8/8/2011 12:21:13 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Price Value=83.36 Currency=0 Simulated=False 8/8/2011 12:21:14 PM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=10 Currency=0 Simulated=False 8/8/2011 12:21:14 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=10 Currency=0 Simulated=False >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=Accepted Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=Working Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=PendingCancel Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=Cancelled Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<< 8/8/2011 12:21:14 PM Entered internal PlaceOrder() method at 8/8/2011 12:21:14 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Close' FromEntrySignal='' >>> OrdeUpdate: Order='bad669435d544624b562dfcc442b7392/Sim101' Name='Close' State=PendingSubmit Instrument='CL 09-11' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='bad669435d544624b562dfcc442b7392' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeUpdate: Order='bad669435d544624b562dfcc442b7392/Sim101' Name='Close' State=Accepted Instrument='CL 09-11' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='bad669435d544624b562dfcc442b7392' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeUpdate: Order='bad669435d544624b562dfcc442b7392/Sim101' Name='Close' State=Working Instrument='CL 09-11' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='bad669435d544624b562dfcc442b7392' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeUpdate: Order='bad669435d544624b562dfcc442b7392/Sim101' Name='Close' State=Filled Instrument='CL 09-11' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=1 Fill price=83.44 Token='bad669435d544624b562dfcc442b7392' Gtd='1/1/0001 12:00:00 AM' <<< >>> OrdeExecution: Execution='d19230a13f934a6a9b8cc07d981865dc' Instrument='CL 09-11' Account='Sim101' Name='Close' Exchange=Default Price=83.44 Quantity=1 Market position=Short Commission=0 Order='bad669435d544624b562dfcc442b7392' Time='8/8/2011 12:21:15 PM' <<< >>> PositionUpdate <<< ### Non-ATM Position Closed (ATM_MGR) -- CL Reset -- Non-ATM Position Closed 8/8/2011 12:21:15 PM Disable() called: strategy disabled 8/8/2011 12:21:15 PM CancelAllOrders: BarsInProgress=0 **NT** Disabling NinjaScript strategy 'A0_TradeManager/f35c6b9b33db4301979131b11304ad4e' |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hi Monpere,
This is a coding issue. You have to control submission of orders so they're placed on the right side of market. Set statements will use the last value set in code. If using SetStopLoss() and mode price, it submits exactly at the price specified. If you're seeing this after a reversal, consider setting the stop loss to mode ticks in the same block as reversal, but prior to submission of the reversal order.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Dec 2007
Posts: 310
Thanks: 0
Thanked 5 times in 3 posts
|
Quote:
|
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
That approach is fine, but you need to be sure of the last value "set" for the stop loss when submitting any entry order.
If you use mode Ticks, then stop loss is placed in relation to your entry price, and should always be on right side of market. If you use mode Price, then it submits a stop loss order exactly where you specify, and can be rejected if you specify an invalid price. The issue is control with the set statements, since they use the last value submitted. Before the submission of any entry order, you need to make sure that it's using mode Ticks for the correct initial placement.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Dec 2007
Posts: 310
Thanks: 0
Thanked 5 times in 3 posts
|
Quote:
From what I can see, in the output window the events occur in the following order 1. Long Postition is opened at 83.48 2. Error is generated Immediately, and strategy sends CanceAllOrders & terminates itself 3. My code is now trying to send profit target order 4. My code is now trying to trail the position to 83.36 with setStopLoss(). 83.36 is 12 ticks below the long position, that is the correct side of the market. Firstly, there must be some kind of timing issue or something. Why do I get an error about a "Sell Stop" order before my code even issues a SetStopLoss()/setProfitTarget()? Seconly, this issue does not happen every time, only on occasion. Thirdly my trailing stop price is on the correct side of the market. Fourthly, the error mentions 83.53, where does that come from? What am I missing?
Last edited by monpere; 08-08-2011 at 12:10 PM.
|
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Your strategy code controls the price of stop loss orders. If you send wrong values they're rejected. From the output I can see that there are two different calculation modes used in the same second, which means you're not controlling properly the price level of your Set orders. You need to simplify and debug your strategy.
This reference sample can help with the technique to monitor the actual values used for Set orders: http://www.ninjatrader.com/support/f...ead.php?t=5790 If you are unsure "the last value set" for your Set statements, then consider moving away from them and use instead ExitLongStop(), ExitShortStop() Set statements are convenient but for the most control you can use advanced handling concepts to submit equivalent orders. http://www.ninjatrader.com/support/h...n_program2.htm http://www.ninjatrader.com/support/h...r_handling.htm
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Senior Member
Join Date: Dec 2007
Posts: 310
Thanks: 0
Thanked 5 times in 3 posts
|
Quote:
Looking at the output from TraceOrders=true, which is an internal Ninja debugging mechanism, do you see any wrong price values? I also have print statements from OnPositionUpdate, do you see any wrong values in those? I don't see any wrong values, if you do, point them out, and I can see where they are coming from.
Last edited by monpere; 08-08-2011 at 01:48 PM.
|
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Unfortunately I don't have anything additional to offer on your output. I can review this further if you attach your trace / log files. Please use Help > Mail to Support feature. Send Attn: RyanM and Reference this thread.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Dec 2007
Posts: 310
Thanks: 0
Thanked 5 times in 3 posts
|
Yes sure, that is the standard NinjaTrader support brush off answer. Dude, I gave you all the internal NT debug info, and you see there is nothing wrong with the values. If I was sending wrong values to NT, would they not show up in your internal debug mechanism? I will give you my logs, and I'll never hear from you again. Forget it. I'll come up with a workaround myself, as I usually do.
|
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
More information is available in your log / trace than you posted, and we will use this to gain a more complete picture of the sequence you're asking about. Requesting additional information is not a brush -off, but part of our standard support procedure. We also always respond same day email or forum.
Ryan M
NinjaTrader Customer Service
Last edited by NinjaTrader_RyanM; 08-08-2011 at 02:19 PM.
|
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
Hi,
I am also having this problem in a strategy. When placing an order, the trailstop gets rejected. The order is placed in this way: SetTrailStop(CalculationMode.Ticks,StopLossDistanc e); Which produces logging like this: 10/11/2011 4:06:00 PM Calling dolong() from a simple trade entry of Signal=+1 10/11/2011 4:06:00 PM DoLong(), enter at limit=False Reversing 10/11/2011 4:06:00 PM Entered internal PlaceOrder() method at 10/11/2011 4:06:00 PM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='' 10/11/2011 4:06:00 PM .. forced Flattening of current position from any opposite signal 10/11/2011 4:06:00 PM Entered internal PlaceOrder() method at 10/11/2011 4:06:00 PM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='' 10/11/2011 4:06:00 PM Ignore order amendment: Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName=Buy to cover' FromEntrySignal='' Reason='Order already has this stop price/limit price/quantity' DelayedEntryInfo 1, 0 10/11/2011 4:06:00 PM Cancelled pending exit order, since associated position is closed: Order='NT-00395/Sim101' Name='Profit target' State=Working Instrument='ES 12-11' Action=BuyToCover Limit price=1142 Stop price=0 Quantity=1 Strategy='AMSuiteTrader4' Type=Limit Tif=Gtc Oco='NT-00216-1394' Filled=0 Fill price=0 Token='e8236a7fde7d44daafd4a5ad4ab4845f' Gtd='1/12/2099 12:00:00 AM' 10/11/2011 4:06:00 PM Cancelled pending exit order, since associated position is closed: Order='NT-00394/Sim101' Name='Stop loss' State=Working Instrument='ES 12-11' Action=BuyToCover Limit price=0 Stop price=1248.75 Quantity=1 Strategy='AMSuiteTrader4' Type=Stop Tif=Gtc Oco='NT-00216-1394' Filled=0 Fill price=0 Token='3201377710aa445eb9f29c3df7b9613e' Gtd='1/12/2099 12:00:00 AM' 10/11/2011 4:06:00 PM (10/11/2011 4:05:57 PM) DoLimitEntry() with data 1, 0 AT MARKET 10/11/2011 4:06:00 PM Entered internal PlaceOrder() method at 10/11/2011 4:06:00 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='MACDZeroCross_Long' FromEntrySignal='' 10/11/2011 4:06:00 PM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=385 Currency=0 Simulated=False 10/11/2011 4:05:57 PM Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='' Mode=Ticks Value=20 Currency=0 Simulated=False **NT** Strategy 'AMSuiteTrader4/00890ac470554df59a2449d3d90586d1' submitted an order that generated the following error 'OrderRejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself. 10/11/2011 4:05:57 PM CancelAllOrders: BarsInProgress=0 10/11/2011 4:05:58 PM Entered internal PlaceOrder() method at 10/11/2011 4:05:58 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Close' FromEntrySignal='' 10/11/2011 4:05:59 PM Disable() called: strategy disabled **NT** Disabling NinjaScript strategy 'AMSuiteTrader4/00890ac470554df59a2449d3d90586d1' This makes no sense as Ninja is supposed to correctly place a TrailStop. I even have gone to the trouble of getting flat before I enter the next position, instead of instantly reversing. No change in the problem. Please help. I can send you the trace file from the above incident if you like. Cheers, saltminer |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hi saltminer,
Sure, please send trace and log files to my attention to support 'at' ninjatrader 'dot' com.
Ryan M
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IB Server side OCO with parent order? | tobbe | SuperDOM and other Order Entry Windows | 3 | 01-06-2012 02:02 AM |
| Unrealized profit display wrong in market analyzer, entry wrong in chart trader | adamus | Market Analyzer | 3 | 06-17-2011 10:56 AM |
| error on picture's right side scale | MoreYummy | Miscellaneous Support | 2 | 04-09-2010 09:54 AM |
| Error Sending Stop/Market order via Pats | dct | Connecting | 11 | 10-28-2009 08:19 AM |
| Short Simulated Order Fills on Wrong Side Of Book | Generic | Miscellaneous Support | 1 | 10-05-2008 04:27 PM |