Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using a time filter overnight with the strategy builder GUI?

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

    Using a time filter overnight with the strategy builder GUI?

    I can't see to get this to behave correctly.

    I'd like to set a time filter that only places trades from 6pm to 8am, closing all positions at 8am. But when I apply this logic to a set in the strategy builder, it takes no trades. Doing some reading on this, it sounds like there is an issue with the 24h clock and using strategy builder, but I'm not very proficient with coding so have a bit of difficulty understanding how to apply these fixes in a strategy.

    Is there a way to build this in the GUI of strategy builder? Or does it need to be coded?

    #2
    Hello sclay115,

    To do what you are asking you would need to make two conditions in a set, the first is checking if the time is greater or equal to 6am, the second checking if the time is less than 8am. That would be your entry set. In a separate set you could make two conditions, one checking if the position is not flat and the other that the time is greater than 8 am.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello sclay115,

      To do what you are asking you would need to make two conditions in a set, the first is checking if the time is greater or equal to 6am, the second checking if the time is less than 8am. That would be your entry set. In a separate set you could make two conditions, one checking if the position is not flat and the other that the time is greater than 8 am.

      https://ninjatrader.com/support/help...ateTimeFilters
      I eventually worked this out, and it's odd how it needed to happen. The qualifier "If Any" or "If All" was strange in this case. If I used "If All" for the condition requirements, no trades were taken with the logic of say greater than 8PM, but less than 8AM. But if I used the logic "If Any", trades were placed within the specified time span. I did need to eliminate the "Exit on Session Close" option, as it just assumed the session ended at midnight, which was odd.

      Does this make sense? Am I doing something wrong?

      Comment


        #4
        I don't know if you are comfortable with programming in Ninjascript editor. I implemented similar time filter function by Ninjascript without any issue. My suggestion is to click "view code" button in the strategy builder to check if the code generated by strategy builder is correct.

        Comment


          #5
          Originally posted by Playdc View Post
          I don't know if you are comfortable with programming in Ninjascript editor. I implemented similar time filter function by Ninjascript without any issue. My suggestion is to click "view code" button in the strategy builder to check if the code generated by strategy builder is correct.
          Thanks for the reply! I'm not really, which is why I was hoping to do it in the GUI. I did however use a similar, working code from another thread on here as a comparison tool to determine the best way to get the GUI interface to behave. Sort of a round about way to do it, but I got there in the end!

          Comment


            #6
            I think Ninjascript is way more powerful than strategy builder. For example, for conditions, you could only choose any or all for all inputs in strategy builder. However, you could use the complex logic such as ((input1 and input2) or (input3 and input4)) etc. I think a good practice is to use your own strategy that is generated by strategy build, then view code, so you could easily pin point which part in the code deals with the condition logic. Then copy and paste the code to editor, edit the condition logic. Finally, compile the code. Since the strategy builder generates the whole code template, you just need to do some minor changes.

            Comment


              #7
              I agree, it's a lot stronger, but not likely something I'll be working on immediately. The concept/strategy is very simple, and doesn't require any complex coding, at least, it shouldn't.

              Comment


                #8
                Originally posted by NinjaTrader_Jesse View Post
                Hello sclay115,

                To do what you are asking you would need to make two conditions in a set, the first is checking if the time is greater or equal to 6am, the second checking if the time is less than 8am. That would be your entry set. In a separate set you could make two conditions, one checking if the position is not flat and the other that the time is greater than 8 am.

                https://ninjatrader.com/support/helpGuides/nt8/index.html?strategybuilder_condition_builder.htm#H owToCreateTimeFilters
                Jesse, turns out this is still misbehaving. Can you double check my work here? If you can review and tell me the expected outcome of when this strategy would allow itself to enter a position, here are screencaps of the time control logic:

                Click image for larger version

Name:	image.png
Views:	80
Size:	9.6 KB
ID:	1333032

                Click image for larger version

Name:	image.png
Views:	82
Size:	16.6 KB
ID:	1333033
                Click image for larger version

Name:	image.png
Views:	80
Size:	16.4 KB
ID:	1333034

                What I'm hoping for is for this strategy to be limited to the hours of 7pm and 8am. However, while running on a sim environment, with live data, it entered a position at 6:48PM.

                Any ideas why this might still not be working correctly?

                Comment


                  #9
                  Hello sclay115,

                  If you are trying to cross midnight you will need to make a second set of conditions in a group. The time condition would need to span a time that is within the same day. You also need to select "if all" in the group so both conditions are required to be true.

                  In the first group you would select 7pm and 11:59pm as the times. In the second group you would use 12:00am and 8:00m as the times

                  Comment


                    #10
                    Originally posted by NinjaTrader_Jesse View Post
                    Hello sclay115,

                    If you are trying to cross midnight you will need to make a second set of conditions in a group. The time condition would need to span a time that is within the same day. You also need to select "if all" in the group so both conditions are required to be true.

                    In the first group you would select 7pm and 11:59pm as the times. In the second group you would use 12:00am and 8:00m as the times
                    Thanks Jesse

                    Out of curiosity, will that allow positions to be held over the two conditions? If I'm in a position at 11.59P, it wouldn't try to exit as it was reaching the time barrier, would it?

                    Also, while I have you, I need a command that allows me to close my position once a time hits a certain time, it seems like the fix to the logic above would solve this, correct?

                    Comment


                      #11
                      Originally posted by NinjaTrader_Jesse View Post
                      Hello sclay115,

                      If you are trying to cross midnight you will need to make a second set of conditions in a group. The time condition would need to span a time that is within the same day. You also need to select "if all" in the group so both conditions are required to be true.

                      In the first group you would select 7pm and 11:59pm as the times. In the second group you would use 12:00am and 8:00m as the times
                      Also, sorry, can you clarify, there needs to be a second condition group? Or an additional set of conditions in a single group?

                      The times below that can't be read, are, in order:

                      17:00
                      23:59
                      0:00
                      8:00

                      Click image for larger version

Name:	image.png
Views:	79
Size:	11.1 KB
ID:	1333232

                      Comment


                        #12
                        Hello sclay115,

                        You will need two seperate groups. The problem is that the time cannot be greater than 7 pm and less than 8am in the same day. A single group is only going to be checking the current time against the time window so it would need to be in a range within a single day. In a first group you would define 7pm and 11:59pm as the times. In the second group you would use 12:00am and 8:00m as the times. Both groups will need to use "If All" so that the time has to be between the two values.

                        Regarding the position, yes a position should be able to be held until you close it. To close the position you would generally use the appropriate exit order. For example in a condition where you are checking if the position is long and the time is within the window you would submit an exit long action. That will close the position.

                        Comment


                          #13
                          Originally posted by NinjaTrader_Jesse View Post
                          Hello sclay115,

                          You will need two seperate groups. The problem is that the time cannot be greater than 7 pm and less than 8am in the same day. A single group is only going to be checking the current time against the time window so it would need to be in a range within a single day. In a first group you would define 7pm and 11:59pm as the times. In the second group you would use 12:00am and 8:00m as the times. Both groups will need to use "If All" so that the time has to be between the two values.

                          Regarding the position, yes a position should be able to be held until you close it. To close the position you would generally use the appropriate exit order. For example in a condition where you are checking if the position is long and the time is within the window you would submit an exit long action. That will close the position.
                          Okay, thanks Jesse, that helps.

                          Regarding closing the position at a certain time. How would I do that? Let's say I want to close the position at 8AM, is that possible as a condition in a set? And if so, what would it be?

                          Comment


                            #14
                            My guess would be you would need two at least two conditions depending on how complicated you wanted it.
                            if Times[DefaultInput][0].TimeOfDay >= new TimeSpan (8,00)
                            and if Position.MarketPosition.Long
                            then ExitLong

                            You would need another one for shorts.
                            The logic being that it's checking to see if it is equal to or after 8:00am and if you are in a long, exit the long.
                            If it is equal to or after 8:00 and you are in a short, exit short.

                            Comment


                              #15
                              Hello sclay115,

                              What rockmanx00 said is correct, you would need two additional sets and conditions like the ones they posted checking your exit condition in addition to the position, then submit an exit order for that position.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              116 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              61 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              40 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              43 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              82 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X