Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 05-04-2012, 08:33 AM   #1
norsay
Junior Member
 
Join Date: Apr 2012
Posts: 9
Thanks: 1
Thanked 1 time in 1 post
Default Historical flag false after adding 2nd time-frame

Hi,

We have a strategy which needs a 2nd time-frame. Adding the first time-frame works fine and the feature "days to load" works as expected. The strategy indicates these data as "historical" (by setting the flag named Historical). As soon as we add the 2nd time-frame the flag is immediately set to false, even for historical data.

Is this behavior as expected? Or what can we do to correctly load historical data for multi time-frame strategies?

Best regards
norsay is offline  
Reply With Quote
Old 05-04-2012, 08:58 AM   #2
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 5,735
Thanks: 189
Thanked 780 times in 746 posts
Default

Hello,

The second data series should load the same amount of historical data as the primary input source.

Would you be able to provide me with a snippet of your code which demonstrates this behavior?
NinjaTrader_Matthew is offline  
Reply With Quote
Old 05-06-2012, 11:36 PM   #3
norsay
Junior Member
 
Join Date: Apr 2012
Posts: 9
Thanks: 1
Thanked 1 time in 1 post
Default

Hi Matthew

Here are the code samples you asked for. "Wait until flat" is set for real time strategies. The time frame is set to 2 "days to load".

Code:
protected override void Initialize() {
	...	
	Add(ADX(14));
	...
	CalculateOnBarClose = true;
	...
}

protected override void OnBarUpdate() {
	...
	Print("DEBUG: OnBarUpdate() - Historical Data: " + Historical + "Time = " + Time[0]);
	...
}
The sample above works as expected in live trading. The historical data for 2 days in the past are processed for the defined time interval immediatly after starting the live strategy. The Historical flag returns true until we reach the actual live data. That is ok so far.

However as soon as I add a 2nd time frame like in the following example. All data are flaged as Historical false (historical and live data).

Code:
protected override void Initialize() {
	...	
	Add(ADX(14));
	Add(PeriodType.Day, 1);
	...
	CalculateOnBarClose = true;
	...
}

protected override void OnBarUpdate() {
	...
	Print("DEBUG: OnBarUpdate() - Historical Data: " + Historical + "Time = " + Time[0]);
	...
}
Is this a bug? Or is there an other way the see if we are processing historical data or live date?

Best regards
norsay is offline  
Reply With Quote
Old 05-07-2012, 07:30 AM   #4
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 5,735
Thanks: 189
Thanked 780 times in 746 posts
Default

Hello,

Your strategy is not meeting the minimum bars required when the daily series is added. By default the strategy will need at least 20 bars. To account for weekends, etc please try increasing your days to load to 25.

You can also try setting Initialize() to BarsRequired = 0;
NinjaTrader_Matthew is offline  
Reply With Quote
Old 05-07-2012, 08:00 AM   #5
norsay
Junior Member
 
Join Date: Apr 2012
Posts: 9
Thanks: 1
Thanked 1 time in 1 post
Default

Hello,

Neither increasing the "days to load" value to 25 nor setting the BarsRequired = 0 has changed the behavior... All data processed are still flaged as Historical = false...
norsay is offline  
Reply With Quote
Old 05-07-2012, 08:05 AM   #6
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 5,735
Thanks: 189
Thanked 780 times in 746 posts
Default

If you set the days to load to 50, do you get the prints as true? Please try increasing the days to load to see if you can get this to return as true. In my testing, as long as the bars required was fulfilled, it should return as true.
NinjaTrader_Matthew is offline  
Reply With Quote
Old 05-07-2012, 08:39 AM   #7
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 5,735
Thanks: 189
Thanked 780 times in 746 posts
Default

Hello,

Another approach would be adding a current bars check to return if the minimum bars required is not met:

Code:
     protected override void Initialize()
        {
            Add(ADX(14));
            Add(PeriodType.Day, 1);
            
            CalculateOnBarClose = true;
            BarsRequired = 0;

        }
        
        protected override void OnBarUpdate()
        {
            
        if(CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired) return;
            
            
         Print("DEBUG: OnBarUpdate() - Historical Data: " + Historical + "Time = " + Time[0]);
           
         }
Last edited by NinjaTrader_Matthew; 05-07-2012 at 08:42 AM.
NinjaTrader_Matthew is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Matthew for this post:
Old 05-08-2012, 03:11 AM   #8
norsay
Junior Member
 
Join Date: Apr 2012
Posts: 9
Thanks: 1
Thanked 1 time in 1 post
Thumbs up

Hi Matthew

Increasing the "days to load" to at least 50 values did the job! Unfortunately I increased the value only to about 40 during my first test Sorry...

Guess I learned a lot for further implementations

I appreciate you help very much! Thank you!
norsay 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
Adding time frame to drop down menu tpt56 Charting 2 12-12-2011 09:13 PM
No Trades when adding a 2nd Timeframe to a Strategy laocoon Strategy Development 13 06-22-2010 07:27 AM
Multi Time Frame Strategy & CalculateOnBarClose = false in strategy analyzer tomtom Version 7 Beta General Questions & Bug Reports 7 05-02-2010 08:57 PM
adding 2nd panel while backtesting wkmetal Version 7 Beta General Questions & Bug Reports 2 04-12-2010 08:37 PM
Discretionary adding of a secondary time frame rperez Strategy Analyzer 8 11-16-2009 12:47 PM


All times are GMT -6. The time now is 11:33 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.