PDA

View Full Version : Pending cancels


Burga1
11-29-2007, 05:22 PM
Greetings,

I wish to have a strategy enter a "long" trade by:

--Possibly entering the position IF proper conditions exist on the CURRENT bar
--If conditions on the CURRENT bar are met, place a "buy" limit order 2 pips above the HIGH of the CURRENT bar for entry on the NEXT bar...

When conditions seem to be in place for a possible trade entry a "pending" order is established, my issue is that (I believe) when the CURRENT bar is completed the strategy immediately cancels the order if the NEXT bar is not 2 pips above the high...my code for orders is as follows:

EnterPlace = (High[0] + 2) * TickSize; //entry 2 pips above high
EnterLongLimit(1, EnterPlace, "Condition 1 Entry");
ExitPlace = (Low[0] - 1) * TickSize; //stop 1 pip below low
SetStopLoss("EnterLongLimit", CalculationMode.Ticks, ExitPlace, true);

Do I possibly need to cancel the "Calculate upon bar close" or is it some other issue? Thanks in advance.

NinjaTrader_Josh
11-30-2007, 12:52 AM
You need to keep resubmitting the order on every bar or else the order will be cancelled if it was not filled. If you wish it to persist there is a feature in NT6.5 that allows you to set a liveUntilCancelled bool to true.

Burga1
11-30-2007, 09:02 AM
Thanks. So are you saying there is no way for me to instruct to place the order on the NEXT bar (the bar after the current bar when trade entry conditions became true) at 2 pips above the high and ONLY for that next bar?

NinjaTrader_Ray
11-30-2007, 09:04 AM
- When you are running a strategy on the close of a bar basis, orders are always submitted on the the next bar
- You can never place an order using the high/low of the next bar since this information is not know
- You can place an order using the high/low of the closes bar (CurrentBar)

Burga1
11-30-2007, 09:28 AM
Thank you. "You can place an order using the high/low of the closes bar (CurrentBar)" -- that is what I wish to do. When I run my strategy using a "real-time" feed I'm noticing that the trade entry positions do not seem to be made at the correct levels (2 pips above HIGHS/2 pips below LOWS)...I'm trying to correct that.

NinjaTrader_Ray
11-30-2007, 09:48 AM
I see.

You will then have to debug this in your code. I see in your 1st post you have an incorrect calculation. To get the high + 2 pips you will need to:

High[0] + (2 * TickSize);

If you are on Beta 6.5 and working in sub-pips, then it would be (20 * TickSize)

Burga1
11-30-2007, 10:09 AM
Thank you, I'll correct that...I guess that would kinda make a difference :)

Burga1
11-30-2007, 12:34 PM
Greetings,

Well I have what seems to be the proper entry behavior coded, however this leads to another question. Using the screenshot I've attached it can be seen that the little markers do in fact appear 2 pips above/below the highs/lows of the bar the trade condition became true...

My question is why these postions appear to remain "open" even after the bar following has passed (I only want a possible trade to trigger on the bar after the bar a trade condition became true--not on following bars). Thus if the trade is not executed on the following bar it should cancel...thank you.

NinjaTrader_Ray
11-30-2007, 01:12 PM
Do not submit the order again on the following bar to cancel it. Executions are plotted based on time and it is possible:

- Condition true on Bar 1
- Order is filled a split second before Bar 2 is closed
- Execution time stamp falls on Bar 3

Burga1
11-30-2007, 02:16 PM
Thanks but if you look at my screenshot, orders are being taken up several bars after the "condition true" bar...each bar is 5 minutes. It is not a matter of seconds...the entry is clearly remaining "live" for following bars to take up for quite some time...the price level on the "bar 2" (the bar the trade should be executed, if at all) never comes close to those entry points...

NinjaTrader_Ray
11-30-2007, 02:27 PM
Then this is because your order remains live since you keep re-submitting it.

If every close of the bar looks like this:

OnBarUpdate()
{
EnterLongLimit(Low[0]);
}

You will have a working limit order on every bar until this order fills.

Burga1
11-30-2007, 02:36 PM
OK, thank you I understand. What is the command used to cancel the order after the following bar ("bar 2") has completed and the order was not taken up?

NinjaTrader_Ray
11-30-2007, 02:44 PM
Please review this section of our Help Guide -

http://www.ninjatrader-support.com/HelpGuideV6/Overview36.html

Specifically this sub section "Order Submission for Entry and Exit Methods"

Burga1
11-30-2007, 02:59 PM
Thanks for the link, that should clear things up a bit...but I do have another related issue to this.

If you look at this screenshot it's clear that the 3 "short" positions do not have the little entry markers placed 2 pips below the low of the previous bar (the bar the trade condition became true). I do not know why this is the case, there are also no "profit/loss" lines connecting those points to other points...I thought perhaps that indicated a "canceled" trade however on 2 of those bars the price did in fact reach a level 2 pips below the low of the previous bar, so I don't know what to make of it...

NinjaTrader_Ray
11-30-2007, 03:02 PM
Those are executions plotted on your chart that may or may not have been generated by your strategy.

If you simply place an order anywhere in NinjaTrader, executions are optionally plotted on a chart.

You will only see strategy related trades (with connector lines) when a strategy is running.

Burga1
11-30-2007, 06:48 PM
Thanks. They must have been strategy-generated, I do not manually enter trades. Could they have been plotted as "historical" trades since I don't believe the strategy was running at those times?...

Why would the entry markers not be in the "correct" locations (2 pips below the low of "condition true" bar)?

KBJ
12-01-2007, 12:30 AM
Why would the entry markers not be in the "correct" locations (2 pips below the low of "condition true" bar)?

Have you tried setting slippage = 0 ?

NinjaTrader_Josh
12-01-2007, 01:40 AM
From the screenshot it looks like you don't have a strategy running. They look like trades you have executed before. If you can post your latest rendition of code we may be able to get some hints to why the trades are being filled at the prices presented in the picture. It looks relative to the close price offset a few ticks rather than low price to me from the pic.

Burga1
12-01-2007, 11:55 AM
Thank you. KBJ I set the slippage to "0" in the properties window when I start the strategy.

Here's the code from the strategy for "Condition 3" (the condition that triggered those trades as can be seen in the screenshot)...

// Condition set 3
if (High[0] > High[1]
&& Close[0] < Close[1]
&& Low[0] >= Low[1]
&& SMIndex(2, 13, 3, 25).SMI[0] < SMIndex(2, 13, 3, 25).SMI[1])
{
EnterPlace = Low[0] - (2 * TickSize);
EnterShortLimit(1, EnterPlace, "Condition 3 Entry");
ExitPlace = High[0] + (1 * TickSize);
SetProfitTarget(CalculationMode.Ticks, 4);
SetStopLoss("EnterShortLimit", CalculationMode.Ticks, ExitPlace, true);
}

Thanks again.

NinjaTrader_Josh
12-01-2007, 01:20 PM
Your SetStopLoss() condition is most likely not working as you intended. Right now you have it set to stop you out if the price drops (High + 1 Tick Size) in ticks.

If you want to stop out at that specific price you want to use CalculationMode.Price not CalculationMode.Ticks

Also, please use some print commands to output the EnterPlace and ExitPlace variables. This will help you debug where your order was intended to fill at.

Burga1
12-02-2007, 07:04 PM
Thanks for the input Josh. I have a question regarding "cancels" of an order if not taken up...if my code reads:

if(some condition is true)
{
EnterPlace = High[0] + (2 * TickSize);
EnterLongLimit(1, EnterPlace, "Condition 1 Entry");
ExitPlace = Low[0] - (1 * TickSize);
SetProfitTarget(CalculationMode.Ticks, 4);
SetStopLoss("Condition 1 Entry", CalculationMode.Price, ExitPlace, true);
ExitLongLimit(1, "Condition 1 Entry");
}

Should the "ExitLongLimit" command be placed after the "EnterLongLimit" command OR before? I would think it should be placed before so that a placed order doesn't immediately cancel itself...I only want to cancel an order that was never taken up...

Is there a system variable that is set when an order has been placed? In that case the code could read something like "If(order placed variable is false){then ExitLongLimit;}"

NinjaTrader_Josh
12-02-2007, 07:06 PM
Sorry I don't follow. If your entry order was never filled you don't need to Exit it. There is no position to exit.

Burga1
12-02-2007, 07:48 PM
Hi,

I'm trying to follow-up on comments from earlier in this post (from post on 11/30 2:34pm). Since my order logic is in the "OnBarUpdate" function this causes the logic to leave the order "open" so that it is being filled on later bars (when I don't want it to do so...)

NinjaTrader_Josh
12-02-2007, 07:52 PM
If you do not resend your order it will automatically expire in the case of it not being filled. This is by design. The only possibility as to orders remaining active after the original entry condition is if that exact entry condition reevaluated to be true again.

Burga1
12-02-2007, 07:56 PM
If that is true then those orders within my screenshot in that post could not have possibly executed, but they did as you can see...

NinjaTrader_Josh
12-02-2007, 08:12 PM
Burga1. Your conditions ARE evaluating to true on multiple subsequent bars. This is why your orders are staying alive. If you do not believe me put print functions as recommended in this debugging tip (http://www.ninjatrader-support.com/vb/showthread.php?t=3418). Place the print inside your if condition to print every time it is evaluated to true. Use it along with TraceOrders (http://www.ninjatrader-support.com/vb/showthread.php?t=3627) and you will see exactly how your orders are working.

Further more you can play with the attached reference strategy. Watch how they behave in the output window. The strategy will print every bar number. If the condition evaluated to true on that bar it will print another line. From the output you can discern that orders that are resubmitted are kept alive. Once an order is not resubmitted you will see the order is effectively timed out.

CurrentBar: 14
CurrentBar: 15
CurrentBar: 16
CurrentBar: 17
12/2/2007 7:06:48 PM Condition Evaluated True on Bar 17 <-- true so order submitted but never filled
12/2/2007 7:06:49 PM Entered internal PlaceOrder() method at 12/2/2007 7:06:49 PM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=133.85 StopPrice=0 SignalName='longlimit' FromEntrySignal=''
CurrentBar: 18
12/2/2007 7:06:51 PM Condition Evaluated True on Bar 18 <-- true so order resubmitted and kept alive
12/2/2007 7:06:52 PM Entered internal PlaceOrder() method at 12/2/2007 7:06:52 PM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=133.86 StopPrice=0 SignalName='longlimit' FromEntrySignal=''
12/2/2007 7:06:52 PM Amended matching order: Action=Buy OrderType=Limit Quantity=1 LimitPrice=133.86 StopPrice=0 SignalName=longlimit' FromEntrySignal=''
CurrentBar: 19
12/2/2007 7:06:54 PM Condition Evaluated True on Bar 19 <-- true so order resubmitted and kept alive
12/2/2007 7:06:55 PM Entered internal PlaceOrder() method at 12/2/2007 7:06:55 PM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=133.88 StopPrice=0 SignalName='longlimit' FromEntrySignal=''
12/2/2007 7:06:55 PM Amended matching order: Action=Buy OrderType=Limit Quantity=1 LimitPrice=133.88 StopPrice=0 SignalName=longlimit' FromEntrySignal=''
CurrentBar: 20
12/2/2007 7:06:57 PM Condition Evaluated True on Bar 20 <-- true so order resubmitted and kept alive
12/2/2007 7:06:58 PM Entered internal PlaceOrder() method at 12/2/2007 7:06:58 PM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=133.89 StopPrice=0 SignalName='longlimit' FromEntrySignal=''
12/2/2007 7:06:58 PM Amended matching order: Action=Buy OrderType=Limit Quantity=1 LimitPrice=133.89 StopPrice=0 SignalName=longlimit' FromEntrySignal=''
CurrentBar: 21 <-- NOT TRUE so order NOT resubmitted. order cancelled
12/2/2007 7:07:01 PM Cancelled expired order: BarsInProgress=0: Order='3ca0d030afc847519fde42c0b1c0e62b/Sim101' Name='longlimit' State=Working Instrument='AAPL' Action=Buy Limit price=133.89 Stop price=0 Quantity=1 Strategy='orderautocancel' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='3ca0d030afc847519fde42c0b1c0e62b' Gtd='12/1/2099 12:00:00 AM'

Burga1
12-02-2007, 08:26 PM
Yes, I understand that the orders are "staying alive" because subsequent bars evaluate to true...that's not the problem. My question is why the "original" entry point (the "first true evaluation" bar) remains used for the subsequent bars...if subsequent bars evaluate to true then the entry point should "shift" on each subsequent bar (in my case 2 pips above/below the high/low of the bar).

For example if "bar 1" evaluates to "true" with an entry point 2 pips above the high of the bar, say a price of 1.4236...then if that price is not met on subsequent bars BUT those bars ALSO evaluate to true then the high + 2 pips of those bars should be the new calculated entry point...not the original 1.4236 point...

The screenshot is showing entries being made at price levels that were not originaly met on the bar after the condition became true (the "original" entry price was not met on that "bar 2" but reached on later bars...).

NinjaTrader_Josh
12-02-2007, 08:35 PM
Again, use TraceOrders to see what limit price your orders are being submitted with. If you look at the output from my previous post you will see the limit price resubmission is changing to reflect the state of the new orders.

Also, please realize that limit orders will let you get filled at the specified price or better. From the screenshot it looks like you are getting "better" fills. Any price below your High + 2 ticks is considered a better price.

Burga1
12-02-2007, 08:58 PM
Well, I guess I'll try to take a look at TraceOrders but just to comment about your mention of "better fills"--that is basically my problem. I don't want "better" fills, I simply want the fill to happen (or not happen at all) on "bar 2" (the bar following the entry condition to be "true") at THAT particular price (high/low +/- 2 pips). My strategy depends on only that bar at the specified price level, if the entry is made on bar 3, or bar 5, or bar 13...OR is executed at a "better" price (a price I didn't specify) then that is of no use to me...in fact it more often than not gets me into trades I don't want to be in. Thus I don't want a trade to execute at all except on that "bar 2", and only "bar 2"...at the price I specify.

My testing is revealing many executed trades that should not have happened at all because the price level on "bar 2" was not met...thus resulting in many losing trades that shouldn't have triggered to begin with...I'm trying to eliminate this.

NinjaTrader_Josh
12-02-2007, 09:10 PM
Then I suggest you run a counter and just not resubmit your orders on the subsequent bars.

if(some condition is true && subsequentCounter < 1)
{
EnterPlace = High[0] + (2 * TickSize);
EnterLongLimit(1, EnterPlace, "Condition 1 Entry");
ExitPlace = Low[0] - (1 * TickSize);
SetProfitTarget(CalculationMode.Ticks, 4);
SetStopLoss("Condition 1 Entry", CalculationMode.Price, ExitPlace, true);
subsequentCounter++;
}

if (Position.MarketPosition == MarketPosition.Long)
{
subsequentCounter = 0;
}
Now this does not guarantee you a fill at the specified price either. There is no true way you can prevent your order from filling at a better price. This will just prevent subsequent resubmission of orders.

Burga1
12-02-2007, 09:33 PM
Thank you. There is no way to control the exact entry price? Might it be possible to use my "EnterPlace" variable in a market order perhaps?

NinjaTrader_Josh
12-02-2007, 09:36 PM
No. There are no order types you can send to the exchange that will guarantee you any fill price.

Please review this tip for all the possibilities available to you in respect to order types: http://www.ninjatrader-support.com/vb/showthread.php?t=3271

Burga1
12-02-2007, 10:10 PM
Thanks. In reviewing that information it seems to me perhaps I'm better off using the "EnterLongStop/EnterShortStop" commands instead...if my goal is to get the "+/- 2 pips" level...?

NinjaTrader_Josh
12-02-2007, 10:14 PM
Stops ultimately transform to market orders. This brings the risk of getting filled not only at better prices, but also at worst prices. It is your call which order type you want to use.