Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Most efficient way to filter out dates in a multitimeframe strategy

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

    Most efficient way to filter out dates in a multitimeframe strategy

    IM running the backtest on minute data, my second data series is daily data

    Code:
       protected override void Initialize()
            {
          Add(PeriodType.Day, 1);
    under Onbarupdate im excluding several dates from trading

    Code:
    	if (BarsInProgress != 0)
    				return;	
    		
    
    		
    		
    	#region onbarupdate variables	
    		
    			.....
    
    if ( (ToDay(Time[0]) ==ToDay(new DateTime(2004,1, 8).AddDays(x))|| ToDay(Time[0]) ==ToDay(new DateTime(2004,2, 5).AddDays(x))||ToDay(Time[0]) == ToDay(new DateTime(2004,3, 4).AddDays(x))||ToDay(Time[0]) ==ToDay(new DateTime(2004,4, 1).AddDays(x)) ||
    	ToDay(Time[0]) ==ToDay(new DateTime(2004,5, 6).AddDays(x))||ToDay(Time[0]) ==ToDay(new DateTime(2004,6, 3).AddDays(x)) )
    
    {return;} else {}
    The code is working and the dates are excluded but im worried that this code is kind of slow.

    Will this statement be checked every new bar of my primary series?
    If yes, would are the best solution to improve the code? Creating a counter? Moving the filter to a section for the second dataseries.

    #2
    While most likely this code here will perform just fine you could improve performance by checking the first bar of session's time stamp instead of each bar.

    If the condition is true set a flag that prevents trading until the next first bar of session.

    Visually you likely won't notice much if any improvement but technically less calculations will take place.



    Regardless of what you do each bar will still be looked at, it's just a matter of how many calculations are ran on each bar.

    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    599 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    345 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    558 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    558 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X