Go Back   NinjaTrader Support Forum > NinjaTrader 7 > 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: 294
Thanks: 19
Thanked 11 times in 10 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: 294
Thanks: 19
Thanked 11 times in 10 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_JoshP
NinjaTrader Product Manager
 
NinjaTrader_JoshP's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,459
Thanks: 1
Thanked 293 times in 98 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_JoshP is offline  
Reply With Quote
Old 09-19-2010, 03:27 PM   #4
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 294
Thanks: 19
Thanked 11 times in 10 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_JoshP
NinjaTrader Product Manager
 
NinjaTrader_JoshP's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,459
Thanks: 1
Thanked 293 times in 98 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_JoshP 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
Problem with multi instruments?.. Godo78 Strategy Development 7 05-12-2010 04:15 PM
How to strategy test against multi timeframes ? wcredle Platform Technical Support 1 03-13-2009 03:37 PM


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

Futures, foreign currency and options 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.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.