PDA

View Full Version : Only placing orders during market hours


HelloHello
09-21-2007, 04:32 PM
Hi, I would like to only place orders during market hours.

Say the stock market is closed and I place a buy limit order. How do i get it so that the price is only executed durning market hours? There is an option on IB "only place trades durning market hours" but this option is only for if you place manual orders and NOT for the API.


Thanks

NinjaTrader_Ray
09-21-2007, 09:43 PM
This is not supported. Orders goes live as you place them.

HelloHello
09-22-2007, 11:06 AM
Would there be a way to get around this by changing the setting or the IB API... or would this be a bit too complicated?

NinjaTrader_Ray
09-22-2007, 11:19 AM
Unfortunately there is no way around this.

HelloHello
09-22-2007, 12:26 PM
I thought of a way I could get around it.

1) The function NTCancelAllOrders; Would that function cancel orders that I initated by putting in manually, or just all orders initated by the API?

2) Also, say I place a order "manually" to buy 100 shares of INTC.

would the following code execute even though the order wasn't initiated by the API? Basically I'm wondering if I can manually put in the orders, and then let the automation manage the trade?

if NTMarketPosition("") <> 0 then
begin
///
///
end;


Thanks

NinjaTrader_Ray
09-22-2007, 06:27 PM
1) All orders across all accounts

2) Current implementation it will not work since position is only reported if an order is initiated through the ATI. With NT 6.5 due out this fall it will report position even if an order was not initiated through the ATI.

bkout
05-07-2009, 07:52 AM
I was surprised to see a Limit Order executed before market hours this morning when I set up my strategy. Is there still no way to confine orders to market hours? I have IB set to market hours as default but based on this thread I guess Ninja overrides that and checking another Ninja entered limit order I have I see that it is enabled for after hours. I could change that one by hand but of course not if it instantly executes which is what happened this morning. I can't imagine that I would have to wait till 9:30 to enter my strategy????

NinjaTrader_Bertrand
05-07-2009, 08:06 AM
Have you tried setting up time filters rules for your strategy? - http://www.ninjatrader-support2.com/vb/showthread.php?t=3226

bkout
05-07-2009, 08:23 AM
I do actually have a time rule for my entry. Since I don't know code I hope there's a way to do that in the wizard for Profit stops? I don't see a way to enter that kind of rule on the stop page.

NinjaTrader_Bertrand
05-07-2009, 08:30 AM
Unfortunately this is not possible on the 'Stops and Targets' page, you could enter this as a condition and then place your Exit() order only during a certain timeframe, like you have coded your entries.

bkout
05-07-2009, 07:26 PM
Not sure I understand that -- is that something that can be done in the wizard?

NinjaTrader_Bertrand
05-08-2009, 06:24 AM
Yes, I believe so if I follow your issue correctly, you can take a look at this link - http://www.ninjatrader-support.com/HelpGuideV6/ConditionBuilder-TimeComparisons.html

Then enter those stops only when the time filters give you 'green light'.

bkout
05-08-2009, 11:37 AM
OK I understand the "Time filter" in terms of using it with the entry (see attached) but when you say "enter those stops only when the time filters give you 'green light'." how do I implement that within the wizard? I don't see any place to put say a 10% stop order on the entry page or a way to put the time condition on the stop page. Is there maybe a tutorial or something you could point me to?

NinjaTrader_Josh
05-08-2009, 12:06 PM
bkout,

That is correct. You cannot apply a time filter to the Stops & Targets page. Instead of using those you will want to directly place an ExitLongStop or ExitLongLimit order.

bkout
05-08-2009, 01:23 PM
OK thanks for walking me through this -- I'm thinking this is going to do what I'm looking for. Please see the two attached images -- after filling out Set 1 and Set 2 for my Long and Short entries I''m using Set 3 to create my 10.5% stop loss. Please check me on the numbers -- will .895 the way I have it give me a 10.5% stop loss from the entry price? Then I have the time rules above so that the stop will only be in effect during mkt hours (my computer is set to EST. How does this look?

NinjaTrader_Josh
05-08-2009, 01:28 PM
Wrong offset. You want to do a negative offset for 0.105 not +0.895.

bkout
05-10-2009, 09:04 PM
OK thanks -- almost there I think. The first capture shows the 10.5% stop for longs and shorts which only applies during market hours. The second capture shows the 21% profit target. Backtesting shows these working as expected with this exception... there was a trade where the open gapped past the profit stop -- however instead of the exit happening immediately or on the next bar as one might expect it did not happen till the price was exactly at the profit stop! What do I need to adjust so that the exit is at the profit stop OR BETTER??

NinjaTrader_Josh
05-11-2009, 07:51 AM
bkout,

I am not following you. Your stop/targets are calculated based off of whatever entry price you get filled at. If the market gapped up your stop/targets will take that into account for your 10.5% and 21%.

bkout
05-11-2009, 08:24 AM
OK -- here's the specific trade that concerned me. SKF entered a short position at 54.50. You can see on the capture that the profit stop is set to 24%. 54.50*76% = 41.42. I captured a chart and the settings for the backtest. On 5/7 SKF opened at 39.54 and the first 6 min bar closed at 40.00 after making a high of 40.37. The next bar opened at 39.85 and had a high of 40.64. So my question is why do the chart and trade report show an exit on the first candle at 41.42? That price was not even reached till the third candle. Somehow the exit took place exactly at the 24% profit price -- should have been lower. Over the last year whenever the profit stop is hit the exit is always at 24.00% !! Something is off.

NinjaTrader_Josh
05-11-2009, 09:02 AM
Not sure I am following you. The bar you have in your screenshot gapped down. It will exit at 41.42 when price gaps down past 41.42.

bkout
05-11-2009, 09:06 AM
No -- a limit order should be filled at the limit price OR BETTER. If you are short and the market opens below your limit buy to cover order the fill should be at that trading level -- it should NOT wait untill price rises back to the limit price.

NinjaTrader_Josh
05-11-2009, 09:12 AM
Not following you. I don't see any waiting for anything. Since the market opened below the market, that is why it closed the trade on that bar. It is not waiting for price to come back. In backtesting a limit order will fill you at the limit price to prevent overstating of performance.

bkout
05-11-2009, 09:24 AM
OK the last part of what you said reveals the problem. If that's the way the backtest has to be I guess that's the end of it, but I think you would be providing a much more realistic backtest by filling at the available price even if it was the high of the bar. You said that you "don't see any waiting for anything" -- but the fill price was not available on the bar that shows the position closed -- look at how the little triangle is "up in the air" above the bar. Anyway I would request to have the option of having a profit target hit at a realistic trading price rather than the limit.

Beyond that please tell me how the setup I have now will handle this gap situation in live trading -- would it exit at the open or at the open of the second bar?

Thanks for explaining -- at least it's clearer what is happening.

NinjaTrader_Josh
05-11-2009, 09:38 AM
bkout,

You can try switching between the liberal and the default fill algorithms. If you do not find one that fits your needs you can also try making your own. Unfortunately we do not support this though: http://www.ninjatrader-support.com/HelpGuideV6/FillTypes.html

In live trading it depends on your CalculateOnBarClose settings. It will exit whenever the conditions deem it feasible to exit.

bkout
05-11-2009, 09:50 AM
Just to verify something -- I want to confirm that the backtest outcome you describe does NOT apply to stop losses. If I have a 10% stop on a long position and the market opens down 20% I want my backtest to show a 20% loss. From looking at backtests it looks like that it will show the 20% loss -- is that correct? Thx

NinjaTrader_Josh
05-11-2009, 09:56 AM
That is correct. Stop orders are ultimately market orders. Limit orders are not.

bkout
05-13-2009, 08:28 AM
Ran into a problem this morning. Normally my system if it is long and gets a EMA cross signal then it closes the long and goes short. The system does have a stop loss and a profit target. Today the stop loss was hit and the long position exited. So far so good. But when a short position triggered Ninja didn't seem to know about the previous long having been exited via the stop so it "exited" (really shorted) the number of shares that had been the long position in addition to (corrrectly) entering the short. So I ended up with basically a double position short. How do I use the wizard to make sure this doesn't happen again? Thanks

NinjaTrader_Josh
05-13-2009, 08:40 AM
bkout,

Please provide more information as to the exact order types submitted. Did you try to scale out without scaling in?

bkout
05-13-2009, 08:54 AM
No but I *may* have adjusted the order for slight error in number of shares -- not sure as it has been a busy morning. Will send orders and log to you at support.

NinjaTrader_Josh
05-13-2009, 08:57 AM
bkout,

That could be it. If you have some unmatched order share quantity it will cause problems. Please ensure they are tidy. If your entry was 100, your exit should be 100. If you want a 50-50 split exit, you need two entries of 50 each.

bkout
05-13-2009, 06:23 PM
I've based most of my systems off one I copied from someone else. When the EMAs do a bullish cross (Condition) then I have EnterLong as an Action. Likewise a Bearish cross has EnterShort as an Action. The system is set to exit at the close. Generally this has backtested and worked well in real trading. The occassional odd share size in the orders however makes me wonder if I need to add an ExitShort to the EnterLong order and and ExitLong to the EnterShort order?

Would that make any difference in trading? What does ExitShort for example do if there is no current short position?

NinjaTrader_Josh
05-14-2009, 07:08 AM
You do not need to do an ExitShort before EnterLong. When you do EnterLong NinjaTrader will automatically close the short position and get you in the appropriate long position. To figure out your position sizing you will need to use TraceOrders = true.

If you call ExitShort while there is no short position it will simply be ignored.