![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
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.
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
|
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 |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
Unfortunately NinjaTrader does not currently support Market On Open orders.
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
|
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. |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
|
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? |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
|
adamus, I think just using the PriorDayOHLC for the range would be more performing than adding a series for this task.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
|
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. |
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Apr 2010
Posts: 1,058
Thanks: 33
Thanked 2 times in 1 post
|
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]);
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]; |
|
|
|
|
|
#11 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |