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

signal on session close & exit on close = true trade on next session open

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

    signal on session close & exit on close = true trade on next session open

    Hello Ninjatraders,

    I have a strategy that trades 60 min bars and exits on session close. When a signal is generated with a sessions last 60 min candle, no trade occurs on the open of the next days session. Can NT enter a trade on the open of the next days 60 min candle while keeping exit on close true.

    Thanks in advance,

    Marco

    #2
    Hello Marco,

    Yes, to make a trade in the first 60 minutes on a 60 minute chart, you need to either run the strategy with Calculate on bar close set to False or add a secondary series to your script with a smaller timeframe.

    http://ninjatrader.com/support/helpG...onbarclose.htm

    The Exit on close will not affect this.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB,

      Thanks for your quick reply but I think higher granularity or CalculateOnBarClose=false will not address this. I will try to better explain what I meant.

      My code generates signals on 60 min bars with CalculateOnBarClose=true. I trade regular trading hours and if a signal occurs during a session my entries happen as intended with entry price at the open of the next 60 min bar. When an entry signal is generated with the last bar of a session the entry price is of course the next day's first bar. This is a problem since when I set Exit on close = true in the strategy properties (to exclude overnight exposure) trades from those signals do not occur. If I set it to false the trades occur as expected on the next bar (first bar of next session).

      My intuition is that NT generates the signal which is then canceled by the exit on close before the execution occurs the next day bar open.

      If I set CalculateOnBarClose to false I would get a completely different behavior. Since I have developed this strategy for 60 min intervals I don't want to use indicator values on a tick basis. 1-minute bars would not do the trick either.

      Thanks

      Marco

      Comment


        #4
        Hi Marco,

        When you mention "When an entry signal is generated with the last bar of a session the entry price is of course the next day's first bar. " this is somewhat not correct.

        The first tick of the session will close the the previous sessions bar and will open the new bar... However, the last bar of the previous session does not count as the first bar of the current session. There is a break a new bar does form.

        This means that you've got a new bar that is no longer associated with the previous session or the exit on close bar.

        In this first bar, you can submit any orders you want after that bar closes or even while it is still forming.

        However, that said, if you have a Calculate on bar close set to True, your first trade will occur when the first bar of the session closes as long as the conditions are true for that bar to enter at that time.


        Here is where I think you are experiencing confusion. You place a trade after the first bar closes and it shows up on the second bar. This is expected.

        When NinjaTrader is running with Calculate on bar close (COBC) as true, orders are placed after the bar closes using logic calculated from that bar.

        Below is a link to the help guide on Calculate on bar close.
        http://www.ninjatrader.com/support/h...onbarclose.htm

        This means that any orders that are triggered from that bar are submitted after the bar closes as the new bar opens. As the order is placed as the new bar opens and the timestamp of the order is within the time of the next bar, the order will show on the next bar.

        If the strategy were running with COBC as false, or if the script has intra-bar granularity and submitted orders on a smaller timeframe, this would cause the timestamp of the order to be within the bar it is triggered on as the order may be submitted intra-bar. This order would show on the same bar as the bar that triggered the order submission.

        This is outlined in the help guide Discrepancies: Real-Time vs Backtest.



        In other words, if you strategy is set to Calculate on bar close True and you place an order after the first bar closes then it shows on the second bar because it is included with that bars time (since it was submitted after the first bar closed it cannot be included with the first bar).

        Let me know if I am not understanding the issue.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your long response. Maybee I don't see the point but here is what I mean with the SampleMAcorssoverStrategy running on SPY 60 min with exit on close = true in strategy settings.

          You see a long trade on the SMA crossover from the 18.30 candle on 05/28. Price is next candle open. Now look at the short crossover on the next day: No trade happens. How can I make it trade while keeping Exit on close = true?
          Attached Files

          Comment


            #6
            Hello marcoheimann,

            In the screenshot it looks like the last bar of the session is what you are pointing out.

            Just to confirm, you want to be able to place an order on the last bar of the session with exit on close set to false?

            Also, I just want to confirm you are not talking about placing a trade at the open of the new session and instead you are trying to place a trade seconds before the session closes?

            No, if you have Calculate on bar close set to True and Exit on close set to True, then you will not be able to place a trade on the last bar of the session. You can place a trade on the first bar of the next session, but you cannot submit an order on the last bar of the session. The Exit on close will prevent this.

            It is possible to submit a trade just before the session closes after the exit on close has triggered and closed the position. It does require that your script run with Calculate on bar close set to False or a secondary tick series.

            Basically, if the exit on close is 30 seconds, submit the order 20 seconds before the session closes.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              ChealseaB,

              The SampleMAcrossoverStrategy comes with NT and it places long trades when SMA(10) crosses above the SMA(25) (see the first trade on screenshot). I point to the SMA(10) crossing below the SMA(25) which should result in a short trade. I think no trade occurs because the cross happens on the last candle of the session and exit on close is set to true (when I set it to false the trade occurs). I would like this trade to occur while keeping exit on close true.

              If I understand you right I could exit trades 70 sec before close and submit orders to a 1 min series. However, this is not what I want since the trade would be executed right before the close while I need to enter on the opening of the session as it would be with exit on close set to false.

              Comment


                #8
                Hello marcoheimann,

                If you want to submit an order at the open of a session, add a secondary series of 1 tick and submit when the session opens, or run the script with Calculate on bar close.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Could you please provide me an example of how to do this with the SampleMAcrossoverStrategy?

                  Comment


                    #10
                    Hello marcoheimann,

                    I am responding on behalf of Chelsea who is not currently in the office. I can give you a basic example of what you are looking for but I would like to clarify beforehand. You want your strategy such that if an order would have been submitted on the last bar of the session, to instead be submitted on the first bar of the next session's open. Is this correct?

                    Thank you in advance.
                    Michael M.NinjaTrader Quality Assurance

                    Comment


                      #11
                      Hello MichaelM,

                      Thank you for your reply. Yes, I would like to see a trade generated by a signal of the last bar of session executed on the open price of the next session. Please look at the screenshot in post #5 to see an example of what I need. ChealseaB suggested using a smaller timeframe if this is of any help.

                      Best,

                      Marco

                      Comment


                        #12
                        Hello marcoheimann,

                        Thank you for your patience. I have attached a commented example based on what was discussed. To import this file, please navigate to File -> Utilities -> Import NinjaScript -> [locate the downloaded .zip file] -> OK

                        Please let me know if you have any questions or if I may be of further assistance.
                        Attached Files
                        Michael M.NinjaTrader Quality Assurance

                        Comment


                          #13
                          Thanks MichaleM!

                          This was almost what I needed and put me on the right track. Just in case this can help someone else: Your script trades after the first candle of the new session (first screenshot). If someone is trading 60 min intervals like me this would result in an execution price equal to the open of the second 60 min candle of the new session which is not what I need. To solve this I added a second TS (1 Tick) and access the 60 min SMA with the BarsArray[0] option. This way the execution happens 1 tick after the open (screenshot 2). In case someone need the code feel free to ask.

                          Marco
                          Attached Files

                          Comment


                            #14
                            Hello marcoheimann,

                            Thank you for the update. I am glad to hear the sample code was helpful. If you would like to post any code that you think would be beneficial to other users with similar requirements, please feel free to do so.

                            Please let me know if I may be of further assistance anytime.
                            Michael M.NinjaTrader Quality Assurance

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Brevo, Today, 01:45 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post Brevo
                            by Brevo
                             
                            Started by aussugardefender, Today, 01:07 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post aussugardefender  
                            Started by pvincent, 06-23-2022, 12:53 PM
                            14 responses
                            239 views
                            0 likes
                            Last Post Nyman
                            by Nyman
                             
                            Started by TraderG23, 12-08-2023, 07:56 AM
                            9 responses
                            384 views
                            1 like
                            Last Post Gavini
                            by Gavini
                             
                            Started by oviejo, Today, 12:28 AM
                            0 responses
                            6 views
                            0 likes
                            Last Post oviejo
                            by oviejo
                             
                            Working...
                            X