It is likely an expiration issue. Orders need to be resubmitted on every single OnBarUpdate() event or else it will auto cancel. I suggest you use TraceOrders to see.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
High/Low between times
Collapse
X
-
In keeping the order alive, it will never cancel until you explicitly cancel it, the GTC on it runs out, or it gets filled. All other situations you need to manually call CancelOrder().
It is likely an expiration issue. Orders need to be resubmitted on every single OnBarUpdate() event or else it will auto cancel. I suggest you use TraceOrders to see.Josh P.NinjaTrader Customer Service
-
I have singled out this section of code and added a print statement and it looks like this part is the part calling the price from the prior long trade. Any ideas?
What I am attempting to do is capture the highest low since a new long entry (called LongEntry) has been established and use this low price minus the 20 pips as a trail stop.Code:(MAX(Low,BarsSinceEntry("LongEntry"))[0]) - .0020;
Comment
-
I am trying to modify the stop once a certain profit amount has been attained. I have the initial stop order in the onExecution section of code that will remain working until a certain profit amount is reached. The onBarUpdate section checks to see if this criteria is met and if so places the stop order below the highest low since entry minus 20 pips. As the highest low moves up the stop order will need to be modified. For some reason the snippet of code on my last post is not updating with the current trade but using the last held stop price from the prior trade. Thoughts on how to fix? Thanks!
GT
Comment
-
Me again. Sorry but this is just not working for me. Additional code posted below. Very frustrating for a novice.
I followed the SampleOnOrderUpdate code as a template. This code enters two separate long positions with two separate names. With the code the way it is if I enter a trade on the first new bar it exits due to an error with the TrLongE position due to an "invalid order price, see log tab." Looking at the output window it shows that the variable LT is holding the value from the prior long position. Everything looks fine on historical data but when running live it does not work. What do I need to change to have the variable LT hold the value for the current position? Also, I just noticed an error message "exceeded entry signals limit based on entryhandling and entriesperdirection properties." Any insight into this one? Thank you for your patience!Code:protected override void Initialize() { CalculateOnBarClose = true; EntriesPerDirection = 1; EntryHandling = EntryHandling.UniqueEntries; ExitOnClose = false; TraceOrders = true; } private DateTime startDateTime; private DateTime endDateTime; protected override void OnBarUpdate() { if (Time[0].DayOfWeek == DayOfWeek.Saturday) return; if (Time[0].DayOfWeek == DayOfWeek.Sunday) return; // Check to make sure the end time is not earlier than the start time if (EndHour < StartHour) return; //Do not calculate the high or low value when the ending time of the desired range is less than the current time of the bar being processed if (ToTime(EndHour, EndMinute, 0) > ToTime(Time[0])) return; // If the stored date time date is not the same date as the bar time date, create a new DateTime object if (startDateTime.Date != Time[0].Date) { startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, StartHour, StartMinute, 0); endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, EndHour, EndMinute, 0); } // Calculate the number of bars ago for the start and end bars of the specified time range int StartBarsAgo = GetBar(startDateTime); int EndBarsAgo = GetBar(endDateTime); // Now that we have the start end end bars ago values for the specified time range we can calculate the highest high for this range double HighestHigh = MAX(High, StartBarsAgo - EndBarsAgo)[EndBarsAgo]; // Now that we have the start end end bars ago values for the specified time range we can calculate the lowest low for this range double LowestLow = MIN(Low, StartBarsAgo - EndBarsAgo)[EndBarsAgo]; double LongEntryLevel = HighestHigh + EntryPips; double ShortEntryLevel = LowestLow - EntryPips; double LongTrail = LongEntryLevel - .0040; double ShortTrail = ShortEntryLevel + .0040; double LT = LongEntryLevel - .0040; double ST = ShortEntryLevel + .0040; //LONG ENTRY AND STOPS //Entry code omitted if((Position.MarketPosition==MarketPosition.Long) && (MAX(High,(Math.Max(0,BarsSinceEntry("TrLongE"))))[0] < (Position.AvgPrice + .0040))) { LT = LongEntryLevel - .0040; } else if((Position.MarketPosition==MarketPosition.Long) && (MAX(High,(Math.Max(0,BarsSinceEntry("TrLongE"))))[0] >= (Position.AvgPrice + .0040))) { LT = (MAX(Low,Math.Max(0,BarsSinceEntry("TrLongE")))[0]) - EntryPips; Print(" LT: " + LT + " HighestHigh: " + HighestHigh + " LowestLow: " + LowestLow + " EntryPips: " + EntryPips); stopOrder = ExitLongStop(0, true,5,LT, "LT", "TrLongE"); } protected override void OnOrderUpdate(IOrder order) { // Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order. if (entryOrder != null && entryOrder.Token == order.Token) { // Reset the entryOrder object to null if order was cancelled without any fill if (order.OrderState == OrderState.Cancelled && order.Filled == 0) { entryOrder = null; } } } protected override void OnExecution(IExecution execution) { if (entryOrder != null && entryOrder.Token == execution.Order.Token) { if (execution.Order.OrderState == OrderState.Filled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { // Check to make sure the end time is not earlier than the start time if (EndHour < StartHour) return; //Do not calculate the high or low value when the ending time of the desired range is less than the current time of the bar being processed if (ToTime(EndHour, EndMinute, 0) > ToTime(Time[0])) return; // If the stored date time date is not the same date as the bar time date, create a new DateTime object if (startDateTime.Date != Time[0].Date) { startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, StartHour, StartMinute, 0); endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, EndHour, EndMinute, 0); } // Calculate the number of bars ago for the start and end bars of the specified time range int startBarsAgo = GetBar(startDateTime); int endBarsAgo = GetBar(endDateTime); // Now that we have the start end end bars ago values for the specified time range we can calculate the highest high for this range double HighestHigh = MAX(High, startBarsAgo - endBarsAgo)[endBarsAgo]; // Now that we have the start end end bars ago values for the specified time range we can calculate the lowest low for this range double LowestLow = MIN(Low, startBarsAgo - endBarsAgo)[endBarsAgo]; if(Position.MarketPosition==MarketPosition.Long) targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + .0040, "StatLongTarget", "StaticLongE") ; if(Position.MarketPosition==MarketPosition.Long) { stopOrder = ExitLongStop(0, true, execution.Order.Filled, HighestHigh - .0040, "StatLongStop", "StaticLongE"); stopOrder = ExitLongStop(0, true, execution.Order.Filled, HighestHigh - .0040, "TrLongStop", "TrLongE"); } if ((stopOrder != null && stopOrder.Token == execution.Order.Token) || (targetOrder != null && targetOrder.Token == execution.Order.Token)) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled) { stopOrder = null; targetOrder = null; } } }
GT
Comment
-
GreenTrade,
We just don't have the bandwidth to thoroughly dissect everyone's code. From a brief glance through, your LT variable is updated in OnBarUpdate(). You will want to debug this and see when it is updating. If it is storing a value from the prior run it is likely because you have not made an update call to the LT value before submitting your order.
In terms of "exceeded entry signals", this occurs when you submit orders while already holding a position. Depending on your EntriesPerDirection and EntryHandling settings you set before you run the strategy, you can only have 1 position open at a time.Josh P.NinjaTrader Customer Service
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
571 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment