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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    152 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    87 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    131 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    127 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    106 views
    0 likes
    Last Post CarlTrading  
    Working...
    X