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

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.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Good reading here.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by AaronKoRn, Today, 09:49 PM
      0 responses
      5 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Today, 08:42 PM
      0 responses
      8 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Today, 07:51 PM
      0 responses
      9 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,975 views
      3 likes
      Last Post jhudas88  
      Started by rbeckmann05, Today, 06:48 PM
      0 responses
      9 views
      0 likes
      Last Post rbeckmann05  
      Working...
      X