Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
All of a sudden all trades are exiting at bar close
Collapse
X
-
Hello joemiller,
The orders are being closed when the bar closes due to the LiveUntilCancelled bool being false (by default) in the order command.
For example, to place an order that will not close at the end of the bar:
EnterLongLimit(0, true, 1, Low[0], "long1");
EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice,string signalName)
Below is a link to the help guide on EnterLongLimit.
The TimeInForce which is either day or gtc will be how the broker handles the order on if it will exit at the end of the day. LiveUntilCancelled, however, is an internal NinjaScript Strategy option that will cancel the order if it has not been filled when the current bar closes.
Please do not hesitate to contact us for any other NinjaTrader inquiries you may have.Chelsea B.NinjaTrader Customer Service
-
Thanks a lot Chelsea.
The following is the logic that all of a sudden gave different results so I obviously did something... unknown to me but no matter, I will apply your suggestion and move on.
if(Open[0]>redline) //go long
EnterLong();
elseif(Open[0]<redline) //go short
EnterShort();
Comment
-
I would like to simply continue doing it as I was doing it
If possible I would like to simply continue doing it as I was doing it [ie] exit and reverse at a non-limit price. It was working, so does anyone have any idea what might have been changed or been lost ... such as an initialize setting etc.
In the meantime I will play with the limit order by maybe setting the limit price large enough or small enough that the order will go off like a market order... maybe something like that will work but that is a lot of hassle. However the original is so clean and simple and non-Mickey Mouse that I sure would like to get it working again. I will continue to work on it. Once again, the original 4 lines of code was:
if(Open[0]>redline) //go long
EnterLong();
elseif(Open[0]<redline) //go short
EnterShort();
Comment
-
I have discovered that in general just plain EnterLong and EnterShort works as expected [ie] opposite positions are closed and a reverse position is entered ..... EXCEPT when the bar time is 1/2 day [ie] 12 hours or 720 minutes.Originally posted by joemiller View PostIf possible I would like to simply continue doing it as I was doing it [ie] exit and reverse at a non-limit price. It was working, so does anyone have any idea what might have been changed or been lost ... such as an initialize setting etc.
In the meantime I will play with the limit order by maybe setting the limit price large enough or small enough that the order will go off like a market order... maybe something like that will work but that is a lot of hassle. However the original is so clean and simple and non-Mickey Mouse that I sure would like to get it working again. I will continue to work on it. Once again, the original 4 lines of code was:
if(Open[0]>redline) //go long
EnterLong();
elseif(Open[0]<redline) //go short
EnterShort();
Comment
-
Hi joemiller,
A market order such as EnterLong or EnterShort will always fill on the same bar. Market orders are designed to fill immediately if there is someone opposite the trade.
A limit order such as EnterLongLimit, however, will only fill if the bid or ask price rests at the limit price.
A limit that is not filled within the same bar will be cancelled unless its placed with LiveUntilCancelled as true in the call to the EnterLongLimit.
Using the managed approach to change the position should always exit the previous position to go to flat and then submit new orders to put you in the new position.
If this is not happening I will need to look through your log and trace to determine the cause.
Please let me know if this is the case and I will give you further instructions to send in this information.Chelsea B.NinjaTrader Customer Service
Comment
-
Thanks for the help Chelsea.
I'm starting to suspect that order management is more complex than at first anticipated therefore I have made up the following scenario for practice:
if a bar open is gt an indicator go flat and reverse position and just the opposite in the other direction. So I will start with the following logic [unless a suggestion is made to do otherwise].
if(Open[0]>redline) //exit the short position and go long
{
ExitShort();
EnterLong();
}
else if(Open[0]<redline) //exit the long position and go short
{
ExitLong();
EnterShort();
}
Comment
-
Hi joemiller,
The exits should not be necessary.
When you are short and the EnterLong is called, is the short position not exited first?
If so, there is something going very wrong and I would like to look through your log and trace files as well as test this script myself.
Please let me know if this is the case.Chelsea B.NinjaTrader Customer Service
Comment
-
Chelsea,
I misunderstood part of your previous reply [ie] "Using the managed approach to change the position should always exit the previous position to go to flat and then submit new orders to put you in the new position". I think it was working ok the way you describe [ie] the explicit exit is not necessary. I will play around some more and then get back to you.
Joe Miller
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
637 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
366 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
569 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
572 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment