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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    110 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    59 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    37 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    41 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    78 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X