Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order on close

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

    Order on close

    Hello,
    I want to write a strategy that uses a 1440 minutes bars with session times 09:30 - 16:00 CT, and if a condition is met enters a position on bar close (meaning at 16:00, and not at the next bar open which will be 09:30). How do I do this?
    The documentation says that I'm suppose to use multi-time frames, but I don't understand how this helps me as I still need to set the session for 09:30 - 16:00 CT for the 1440 minutes time-frame and so it will also apply for the other time-frame and I still won't be able to use the data between 16:00 to 09:30 to enter at 16:00.

    Please explain precisely what do I need to do to write the strategy logic described.

    Thank you.

    #2
    Hello,

    This sounds like a tricky situation. Since the close of one bar occurs in the same instant as the open of the next bar, by the time the order is executed the time has already passed to the open of the next bar, even when an order is submitted at the close of the bar before -- there is not a buffer of time in between the two points.

    The best way to do this would be to add intra-bar granularity to your script, as you mentioned, and set up your strategy to enter just barely before the close of the bar, rather than at the exact point of the close.

    We have a comprehensive reference sample that will walk you through everything you will need to set this up in your code. The sample is heavily commented to describe every step of the process. You can view this sample at the link below:

    http://www.ninjatrader.com/support/f...ead.php?t=6652

    Now, if we're specifically talking about real-time fills, then there should not be a need to do this. For real-time fills to occur intra-bar, you can simply set CalculateOnBarClose = False in your code (and/or in the Strategies settings windows). This will cause the strategy to run its calculations on each incoming tick, rather than waiting for the close of the bar.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Hi Dave,
      I went over your answer and the sample, and I still do not see how to operate at the bar close. Specifically:
      1. You suggested that "The best way to do this would be to add intra-bar granularity to your script, as you mentioned, and set up your strategy to enter just barely before the close of the bar, rather than at the exact point of the close". However, the signal is given based on the close of the primary bar, which will not happen till 9:30 tomorrow. If there is no signal, how can I send an order just before the Close?
      2. The SampleIntrabarBacktest does not help, as the primary bar series is still an intraday bar.
      3. Even if there exists a way to close the primary bar near 16:00 rather than 9:30 tomorrow, the secondary bars will have to continue beyond the session template of 9:30-16:00, otherwise they too will start tomorrow.
      What am I missing here?
      Thanks

      Comment


        #4
        Hello,

        In that case, I'd say that the session template will need to be changed, in order to provide a bit more time between the close of the final bar in the session and the open of the next session. If you are receiving a signal at the last moment of the last bar in the session template, then the strategy will not have any bars data on which to submit the order after receiving the signal.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          How does changing the session template makes any difference? Any session I will put will still wait until the open of next bar to send the signal.
          Lets say I change the session to 09:30 - 16:05, since both the primary and secondary bars receive the same session, the intraday bar will still close its day at the same time as the 1440 bar (16:05) and it won't have a chance to do anything until 09:30.

          Am I missing something basic here?

          Comment


            #6
            I was assuming that you wanted the signal to trigger at 16:00 specifically, in which case adding an extra 5 minutes would give you the time to submit the order before the session template ends.

            If that's not the case, then you may have better luck using the Default 24/7 session template and just setting up a time filter in your code. This way, you will have all of the bars and data you need to submit orders right after the last bar of your trading day, but your code will stop the strategy from taking any further actions until 9:30 the next day.

            You can find more information on setting up time filters via the reference sample linked below:

            http://www.ninjatrader.com/support/f...ead.php?t=3226
            Dave I.NinjaTrader Product Management

            Comment


              #7
              You apparently do not understand what I want to do, so I'll try to be as clear as possible.

              I want to use a 1440 minute bar with the session template of 09:30-16:00. I need this bar specifically because I want to use its values (Open,High,Low,Close) and indicators using this specific bar setting to calculate an entry and exit signal. And I want that the orders I place (if I have a signal) will be executed at the close of this bar (16:00) and not at its open (09:30).

              If I use a 24 hours session I will not have the values (Open,High,Low,Close) of the 1440 minute bar and will not be able to use them for my entry or exit signal, but if I do use the 1440 minute bar with session template of 09:30-16:00, I have no way of placing the orders at 16:00, as the 1440 will be closed only at 09:30 (the next bar open), and the order will only be placed than.

              If I use a secondary bar I will still need to use the 09:30-16:00 session (again, because I need to use it to get the correct OHLC values for the 1440 minute bar), so the secondary bar will also won't see that the 1440 minute bar got a signal to place an order before 09:30.

              So my question is if there is a way for me to get the OHLC data for the period of 09:30-16:00 and be able to use indicators with that data while still being able to execute an order at 16:00?

              Please read my respond carefully, if there is something still unclear about what I want to do please ask me about it.

              Thank you.

              Comment


                #8
                Hello orenshkol,

                Thank you for your response.
                So my question is if there is a way for me to get the OHLC data for the period of 09:30-16:00 and be able to use indicators with that data while still being able to execute an order at 16:00?
                No, the Session Template would mean that the order would be submitted once the bar closes, that means when the next bar opens.

                You will remember we went over this a bit at the following link: http://www.ninjatrader.com/support/f...d.php?p=414078

                Please let me know if you have any questions.

                Comment


                  #9
                  And there is absolutely no way of bypassing this? somehow getting or constructing the OHLC data I need and still executing the order at the same day? For example using OHLC data of 09:30-16:00 (as one bar) and executing the order at 16:30.

                  Comment


                    #10
                    Hello orenshkol,

                    There would not be a means to work around the bar structure and how the indicators and strategies calculate on that data.

                    Comment


                      #11
                      I think edit your session template which is ending 16;00 now to 15;58 and add start session 15;59 and 16pm could give you some work around. I understand that will throw off your calculation a bit but will close your bar 1438m at least and will open another bar which allows to execute your strategy.
                      Problem with ninja time bars is the ninja uses a new tick of a new bar to close expired bar. I'm not saying it will work you'd need to try it.
                      With the missing 2 min. of a bar of a calculation, just add average of 2 min, you are missing from your bar of 1438 so you kind of have presumed 1440m bar.

                      Comment


                        #12
                        You can define more then one session template to a strategy? How?

                        Comment


                          #13
                          Hello orenshkol,

                          Thank you for your response.

                          This would not be possible. This will be featured in NinjaTrader 8 though.

                          Comment


                            #14
                            Will you be able to define for each time-frame in a multi time-frame strategy its own session template?

                            Comment


                              #15
                              Originally posted by orenshkol View Post
                              Will you be able to define for each time-frame in a multi time-frame strategy its own session template?
                              Yes, this will be possible.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              149 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post tkaboris  
                              Working...
                              X