if (queueShortTrade)
{
EnterShort(5, "MTF-Short");
//First Profit Target
ExitShortLimit(2, GetCurrentBid() - 80 * TickSize, "PT1", "MTF-Short");
Print(GetCurrentAsk() - 80 * TickSize);
queueShortTrade = false;
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Closing Partial Positions
Collapse
X
-
Closing Partial Positions
Hello, I'm trying to set profit targets for partial positions based on # of contracts. Below is a section of code that seems to work, but when it puts in the order(and fills just fine) it opens, then immediately closes the profit target. I can't figure out why it simply won't keep it open.
(BTW if there's a better way to set multiple profit targets, I'm totally open to that, too)Code:Tags: None
-
Hello alphatango,
When using the managed approach each quantity you want to scale in and out should be a separate entry order with a unique signal name, and the exit orders should use the from entry signals of those entries.
Below is a link to an example.
If you don't want separate entries, then use the unmanaged approach instead of the managed approach so you have full control over the order quantities.Chelsea B.NinjaTrader Customer Service
-
How do I use .cs files?
Also that would make sense. I could have the same entry signal say (pardon the syntax):
EnterLong(1, "Pos1");
EnterLong(1, "Pos2");
...
[then]
ExitLongLimit(1, [target calculation], "PT1", "Pos1")
(and so on).
Correct?
Comment
-
I will say that even splitting up the orders doesn't fix the Profit Target exit immediately canceling once the order is put in.
Comment
-
Hello alphatango,
To import a NinjaScript into NinjaTrader 8 do the following:- Download the script to your desktop, keep it in the compressed .zip file.
- From the Control Center window select Tools -> Import -> NinjaScript Addon
- Click the Desktop icon on the left to navigate to the desktop
- Select the downloaded .zip file -> then click Open
- NinjaTrader will then confirm if the import has been successful.
Below is a link to the help guide on importing NinjaScripts.
https://ninjatrader.com/support/help...-us/import.htm
Once imported, open the Strategy Builder and select ScaleOutBuilder from the Strategy drop-down.
Also, if you are using Exit methods, these need to be submitted after the entry has filled and the position has been taken. I recommend doing this from OnExecutionUpdate().
The ProfitCasestopTrailExitOrdersExample linked below has code that demonstrates submitting exit orders when the entry fills in OnExecutionUpdate().
"I will say that even splitting up the orders doesn't fix the Profit Target exit immediately canceling once the order is put in."
Enable TraceOrders to see if the order is being ignored or automatically cancelled.
Below is a link to a support article on using TraceOrders and adding debugging output to understand behavior.
It's possible that the order is not being re-submitted on each new bar and is being automatically cancelled due to the isLiveUntilCancelled overload parameter as true not being used.
The TraceOrders output will show the order automatically being cancelled.Chelsea B.NinjaTrader Customer Service
Comment
-
I don't have Import > Ninjascript. I just have Import > Ninjascript Add-On. Is that the same thing?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
50 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 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