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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      88 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      134 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X