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

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.

    Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Wizard.3:23 Strategy Wizard Overview7:...


    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 gravdigaz6, Today, 11:40 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by MarianApalaghiei, Today, 10:49 PM
              3 responses
              10 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by XXtrader, Today, 11:30 PM
              0 responses
              4 views
              0 likes
              Last Post XXtrader  
              Started by love2code2trade, Yesterday, 01:45 PM
              4 responses
              28 views
              0 likes
              Last Post love2code2trade  
              Started by funk10101, Today, 09:43 PM
              0 responses
              9 views
              0 likes
              Last Post funk10101  
              Working...
              X