I've been messing about with the ADD() function for a few days observing some wierd / undocumented behaviour. I would appreciate if other users or NT developers could comment
For all cases all I am trying to do is add the default/current instrument but with differing time periods. These dataseries' are then used in the OnBarUpdate() function and (barsInProgress == xxx) to do different things at different times.
All comments relate to the Add function placed in the Initialize() function
(a) problems if Add is not in the lowest { } root.
Here I was trying to be tricky and dynamically add different data series based on user inputs, however I found that this would not work if the Add function was placed a few levels deep within an if statement or similar. I imagine this has to do with some kind of variable scope and allocation, however I can't see the behaviour documented.
For example, this kind of thing did not seem to work:
if (userVariable == 1440)
{
Add(PeriodType.Minute, 1440);
} else if (userVariable == 240)
{
Add(PeriodType.Minute, 240);
}
etc...
but this does:
Add(PeriodType.Minute, 1440);
Add(PeriodType.Minute, 240);
however you end up with 2 dataseries when I only wanted one...
(b) issues with anything other than PeriodType.Minute
None of the following seemed to work. I received no errors in the log or anywhere but my program would not backtest:
Add(PeriodType.Week, 1); // week
Add(PeriodType.Month, 1); // monthly
Add(PeriodType.Month, 3); // quarterly
Add(PeriodType.Year, 1); // yearly
I put this down to possibly only PeriodType.Minute supported by the add function, however then i ran into the next problem..
(c) issues with larger numbers of .minute:
I changed my code to the following for init to get my different timescaled bars:
Add(PeriodType.Minute, 240);
Add(PeriodType.Minute, 1440); // daily
Add(PeriodType.Minute, 1440*7); // weekly
Add(PeriodType.Minute, 1440*30); // monthly
Add(PeriodType.Minute, 1440*90); // quarterly
Add(PeriodType.Minute, 1440*365); // yearly
I noticed I was getting irregular values for ATR using the different data series. I debugged to investigate further and found the following:
- BarsArray {NinjaTrader.Data.Bars[8]} NinjaTrader.Data.Bars[]
+ [0] {instrument='$AUDUSD' from='2010-01-01' to='2011-10-04' period=240 Min splitAdjusted=False dividendAdjusted=False bars=2214} NinjaTrader.Data.Bars
+ [1] {instrument='$AUDUSD' from='2010-01-01' to='2011-10-04' period=1 Min splitAdjusted=False dividendAdjusted=False bars=530900} NinjaTrader.Data.Bars
+ [2] {instrument='$AUDUSD' from='2010-01-01' to='2011-10-04' period=240 Min splitAdjusted=False dividendAdjusted=False bars=2214} NinjaTrader.Data.Bars
+ [3] {instrument='$AUDUSD' from='2010-01-01' to='2011-10-04' period=1440 Min splitAdjusted=False dividendAdjusted=False bars=369} NinjaTrader.Data.Bars
+ [4] {instrument='$AUDUSD' from='2010-01-01' to='2011-10-04' period=10080 Min splitAdjusted=False dividendAdjusted=False bars=369} NinjaTrader.Data.Bars
+ [5] {instrument='$AUDUSD' from='2010-01-01' to='2011-10-04' period=43200 Min splitAdjusted=False dividendAdjusted=False bars=369} NinjaTrader.Data.Bars
+ [6] {instrument='$AUDUSD' from='2010-01-01' to='2011-10-04' period=129600 Min splitAdjusted=False dividendAdjusted=False bars=369} NinjaTrader.Data.Bars
+ [7] {instrument='$AUDUSD' from='2010-01-01' to='2011-10-04' period=525600 Min splitAdjusted=False dividendAdjusted=False bars=369} NinjaTrader.Data.Bars
Notice here how the "bars" property for the last 5 are all the same (369)
there is clearly an issue here.
Please help asap.
thanks
PB

Comment