Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Walk forward optimization using data it shouldn't know about

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

    Walk forward optimization using data it shouldn't know about

    Hello,

    I noticed that the optimizer doesn't always respect the from and to dates that you set. For example if I set a strategy to optimize from Jan 3rd to Jan 5th, sometimes I see trades that took place on the 2nd and 6th.

    My strategy has a profit factor of 4.0 - 5.0 and trades many times a day, I was worried this was fake and it scared me that it's trading outside of it's range. For example, Jan 6th is the out of sample period, so this is how I measure how well it works.

    I started doing some detective work and created this bit of code, instantly I got hundreds of prints stating "OnBarUpdate called with bad bar", and the profit factor dropped instantly to 0.5 .

    I'm not sure what's causing it and it doesn't happen on all of my machines. Here's the code I'm using to stop it:

    Code:
            private DateTime bt_start ;
            private DateTime bt_end ;
    
            protected override void Initialize()
            {
                bt_start = this.BackTestFrom;
                bt_end = this.BackTestTo;
            }
    
            protected override void OnBarUpdate()
            {
                if(this.Account.Mode == Mode.Simulation) {
                    if(Time[0] < bt_start) {
                        //Print("OnBarUpdate called with bad bar " + Time[0]);
                        return;
                    }
                    if(Time[0] >= bt_end) {
                        //Print("OnBarUpdate called with bad bar " + Time[0]);
                        
                        if (Position.MarketPosition == MarketPosition.Long) {
                            ExitLong();    
                        }
                    
                        return;
                    }
                }
        }

    #2
    eduffield, this would be unfortunately an expected limitation you're running into here - the session templates defined would always be used in full, so it would not segment the template even if it would mean for your setup it would span across the date. This is on our list to look into for your next major platform update.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    32 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, Yesterday, 02:41 AM
    0 responses
    14 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    23 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    34 views
    0 likes
    Last Post CarlTrading  
    Working...
    X