Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
SetProfitTarget() and SetStopLoss() not working
Collapse
X
-
Hello samish18,
May I confirm SetProfitTarget() and SetStopLoss() being called before the entry order method and not after?
Enable TraceOrders and print the order.ToString() in OnOrderUpdate().
This will let us know what is happening with the orders.
Below is a link to a support article on using prints and TraceOrders to understand behavior.
Save the output to a text file (right-click the output window, select Save as)
Attach the output text file to your next post.Chelsea B.NinjaTrader Customer Service
-
Attached is the output. I had to shorten it quite a bit as I am running on a 1 tick chart. The strategy entered at 3:54:40 (per the execution tab) and then went past both the take profit and stop loss in the next minute (no take profit or stop loss were evidently in place)
Comment
-
Hello samish18,
It appears this strategy is attempting to submit an order thousands of times in the span of a few seconds, but is not able due to the entries per direction and re-using signal names.
That said, it looks like the stop order is being submitted and then immediately cancelled.
orderId='131299008318' account='DEMO3680918' name='Stop loss' orderState=Submitted instrument='NQ DEC24' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=20443.5 quantity=1 tif=Gtc oco='131299008122_1' filled=0 averageFillPrice=0 onBehalfOf='' id=149 time='2024-10-10 15:54:40' gtd='2099-12-01' statementDate='1800-01-01'
orderId='131299008318' account='DEMO3680918' name='Stop loss' orderState=CancelPending instrument='NQ DEC24' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=20443.5 quantity=1 tif=Gtc oco='131299008122_1' filled=0 averageFillPrice=0 onBehalfOf='' id=149 time='2024-10-10 15:54:41' gtd='2099-12-01' statementDate='2024-10-10'
orderId='131299008318' account='DEMO3680918' name='Stop loss' orderState=CancelPending instrument='NQ DEC24' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=20443.5 quantity=1 tif=Gtc oco='131299008122_1' filled=0 averageFillPrice=0 onBehalfOf='' id=149 time='2024-10-10 15:54:41' gtd='2099-12-01' statementDate='2024-10-10'
orderId='131299008318' account='DEMO3680918' name='Stop loss' orderState=Working instrument='NQ DEC24' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=20443.5 quantity=1 tif=Gtc oco='131299008122_1' filled=0 averageFillPrice=0 onBehalfOf='' id=149 time='2024-10-10 15:54:40' gtd='2099-12-01' statementDate='1800-01-01'
orderId='131299008318' account='DEMO3680918' name='Stop loss' orderState=CancelPending instrument='NQ DEC24' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=20443.5 quantity=1 tif=Gtc oco='131299008122_1' filled=0 averageFillPrice=0 onBehalfOf='' id=149 time='2024-10-10 15:54:41' gtd='2099-12-01' statementDate='2024-10-10'
orderId='131299008318' account='DEMO3680918' name='Stop loss' orderState=CancelSubmitted instrument='NQ DEC24' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=20443.5 quantity=1 tif=Gtc oco='131299008122_1' filled=0 averageFillPrice=0 onBehalfOf='' id=149 time='2024-10-10 15:54:40' gtd='2099-12-01' statementDate='1800-01-01'
orderId='131299008318' account='DEMO3680918' name='Stop loss' orderState=Cancelled instrument='NQ DEC24' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=20443.5 quantity=1 tif=Gtc oco='131299008122_1' filled=0 averageFillPrice=0 onBehalfOf='' id=149 time='2024-10-10 15:54:40' gtd='2099-12-01' statementDate='1800-01-01'
So something in the logic is causing the entry order method to be called over and over again on each new tick and something is causing the stop order to be cancelled when submitted.
May I have an export of the script to investigate further?
To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:- Click Tools -> Export -> NinjaScript Add-on...
- Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
- Click the 'Export' button
- Enter the script name in the value for 'File name:'
- Choose a save location -> click Save
- Click OK to clear the export location message
- (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
Once exported, please attach the file as an attachment to your reply.Chelsea B.NinjaTrader Customer Service
Comment
-
-
Hello samish18,
The script appears to be attempting to cancel an order and submit a new order using the same signal name on every tick.
I suspect that attempting to cancel the order at the same time the order is filling is causing the stop and target to be cancelled.
If you remove the call to CancelOrder() can the behavior be reproduced?Chelsea B.NinjaTrader Customer Service
Comment
-
When I remove it, I eventually get the error: "Strategy submitted an order that generated the following error 'Unable to submit order'. Strategy has sent cancel requests, attempted to close the position and terminated itself" and "Order can't be submitted: order status is cancelPending."
Comment
-
Hello samish18,
To confirm, you have only removed line 62, is this correct?
Try removing the instance of the strategy from the chart in the Available list of the Strategies window, and add a new instance from the Configured area and enable this.
Does the error still occur?Chelsea B.NinjaTrader Customer Service
Comment
-
Hello samish18,
Are you able to place a manual order to the account?
This appears to be tested on a live demo, is this correct?
Can you reproduce using the Sim101 account or in Playback?
If so, may I test the script in it's current state?
Please provide an export.
To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:- Click Tools -> Export -> NinjaScript Add-on...
- Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
- Click the 'Export' button
- Enter the script name in the value for 'File name:'
- Choose a save location -> click Save
- Click OK to clear the export location message
- (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
Chelsea B.NinjaTrader Customer Service
Comment
-
Hello samish18,
To confirm, the orders are getting stuck testing the Sim101 account or on the Playback101 account?
(I suspect you may having high latency causing the orders to not be transmitted to the live demo account)
I was not able to confirm, you are able to place manual stop orders and these are becoming working without issue?
I would like to you export the NinjaScript. Tools > Export > NinjaScript.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
30 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment