Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Prevent Strategy from Running During Specific Hours

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

    Prevent Strategy from Running During Specific Hours

    Hi there,

    I'm looking to run one of my strategies between Midnight and 10:00 AM, shut down, then run again after 5:00 PM. I'm struggling with the paramaters for this because there is no "or" option in the conditions and every time I try to set up groups, it only seems to recognize one set of instructions. Is there an easy way to do this in strategy builder?

    #2
    Hello koyunbaba, thanks for your question.

    There is an Or (||) option in the builder. On the top left of the set, there is a setting "If all" or "If any" If all acts as the AND and If any acts as the OR. To do this set the main set to "if any" and make two condition groups set to "if all". You would enter the two time constraints into those two groups.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply. I guess what I mean is that I'm struggling to combine the AND with the OR. So logically what I'm looking for is this:

      IF <Indicator condition> >= X
      AND (Current Bar Time of Day > 12:00 AND Current Bar Time of Day < 08:00)
      OR (Current Bar Time of Day > 17:00 AND Current Bar Time of Day <=23:59)

      The group function allows me to select an If Any operator, but then it doesn't truly filter the time - it only looks to the < or > to determine if the bar meets the criteria, which it always does.

      Comment


        #4
        Hi koyunbaba, thanks for your reply.

        Could you Export your script and post the .zip here so I can have a look at what you have so far?

        I look forward to assisting.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Koyunbaba,

          I am not a support representative from Ninja Trader but I would like to help you with your question.

          It looks like you are using the Strategy Builder and you want to be able to group conditions. It can be easily achieved, all you have to do is use the button "group" and play with it.

          Let's say that you want to build this condition:

          If (SMA(14) &gt;= EMA(14) OR (Close &gt; Open AND Time &gt; 9:30 AM))

          All you have to do in Conditions and Actions is at the upper left corner select "If Any" -which actually means OR- and configure the first part, which is "SMA(14) &gt;= EMA(14)", then you need to create a grouped condition, so you click the "group" button, between "add" and "edit" buttons at the bottom right corner of Conditions. Here you will choose "If All" -which means AND- and configure the other 2 conditions.

          To facilitate your understanding I included a picture that should give you a clue about how to do it, please check it out:

          http://prntscr.com/tm7sn6

          Comment


            #6
            See attached

            Comment


              #7
              Hi koyunbaba, thanks for posting that.

              I went ahead and made a working example that satisfies both of the time conditions. Please see attached. I removed your script in case you wanted to keep that private.

              Please let me know if I can assist any further.
              Attached Files
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                OK this makes sense. I've added the language to my strategy, but when I go to re-run the strategy analyzer, there's no change. I did compile (a couple of times, for good measure).

                Comment


                  #9
                  Hi koyunbaba, thanks for your reply.

                  Can you try selecting a different strategy, then selecting the test strategy again? This will make the OnStateChanged method run completely through.
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    Yeah I continue to get results outside of the parameters, even after a full restart of the application.

                    Comment


                      #11
                      Hello, thanks for your reply.

                      It's working fine in the strategy analyzer on my end:
                      https://clauber.tinytake.com/tt/NDQ4MTM2Nl8xNDE4ODY0NA

                      You might not have added what I made exactly, which could cause a problem.

                      Chris L.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by blar58, Today, 01:21 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post blar58
                      by blar58
                       
                      Started by tonynt, Today, 01:21 PM
                      0 responses
                      5 views
                      0 likes
                      Last Post tonynt
                      by tonynt
                       
                      Started by Byron22, Today, 12:19 PM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_PaulG  
                      Started by Trader17, Today, 12:25 PM
                      2 responses
                      8 views
                      0 likes
                      Last Post Trader17  
                      Started by focus333, Today, 10:48 AM
                      1 response
                      17 views
                      0 likes
                      Last Post NinjaTrader_Kate  
                      Working...
                      X