NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-23-2011, 07:02 AM   #1
adamus
Senior Member
 
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
Default Trading gaps, need a market-on-open for backtesting

I want to write a strategy to backtest a theory that I can make money trading gaps.

I can't work out how best to implement this.

My first attempt was no good because the order is executed on the second bar after the gap is formed, whereas I want to enter at the market as soon as the Open[0] of the first bar arrives.

I realise i can do this in real-time with CalculateOnBarClose = false, but this doesn't work in backtesting.

The closest I can get is to use 1 minute bars but then I see I miss a considerable number of ticks.

Can I place a conditional Market-on-Open i.e. with a stop? I figure this would move into the realm of Unmanaged Orders, as long as I can backtest it.

Can't find anything in the Help or the forum messages.

Thanks.
adamus is offline  
Reply With Quote
Old 01-23-2011, 12:24 PM   #2
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

adamus, please try adding in a 1 tick series, and then send your orders to that series. You'd be at most 3 ticks late on the entry in that case. There is a reference sample for backtesting with an intrabar granularity.
NinjaTrader_Austin is offline  
Reply With Quote
Old 01-23-2011, 12:49 PM   #3
adamus
Senior Member
 
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
Default

Austin,

I have two issues with that.

Firstly, I have tick data from a third party data provider against which I will test going back to 1997 - but that will take huge amounts of time to run backtests on with a 1 tick series.

Secondly I have no tick data from Interactive Brokers whom I trade with and I would prefer to do my final backtesting against the data against which I will trade.

Is there any mechanism I can implement on the order API?

Thanks
adamus is offline  
Reply With Quote
Old 01-23-2011, 01:13 PM   #4
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

Unfortunately NinjaTrader does not currently support Market On Open orders.
NinjaTrader_Austin is offline  
Reply With Quote
Old 01-25-2011, 04:33 AM   #5
adamus
Senior Member
 
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
Default

OK, slightly disappointed but I guess there is no robust way to simulate a market order execution placed once the Open[0] tick is read.

It's also obviously disappointing that IB don't provide tick data.

The limits of our technical abilities have been reached, methinks.
adamus is offline  
Reply With Quote
Old 01-25-2011, 05:43 AM   #6
adamus
Senior Member
 
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
Default

Austin, I've got a related question trying to code this up.

I'm using a 1 tick series as advised.

I need the range for Friday, High - Low and I need to access this information in the onBarUpdate for the tick series on the first onBarUpdate on Sunday.

What's the easiest most performant way to do this?

Shall I add a 1 day bar time series and set CalculateOnBarClose = true and then do this:

fridayRange = High[1] - Low[1];

or is it

fridayRange = High[0] - Low[0];

Or is there a better way, from a processing speed point of view?
adamus is offline  
Reply With Quote
Old 01-25-2011, 07:09 AM   #7
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
Default

adamus, I think just using the PriorDayOHLC for the range would be more performing than adding a series for this task.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-28-2011, 08:58 AM   #8
adamus
Senior Member
 
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
Default

Hi Bertrand,

I'm trying it with the PriorDayOHLC and I'm getting completely different values for the bars on the Friday in the daily bars and the PriorDayOHLC().High etc.

My instruments are set to session template: forex

The PriorDayOHLC output seems to be showing much smaller bars. i.e. as if it were reading bars from the minute bars series.

Yet PriorDayOHLC should show the actual previous day's OHLC, isn't that so?

I guess I should look in the source.
adamus is offline  
Reply With Quote
Old 01-28-2011, 09:44 AM   #9
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
Default

adamus, the indicator would be tied to the chart session set, correct - to which series are you attempting to apply it? It would be working for intraday ones only.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-28-2011, 02:04 PM   #10
adamus
Senior Member
 
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
Default

Hmm, I'm not quite sure I follow you.

These are the values I'm trying to get when BarsInProgress=1 means the 1 day time series I added as the second bars.

HTML Code:
if (BarsInProgress == 1 && Time[0].DayOfWeek == System.DayOfWeek.Friday)
    Print("High==" + High[0] + " Low==" + Low[0] + " Close==" + Close[0]);
And this is how I'm trying to get them using PriorDayOHLC() - the bars series is either 1 tick bars or 1 minute bars.

HTML Code:
private PriorDayOHLC friday;

//onStartUp
friday = PriorDayOHLC();

//onBarUpdate 
if (BarsInProgress == 0 && Time[0].DayOfWeek == System.DayOfWeek.Sunday)
double fridayRange = friday.High[0] - friday.Low[0];
double gapStart = friday.Close[0];
adamus is offline  
Reply With Quote
Old 01-28-2011, 02:16 PM   #11
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

This likely would not work.

"friday" is an indicator object. There is no such thing of High or Low, etc. from that indicator. To access the values of that indicator you need to call the correct plot names for them which are PriorOpen, PriorClose, etc.

http://www.ninjatrader.com/support/h...r_day_ohlc.htm

It would be friday.PriorHigh[0] for example.
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Market Replay data gaps? scootaloo_trader Version 7 Beta General Questions & Bug Reports 4 09-24-2010 02:57 AM
How to start backtesting and trading freewind Installation and Licensing 1 01-18-2010 03:41 AM
Is it possible to do market replay and backtesting based on market depth? clearpicks Indicator Development 1 03-11-2009 04:07 PM
Market Gaps and Stop Orders GreenTrade Strategy Development 11 01-19-2009 06:26 PM
SetProfitTarget works in backtesting but not in live trading. Why? ooppie General Programming 3 10-03-2008 09:51 AM


All times are GMT -6. The time now is 03:04 PM.