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 Jonafare, 12-06-2012, 03:48 PM
      5 responses
      3,985 views
      0 likes
      Last Post rene69851  
      Started by Fitspressorest, Today, 01:38 PM
      0 responses
      2 views
      0 likes
      Last Post Fitspressorest  
      Started by Jonker, Today, 01:19 PM
      0 responses
      2 views
      0 likes
      Last Post Jonker
      by Jonker
       
      Started by futtrader, Today, 01:16 PM
      0 responses
      7 views
      0 likes
      Last Post futtrader  
      Started by Segwin, 05-07-2018, 02:15 PM
      14 responses
      1,792 views
      0 likes
      Last Post aligator  
      Working...
      X