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

Time based entry and exit

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

    Time based entry and exit

    Hi,

    I am coding a strategy to enter long when it is 9AM and exit at 11AM.
    What is the right way to do this?
    I tried this code below, but in strategy backtest, it did not generate trades on 5 min bar.
    Thanks


    if ((ToTime(Time[0]) > 90000)
    && (ToTime(Time[0]) < 110000)
    && Position.MarketPosition == MarketPosition.Flat)
    {

    EnterLong(DefaultQuantity, "Long");
    }


    if (ToTime(Time[0]) >= 110000
    && ToTime(Time[0]) <= 90000
    && Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong("ExitLong", "Long");
    }

    #2
    Ninjatrader support, any take on this? Thanks

    Comment


      #3
      ssg10,
      Thank you for getting in touch with us regarding this, and I apologize about the delay..
      Please check to see if your strategy is appearing yellow within the strategies tab. A Yellow highlighted "Strategy" cell indicates the strategy is waiting to be flat before submitting any live orders. The strategy has virtual historical orders that must be flat before it will place an order. A work around for this is to go to Tools -> Options -> Strategies -> NinjaScript and change the setting for "On starting a real-time strategy" to "immediately submit live working historical orders. I would like to note that it is important to understand that the position of the strategy in the strategies tab may not reflect the accounts actual position that is reported in the Accounts tab. Please see the following link on these settings. http://www.ninjatrader.com/support/h...tegies_tab.htm

      Making this change and restarting the strategy will have you enter a long position immediately (time and position qualifications withstanding.)
      The second issue deals with your exit times used on the second portion of the code. It is impossible for the time to be BOTH after 11:00 AM and before 9:00 AM. To correct this, change the "&&" to a "||" . (This will change from an AND to an OR condition.)
      Please let us know if we can assist you further.
      Matt L.NinjaTrader Customer Service

      Comment


        #4
        Thanks.
        The first suggestion helped.

        If I need to add a calculation for the bars before the entry condition, the highest price minus the lowest price of time range 6AM to 8AM before the entry condition at 9AM --- How can I do that?

        Comment


          #5
          Hello,
          Thank you for getting back to us.

          I have enclosed a reference sample that you can use as a guide to accomplish your objectives.
          http://ninjatrader.com/support/forum/showthread.php?t=8600

          Please let us know if we can be of further assistance.
          Matt L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by junkone, Today, 11:37 AM
          2 responses
          14 views
          0 likes
          Last Post junkone
          by junkone
           
          Started by frankthearm, Yesterday, 09:08 AM
          12 responses
          44 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by quantismo, 04-17-2024, 05:13 PM
          5 responses
          35 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by proptrade13, Today, 11:06 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          35 views
          0 likes
          Last Post love2code2trade  
          Working...
          X