Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Issues with limit orders...
Collapse
X
-
For sure you will keep resubmitting. Your reset flag condition is when you are flat. That is not a good stand alone condition. It can take many bars for your limit orders to fill and the whole time they are working, you are flat. You should not reset your orders till after your entries fill/cancel/etc.Josh P.NinjaTrader Customer Service
-
still having problems... here is the code I am using to test my logic... I'm not able to seem to have orders submitted unless I set the number of bars to cancel on to be some large number say 20.... please help...
the reason I put in a Cancel Orders section in the OnBarUpdate() and in OnOrderUpdate() was because I could not seem to get it the model to NOT keep resubmitting prices constantly, but by doing this... I could.... I'm making some progress, but yet quite confused and would really appreciate the helpCode:{ #region Variables // Wizard generated variables private int period = 1; // Default setting for Length private IOrder myEntryOrder = null; private int barNumberofOrder = 0; // User defined variables (add any user defined variables below) #endregion protected override void Initialize() { CalculateOnBarClose = false; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // GET INDICATOR VALUES TO ENTER BUY MODE OR SELL MODE // SELL MODE if (High[0] < EMA(Period)[0] && myEntryOrder == null) { myEntryOrder = EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 4 * TickSize, "Short"); barNumberofOrder = CurrentBar; } // BUY MODE if (Low[0] > EMA(Period)[0] && myEntryOrder == null) { myEntryOrder = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() + -4 * TickSize, "Long"); barNumberofOrder = CurrentBar; } // CANCEL ORDERS if (CurrentBar > barNumberofOrder + 5) { CancelOrder(myEntryOrder); myEntryOrder = null; } } // WORK ORDERS, CANCEL ORDERS, STOP LOSS, PROFIT TARGETS protected override void OnOrderUpdate(IOrder order) { if (myEntryOrder != null && myEntryOrder.Token == order.Token) { Print(order.ToString()); if (order.OrderState == OrderState.Working && CurrentBar > barNumberofOrder + 5) { myEntryOrder = null; CancelOrder(myEntryOrder); } if (order.OrderState == OrderState.Filled) { SetStopLoss("Long", CalculationMode.Ticks, 8, false); SetStopLoss("Short", CalculationMode.Ticks, 8, false); SetProfitTarget("Long", CalculationMode.Ticks, 8); SetProfitTarget("Short", CalculationMode.Ticks, 8); myEntryOrder = null; } } } #region Properties [Description("")] [Category("Parameters")] public int Period { get { return period; } set { period = Math.Max(1, value); } } #endregionLast edited by BigDog008; 06-08-2009, 12:46 AM.
Comment
-
BigDog008,
I am not quite sure what you mean by resubmitting prices constantly. Your entry orders will go in when the IOrder is null. Once it is accepted it will not be possible to resubmit until the IOrder is reset back to null. Not sure how you have concluded you cannot cancel in less bars. I suggest you add Print() in your code and try to follow it each step of the way and see what it is evaluating your conditions as.Josh P.NinjaTrader Customer Service
Comment
-
Josh, sorry about the incoherent post... was up late at night when I started typing :P
what i ment by constantly resubmitting is that say an order is working, and then filled with its appropriate stop and target in place... once either the stop or target is hit, and the proper condition is met, it should submit a new order, which it doesn't seem to do....
i've attached the code to show what I mean... I think that would explain better what I'm trying to do or the issues i'm having... i'm trying to run it on 6Range bar on say the ES contract... as far as cancelling orders... you'll notice when you run if you want to cancel orders in say 3 bars vs 5... it doesn't seem to do it, which I find confusing because the logic seems sound...Attached Files
Comment
-
BigDog008,
If you want it to submit a new order after you have closed your current trade you will want to reset your IOrder after the trade has closed.
You will need to debug why your cancels aren't working. Please use TraceOrders = true and add Print()s to see what is happening.Josh P.NinjaTrader Customer Service
Comment
-
that's what I was doing in the OnOrderUpdate section...Originally posted by NinjaTrader_Josh View PostBigDog008,
If you want it to submit a new order after you have closed your current trade you will want to reset your IOrder after the trade has closed.
You will need to debug why your cancels aren't working. Please use TraceOrders = true and add Print()s to see what is happening.
once an order is considered working... i reset it to null... also once its filled i set it to null.... do i have to do this when the targets or losses are hit too?
Comment
-
What I was suggesting was for you not to reset at that point but rather only reset after the trade completes; as in gets in and out. When you reset it at the point where you place stop/targets you are opening up your strategy for further trades at that point in time (provided EntriesPerDirection allows you to). Not sure if that is what you intend or not. Your call.Josh P.NinjaTrader Customer Service
Comment
-
Josh,
Rather than using the CancelOrder function based on number of bars passed, is it possible to use it based on number ticks the current price has deviated from the limit order?
also do I need to handle CANCEL ORDERS in the OnBarUpdate() section, or can I use that to simply enter BUY MODE and SELL MODE, and then manage the working and filled orders stictly from OnOrderUpdate()
Comment
-
You can use whatever you want. Just program an if-statement that checks price versus your limit price and then call CancelOrder when you see fit.
Not following what you mean by BUY MODE and SELL MODE. CancelOrder() cancels the order you tell it to cancel. It doesn't do anything else. You can call it from where ever you want.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
683 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
386 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
111 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
584 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
585 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment