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

End of session

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

    End of session

    Hello,

    I would like to call ExitLongLimit() function 10 minutes before end of session.

    Is there any example for this?

    Sincerely,kobi

    #2
    Hello levikNT,

    Thank you for your note.

    You could use the following to exit through a market order x number of seconds before the close,


    If you wanted to submit a limit order however, you would have to run the strategy with calculate set to OnEachTick, so that you compare the current time to the session close time minus 10 minutes. If you did not want to run the strategy with calculate set to OnEachTick, you could submit your exit call within OnMarketData, however that would be more complicated.

    I do not have any samples of what you’re looking to do however I can provide the following sample which will add a certain amount of seconds to the time an entry order is filled, then in OnBarUpdate, if the bar time is greater than the current time, exit the trade. You could create a datetime object which is equal to 10 minutes before the close and modify the attached sample, which should do what you're looking to do.

    Please let us know if you need further assistance or if you’d like us to reach out with a list of third parties that would be interested in building this for you.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_AlanP View Post
      Hello levikNT,

      Thank you for your note.

      You could use the following to exit through a market order x number of seconds before the close,


      If you wanted to submit a limit order however, you would have to run the strategy with calculate set to OnEachTick, so that you compare the current time to the session close time minus 10 minutes. If you did not want to run the strategy with calculate set to OnEachTick, you could submit your exit call within OnMarketData, however that would be more complicated.

      I do not have any samples of what you’re looking to do however I can provide the following sample which will add a certain amount of seconds to the time an entry order is filled, then in OnBarUpdate, if the bar time is greater than the current time, exit the trade. You could create a datetime object which is equal to 10 minutes before the close and modify the attached sample, which should do what you're looking to do.

      Please let us know if you need further assistance or if you’d like us to reach out with a list of third parties that would be interested in building this for you.
      Hello Alan,

      What if the chart doesn't get any "ticks" few minutes before market closes, in this case - the only way to exit the market would be to use timer with custom event?

      Could you please show a sample how to use timer to properly exit let's say at 15:59:30 each day (even if the OnBarUpdate doesn't get triggered because of lack of ticks coming in)?

      Thanks

      Comment


        #4
        Hello music_p13,

        You could have the time checked in OnMarketData, which is triggered by any change in Bid/Ask or Last.

        I put together and attached a sample which allows the user to specify the close time, and upon starting the strategy a long position will be taken. After time has passed the user inputted time in the UI, the position will be closed.

        Whats nice about this sample is that you can run the strategy with Calculate On Bar Close, because the time if statement is in OnMarketData.

        Please see OnMarketData section of our helpguide,


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

        Comment


          #5
          Originally posted by NinjaTrader_AlanP View Post
          Hello music_p13,

          You could have the time checked in OnMarketData, which is triggered by any change in Bid/Ask or Last.

          I put together and attached a sample which allows the user to specify the close time, and upon starting the strategy a long position will be taken. After time has passed the user inputted time in the UI, the position will be closed.

          Whats nice about this sample is that you can run the strategy with Calculate On Bar Close, because the time if statement is in OnMarketData.

          Please see OnMarketData section of our helpguide,


          Please let us know if you need further assistance.
          Thanks, that is a nice alternative instead of using timer since there is a very high chance that bid/ask/last data will change even if no tick has occurred.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NRITV, Today, 01:15 PM
          2 responses
          9 views
          0 likes
          Last Post NRITV
          by NRITV
           
          Started by frankthearm, Today, 09:08 AM
          7 responses
          31 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by maybeimnotrader, Yesterday, 05:46 PM
          5 responses
          26 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by quantismo, Yesterday, 05:13 PM
          2 responses
          19 views
          0 likes
          Last Post quantismo  
          Started by adeelshahzad, Today, 03:54 AM
          5 responses
          33 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X