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 09-18-2010, 11:38 PM   #1
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 184
Thanks: 3
Thanked 0 times in 0 posts
Default NT7 - Multi-timeframes multi instruments

All,

A question in relation to NT7 multi-timeframe multi-instrument strategies.
The below code snippet is executed as part of a strategy on a 10min chart.
Code:
protected override void Initialize()
{
  Add(PeriodType.Minute,30);
  Add("^SP500",PeriodType.Minute,10);
  Add("^SP500",PeriodType.Minute,30); 
}

protected override void OnBarUpdate()
{
  if (FirstTickOfBar) 
  {
    if (CurrentBar < 200) return;
    Print (Time.ToString() + " - " + BarsInProgress);
  }
}
I would have expected a result similar to the below list.
17/09/2010 11:30:00 AM - 0
17/09/2010 11:30:00 AM - 1
17/09/2010 11:30:00 AM - 2
17/09/2010 11:30:00 AM - 3
17/09/2010 11:40:00 AM - 0
17/09/2010 11:40:00 AM - 2
17/09/2010 11:50:00 AM - 0
17/09/2010 11:50:00 AM - 2
17/09/2010 12:00:00 AM - 0
17/09/2010 12:00:00 AM - 1
17/09/2010 12:00:00 AM - 2
17/09/2010 12:00:00 AM - 3
However, BarUpdates are not being processed as expected, it seems BarUpdates are being randomly skipped.


Regards
Shannon
Shansen is offline  
Reply With Quote
Old 09-19-2010, 04:17 AM   #2
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 184
Thanks: 3
Thanked 0 times in 0 posts
Default

All,

In the same vein as NT6.5, I've re-ordered the BarArrays to be in in descending order and lower than the Primary BarArray. This partially corrects the issue (where BarArrays 0 & 1 are 30min and BarArrays 2 & 3 are 10min)...
Code:
0 - 17/09/2010 4:30:00 AM
1 - 17/09/2010 4:30:00 AM
2 - 17/09/2010 4:30:00 AM
3 - 17/09/2010 4:30:00 AM
2 - 17/09/2010 4:40:00 AM
3 - 17/09/2010 4:40:00 AM
2 - 17/09/2010 4:50:00 AM
3 - 17/09/2010 4:50:00 AM
0 - 17/09/2010 5:00:00 AM
1 - 17/09/2010 5:00:00 AM
2 - 17/09/2010 5:00:00 AM
3 - 17/09/2010 5:00:00 AM
However, for what seems to be whole days things get a little strange, three different combinations from what I can see...
Code:
0 - 16/09/2010 10:00:00 AM
2 - 16/09/2010 10:00:00 AM
2 - 16/09/2010 10:10:00 AM
2 - 16/09/2010 10:20:00 AM
0 - 16/09/2010 10:30:00 AM
2 - 16/09/2010 10:30:00 AM

3 - 10/09/2010 2:30:00 AM
3 - 10/09/2010 2:40:00 AM
3 - 10/09/2010 2:50:00 AM
3 - 10/09/2010 3:00:00 AM

1 - 18/09/2010 4:30:00 AM
3 - 18/09/2010 4:30:00 AM
3 - 18/09/2010 4:40:00 AM
3 - 18/09/2010 4:50:00 AM
1 - 18/09/2010 5:00:00 AM
3 - 18/09/2010 5:00:00 AM
Ideas are most welcome.

Regards
Shannon
Shansen is offline  
Reply With Quote
Old 09-19-2010, 01:00 PM   #3
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,460
Thanks: 1
Thanked 171 times in 82 posts
Default

Shannon,

The way it works is that you will get the event in chronological order. Please be aware that missing data will result in "missing" updates too. Of course real-time behaves completely different than historical as well depending on CalculateOnBarClose since those events get triggered by whichever data event comes down the pipes first from your data provider.
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-19-2010, 03:27 PM   #4
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 184
Thanks: 3
Thanked 0 times in 0 posts
Default

Josh.

Thanks for the quick reply.

The two instruments I'm working with are the ^SP500 and the current ES. I would not have expected "missing" data. As I have no control over what or when missing data will present, any recommendations on the structure for robust coding?

Also you mentioned real-time behaves differently to historical depending on CalculateOnBarClose (COBC), please elaborate further.
My strategy will run as COBC = false. While is is designed to reference the appropriate bar information. Still, unexpected barupdate events will not help.

Regard
Shannon
Shansen is offline  
Reply With Quote
Old 09-19-2010, 09:19 PM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,460
Thanks: 1
Thanked 171 times in 82 posts
Default

Shannon,

Basically NT is event driven. This means that you should not rely on a certain sequence of events, especially timestamps across different instruments. In real-time the events are processed as they come in. If ES decides to push a tick through your data provider before ^SP500, then you will receive the ES BarsInProgress event first. If on a different tick, ^SP500 came first, then you would get that one first. There is no way you can predict which one will come first and which one will come second. If data on ES suddenly stops for some reason, but ^SP500 continues you will just keep receiving ^SP500 events and completely skip the ES BarsInProgress.

To deal with this behavior I have no general guidelines I can provide because it is really dependent on what logic you are exactly trying to do. If your code requires both BarsInProgress to have received the information of a certain point in time, you can check the other BarsInProgress' information when you receive one to see if you did receive it already. If you have not, then don't process your logic yet.
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Tags
firsttickofbar, instruments, multi, nt7, timeframe

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
SetStopLoss() in multi timeframes DarthTraderson Strategy Development 11 03-01-2013 04:39 AM
Multi TimeFrames -- 2nd Secondary dpennypacker Version 7 Beta General Questions & Bug Reports 7 06-30-2010 04:38 PM
Problem with multi instruments?.. Godo78 Strategy Development 7 05-12-2010 04:15 PM
RSI (multi timeframes) returned values are different between Ninja 6.5 and 7 Jean-Marc-Molina Version 7 Beta General Questions & Bug Reports 6 11-16-2009 09:51 AM
How to strategy test against multi timeframes ? wcredle Strategy Analyzer 1 03-13-2009 03:37 PM


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

FULL RISK DISCLOSURE: Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.