Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy doesn't work properly unless AddDataSeries() is added

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

    Strategy doesn't work properly unless AddDataSeries() is added

    Hey all,

    I'm working on a 5 minute strategy, that started off as a 1 and 5 minute multi time-series strategy. Anyways, I'm noticing something strange when I remove or comment out the line

    AddDataSeries(BarsPeriodType.Minute, 5);

    The strategy now only takes about 60-70% of the trades it took when that line was left in. From my understanding, if the strategy is designed to run on a 5 minute chart, AddDataSeries() doesn't need to be called at all. It just needs to be set to a 5 minute data series on a chart or in the Strategy Analyzer.

    Can a NinjaTrader expert take a look at my strategy code below, and do the following?

    1) Uncomment AddDataSeries(BarsPeriodType.Minute, 5);
    2) Change (starts on line 320)

    if(BarsInProgress == 1 && CurrentBar >= 3){


    if(IsSwingHigh())

    listSwingHighs.Add(Draw.Line(this, string.Format("MSS{0}", CurrentBar), false, 2, High[1], -1, High[1], Brushes.Green, DashStyleHelper.Dash, 1));

    else if(IsSwingLow())

    listSwingLows.Add(Draw.Line(this, string.Format("MSS{0}", CurrentBar), false, 2, Low[1], -1, Low[1], Brushes.Red, DashStyleHelper.Dash, 1));


    }

    to

    if(BarsInProgress == 0 && CurrentBar >= 3){

    if(IsSwingHigh())

    listSwingHighs.Add(Draw.Line(this, string.Format("MSS{0}", CurrentBar), false, 2, High[1], -1, High[1], Brushes.Green, DashStyleHelper.Dash, 1));

    else if(IsSwingLow())

    listSwingLows.Add(Draw.Line(this, string.Format("MSS{0}", CurrentBar), false, 2, Low[1], -1, Low[1], Brushes.Red, DashStyleHelper.Dash, 1));


    }

    3) Run a backtest and note how many trades are taken
    4) Then, completely remove the 5 minute data series and change all references to BarsInProgress to 0 (primary series) and BarsArray[0] to just Bars

    I am desperately trying to understand why the number of trades are different, when the entry logic is exactly the same code. The only thing is that it changes from a multi time-series strategy to a single.

    Any help would be appreciated. Thanks!

    Attached Files
    Last edited by jaybedreamin; 03-02-2023, 08:09 PM.
    jaybedreamin
    NinjaTrader Ecosystem Vendor - Zion Trading Algos

    #2
    Hello jaybedreamin,

    If by removing that the results change that means that changed how your logic was executed. Our support can't debug scripts for you so this would be a situation where you would need to add prints to see how commenting that out changes your logic. I see that you have a condition for BarsInProgress 1 so removing AddDataSeries effectively turns off that part of your logic.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X