Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Strategy Builder for Time Limits

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

    Using Strategy Builder for Time Limits

    I want to build a strategy using the Strategy Builder to create a strategy, but I'm not sure how to set the trade time within the builder....

    I want to set restrictions for the time that trades will execute (from 7am to 1500 on an hourly chart).

    How would one do this?

    #2
    Hello devildriver6,

    Thank you for your note.

    To limit your strategy from taking positions outside of day time hours, i.e. trade only during primary session, you could add a time filter condition to your code. This could be done using the strategy wizard or written in the editor.

    I have provided a link to the strategy wizard youtube, bookmarked at 28:20 which goes into setting up a time filter. Note the links below are for NT7, however the same logic applies in NT8.



    Below is a reference example of Using a time filter to limit trading hours:


    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Perfect, thank you.

      One more unrelated question, if you'd be so kind to oblige.

      I want the exit to happen at a specific price based on an indicator, not on the close of a bar.
      How can one make that happen in the strategy builder?

      For instance, it price crosses above the 10ma, the nearest tick value above the 10ma is the exit price.

      How can I get this done?

      Comment


        #4
        Hello devildriver6,

        What you could do is build a condition which says, if your current position is long, then submit a ExitLongLimit at a price equal to say the SMA. I have attached a strategy which does this. With this approach, you have a limit order working at a level so the moment the price trades through it, you would exit the position.

        Please let us know if you need further assistance.
        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          I thought I followed the steps in the instructional video using the strategy builder in Nt8 to generate the allowed trade time logic:

          the code generated for 3 allowable trade window is the following and not actually hitting a true condition as it doesn't trade.

          && (Times[0][0].TimeOfDay < new TimeSpan(11, 30, 0))
          && (Times[0][0].TimeOfDay > new TimeSpan(15, 15, 0))
          && (Times[0][0].TimeOfDay < new TimeSpan(16, 10, 0))
          && (Times[0][0].TimeOfDay > new TimeSpan(3, 0, 0))
          && (Times[0][0].TimeOfDay < new TimeSpan(5, 0, 0)) ) )

          The sample trade time strategy mentioned above looks like this:

          if ((ToTime(Time[0]) >= 93000 && ToTime(Time[0]) < 120000) || (ToTime(Time[0]) >= 140000 && ToTime(Time[0]) < 154500))

          I could unlock and do it by hand but lie to use the builder for as much code as possible as it get's messy at time changing the unlocked code

          thank you

          glen



          Comment


            #6
            Hello demarcog,

            I think you want to be using groups. In the groups use 'If All', and in the outer conditions use 'If Any'.

            This would join the conditions within the groups with ands '&&', and will join the groups themselves with '||'.

            if group 1 or group 2 or group 3.


            This is discussed in the Strategy Builder 301 training video.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi ChelseaB,

              Thank you for the response and that is very helpful in understanding the structure of how the If all and If any.

              The functions generated were different then the sample code looks like it makes more sense using one method ToTImeI(Time[0]) where the code the strategy builder generated for me TimeSpan looks like it may not be doing the exact same function but I'm not sute.

              thank you

              glen

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              43 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              124 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              65 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              46 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X