Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsPeriods.BarsPeriodType in Backtesting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    BarsPeriods.BarsPeriodType in Backtesting

    Hi,

    So in NT7 I used to have a lot of multi-series indicators which worked on both day and minute charts. To do this without hardcoding them as either day or minute indicators, I would use the following so that the indicator would automatically derive the secondary series from the primary series of the chart/strategy:

    Code:
    Add("XYZ", BarsPeriods[0].Id, BarsPeriods[0].Value);
    I take it that this has now been renamed, and the NT8 equivalent is:

    Code:
    AddDataSeries("XYZ", BarsPeriods[0].BarsPeriodType, BarsPeriods[0].Value);
    However, when I have used this in an indicator which is then used within a strategy using AddChartIndicator(), I have encountered some problems. Note that these problems are found when the strategy is backtested in Strategy Analyzer. I am backtesting a daily bar strategy, and have the following line of code within my indicator:

    Code:
    Print (CurrentBars[0] + " / " + CurrentBars[1] + " : " + CurrentBars[2]);
    This then prints the following, which makes me think that the indicator is adding 1 minute bars, despite the primary bar series being daily bars:
    1 / 777 : 689
    2 / 1166 : 1034
    3 / 1555 : 1379
    4 / 1932 : 1724

    When I change the code in the indicator to the following, I get the following as expected:

    Code:
    AddDataSeries("XYZ", BarsPeriodType.Day, 1);
    1 / 1 : 1
    2 / 2 : 2
    3 / 3 : 3
    4 / 4 : 4
    5 / 5 : 5
    6 / 6 : 6

    #2
    Hello wuileng,

    Thank you for your post.

    BarsPeriod can run into this issue in both NinjaTrader 7 and 8. It is not designed to run in Initialize() (NT 7) or SetDefaults (NT 8) as the bars objects may not have loaded yet.

    While I have had luck running this in Initialize() in NinjaTrader 7 it does not always work and in most cases does not work on any ones PC that I provide the code to. This is due to the fact the bars have not loaded.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by algospoke, Yesterday, 06:40 PM
    2 responses
    24 views
    0 likes
    Last Post algospoke  
    Started by ghoul, Today, 06:02 PM
    3 responses
    15 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    46 views
    0 likes
    Last Post jeronymite  
    Started by Barry Milan, Yesterday, 10:35 PM
    7 responses
    23 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by AttiM, 02-14-2024, 05:20 PM
    10 responses
    181 views
    0 likes
    Last Post jeronymite  
    Working...
    X