Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to Prevent Closing a Position before Stop/Target Reached
Collapse
X
-
What you have written will do what you want. There have been many arguments and much caviling on these fora about the fact that in the presence of protective orders, the Managed approach for orders will not reverse a trade on the same bar if CalculateOnBarClose is true, or indeed at all, if there is no cancellation of said orders.Originally posted by NewEngTrader View PostHello,
I have created a strategy that has a condition to go long or go short based on simple criteria and the long/short criteria are the inverse of each other. It is based on an SMA crossover strategy. I am using an EnterLong() and EnterShort() order for each condition and I have declared a SetStopLoss and SetProfitTarget value declared for each condition.
If I am in a long position, I want to ensure that the position will not close until the target or stop value is reached, even if a short signal appears. In addition, if there is a short signal and I am currently in a long position, I also do not want NT to place another order to go short until the long has reached the target or stop (meaning I only want 1 futures contact to be bought a one time).
Based on the current code (below), it seems that if I am in a long position and a short signal appears, it will close my position out and reverse. I am trying to figure out what rule I am missing to prevent the long form being closed or an additional order from being placed.
Thanks for any information you can provide,
-Dave
protected override void Initialize()
{
EntriesPerDirection = 1;
EntryHandling = EntryHandling.UniqueEntries;
CalculateOnBarClose = false;
}
protected override void OnBarUpdate()
{
if (long criteria)
{
EnterLong(1, "long");
SetStopLoss(CalculationMode. ...);
SetProfitTarget(CalculationMode ...);
}
// Condition set 2
if (short criteria)
{
EnterShort(DefaultQuantity, "Short");
SetStopLoss(CalculationMode ...);
SetProfitTarget(CalculationMode ...);
}
Leave a comment:
-
Hello NewEngTrader,
Thank you for your post and welcome to the NinjaTrader Support Forum!
Add Position.MarketPosition == MarketPosition.Flat to the conditions:
For information on Position please visit the following link: http://www.ninjatrader.com/support/h...7/position.htmCode:if (long criteria && Position.MarketPosition == MarketPosition.Flat) { EnterLong(1, "long"); SetStopLoss(CalculationMode. ...); SetProfitTarget(CalculationMode ...); } // Condition set 2 if (short criteria && Position.MarketPosition == MarketPosition.Flat) { EnterShort(DefaultQuantity, "Short"); SetStopLoss(CalculationMode ...); SetProfitTarget(CalculationMode ...); }
Please let me know if I may be of further assistance.
Leave a comment:
-
How to Prevent Closing a Position before Stop/Target Reached
Hello,
I have created a strategy that has a condition to go long or go short based on simple criteria and the long/short criteria are the inverse of each other. It is based on an SMA crossover strategy. I am using an EnterLong() and EnterShort() order for each condition and I have declared a SetStopLoss and SetProfitTarget value declared for each condition.
If I am in a long position, I want to ensure that the position will not close until the target or stop value is reached, even if a short signal appears. In addition, if there is a short signal and I am currently in a long position, I also do not want NT to place another order to go short until the long has reached the target or stop (meaning I only want 1 futures contact to be bought a one time).
Based on the current code (below), it seems that if I am in a long position and a short signal appears, it will close my position out and reverse. I am trying to figure out what rule I am missing to prevent the long form being closed or an additional order from being placed.
Thanks for any information you can provide,
-Dave
protected override void Initialize()
{
EntriesPerDirection = 1;
EntryHandling = EntryHandling.UniqueEntries;
CalculateOnBarClose = false;
}
protected override void OnBarUpdate()
{
if (long criteria)
{
EnterLong(1, "long");
SetStopLoss(CalculationMode. ...);
SetProfitTarget(CalculationMode ...);
}
// Condition set 2
if (short criteria)
{
EnterShort(DefaultQuantity, "Short");
SetStopLoss(CalculationMode ...);
SetProfitTarget(CalculationMode ...);
}
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CaptainJack, 05-29-2026, 05:09 AM
|
0 responses
227 views
0 likes
|
Last Post
by CaptainJack
05-29-2026, 05:09 AM
|
||
|
Started by CaptainJack, 05-29-2026, 12:02 AM
|
0 responses
146 views
0 likes
|
Last Post
by CaptainJack
05-29-2026, 12:02 AM
|
||
|
Started by charlesugo_1, 05-26-2026, 05:03 PM
|
0 responses
160 views
1 like
|
Last Post
by charlesugo_1
05-26-2026, 05:03 PM
|
||
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
238 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
197 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|

Leave a comment: