Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 samish18, Yesterday, 08:31 AM
    4 responses
    14 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by funk10101, Yesterday, 09:43 PM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by TheWhiteDragon, 01-21-2019, 12:44 PM
    5 responses
    551 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by rtwave, 04-12-2024, 09:30 AM
    5 responses
    37 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by funk10101, Today, 12:02 AM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Working...
    X