Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Small issue when adding trading time filter to strategy

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

    Small issue when adding trading time filter to strategy

    I am somewhat new to programming strategies, but can generally understand the logic. I need help getting my trade time filter working. I might have it placed in the wrong state or something? I'm not entirely sure. I added 2 blocks of time on the strategy so it trades between those times.

    Everyting compiles just fine. I guess I'm not sure where I'm supposed to place each part of the code. The defaults go stat.setdefaults, but what about the rest of it?

    Here is what I added as defaults:

    Code:
    //Trading Time Filter #1
    StartTime1 = DateTime.Parse("06:00", System.Globalization.CultureInfo.InvariantCulture) ;
    EndTime1 = DateTime.Parse("07:15", System.Globalization.CultureInfo.InvariantCulture) ;
    
    //Trading Time Filter #2
    StartTime2 = DateTime.Parse("08:35", System.Globalization.CultureInfo.InvariantCulture) ;
    EndTime2 = DateTime.Parse("10:00", System.Globalization.CultureInfo.InvariantCulture) ;


    This is what I added for bools:

    Code:
    bool TradeBlock1 = ((Times[0][0].TimeOfDay > StartTime1.TimeOfDay) && (Times[0][0].TimeOfDay < EndTime1.TimeOfDay));
    bool TradeBlock2 = ((Times[0][0].TimeOfDay > StartTime2.TimeOfDay) && (Times[0][0].TimeOfDay < EndTime2.TimeOfDay));


    And then this is what I had for my logic:

    Code:
    // If not between start and end time return
    if (!TradeBlock1 && !TradeBlock2)
    
    {
    return;
    
    }



    Any help to get this functioning is greatly appreciated





    #2
    Hello traderty,

    Thank you for your post.

    You said that it compiled successfully; is the strategy behaving as expected when testing it out? If not, please describe the unexpected behavior that you are trying to correct. Additionally, we have a reference sample of a strategy that uses time filters to limit when it trades here:


    Please let us know if we may be of further assistance.

    Comment


      #3
      Good reading here.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      50 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X