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

How to enter on the close of the bar?

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

    How to enter on the close of the bar?

    1) I want to enter at close of the bar, after the Ma crossover happens (or lets say, X_condition).

    It's a bit funny, but how I can execute enter at the close of the following(!) bar when such condition happens?

    2) i dont want to force strategy to execute orders only on open/close of daily bar, but on any price inside bar (like it could have done on real time daily. its called intra-bar order). for example, on daily chart backtest, if Z_condition happens, i want to enter 10 ticks above the open on the following bar - how to do that?

    #2
    Hello selnomeria,

    If an order is submitted after a bar is closed it will appear on the next bar.


    Are you asking how to add intra-bar granularity so that a intra-bar order placement and fills can be made?

    Below is a link to a forum thread where (at the bottom) I have discussed intra-bar granularity.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea_B,
      please please.

      has someone succeeded to execute trades on (or near) close of bar? can you give me any reference link? I cant succeed, even with adding 1 min timeframe (especially with Range/renko/etc charts).

      My clients asks me, that in BackTesting the trades executed on close of bar, and he is right, because in TradeStation, ThinkOrSwim, Amibroker and etc,, that can be done in backtesting..
      Last edited by ttodua; 09-11-2017, 07:48 AM.

      Comment


        #4
        Hello selnomeria,

        On other platforms, does the time of the bar represent when the bar opened or when the bar closed?

        In NinjaTrader the time of the bar represents when the bar closed.

        If the bar fully closes and simultaneously a new bar is opened, then the logic of the script is checked and an order is placed, that order would have actually been submitted on the new bar (right when it opened) and thus it appears on the new bar.

        If other platforms are showing this order on the trigger bar, and this was submitted after the bar closed, and the time of the bar is the close of the bar, then the other platforms are misrepresenting this information and it would not be accurate.

        Once the tick comes in that decides that bar is closed, that tick has already happened and it would be too late to generate any action before the bar has closed.

        For tick based bars, there is no way to know the bar will be closing until the tick is received that actually closes the bar.

        You can choose to add a 1 tick series to your script and trigger any actions while a bar is still open. Any orders submitted while a bar is still open would appear on that bar.
        For example if you were to submit an order on a 1 tick series at 9:59:59, this would appear on the 10:00 bar (being open from 9:59:00 to 10:00:00) and would not appear on the 10:01 bar.

        Adding a 1 minute series would allow for actions every minute. This may or may not be before a tick based bar such as renko or range would close as these are not based on time.

        For a tick based series, you would need to create custom logic that would tell the script when you predict the bar will close based on the tick information coming in. I am not aware of this logic being available on the forums.

        This thread will remain open for any community members that would like to create this logic as a convenience to you.

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
        Last edited by NinjaTrader_ChelseaB; 09-17-2017, 12:29 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          yes, now your answer was more helpful,

          1)
          Once the tick comes in that decides that bar is closed, that tick has already happened and it would be too late to generate any action before the bar has closed.
          - yes, i understand completely, and you are right, but :

          ......... then the other platforms are misrepresenting this information and it would not be accurate.
          - I dont fully agree with this, because it is backtesting, and if we were in live during all those moments, we had manually executed orders 1 minute before the daily bar was closed. so, in backtesting there should have been a parameter in code, allowing us to "simulate" (and maybe what you say "misrepresentation" ), because that "misrepresentation" could have been real, if we were live at that moment, because we would had executed trades 1 minute before daily close (and that is what we want - execution of orders near the CLOSE of daily bar) .

          You can choose to add a 1 tick (or 1 min) series
          - probably that could be the solution, thanks!

          I am not aware of this logic being available on the forums.
          - proabably i wanted this too!

          ------------
          So, I see that functionality will never be added in NT (even in future versions), but we have to do: use MarketReplay or Add 1 minute series.

          so, final question:

          Now, the only solution to achieve Trade before the close of Daily bar, we should have:
          Code:
          if (Time_prev < 15:58 and Time_curr>15:58) {
              MyOrder....
          }
          So, I have now two choice:
          use MarketReplay and backtest strategy there...

          OR

          Add 1 minute series in strategy and backtest diretly on regular chart....


          Am I right? Or i have to add 1 min series and in addition I have to backtest it in Marketreplay? (I ask this because I've seen that without adding 1min series, in MarketReplay, it is being executed like it was real-time, thus i thought that adding 1min series was not necessary. but please explain this subject, that is my last question, and i think, this subject should also be mentioned in this topic :
          You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


          because we dont know the difference between adding 1min series into regular chart and backtesting strtegies there, or backtesting strategies in MarketReplay.


          HUGE THANKS!
          Last edited by ttodua; 09-16-2017, 05:13 AM.

          Comment


            #6
            Hello selnomeria,

            If you are wanting to submit orders just before a bar closes, add 1 tick, or 1 second, or 5 second, or 1 minute, or 5 minute (some added series that will trigger before the bar closes), and submit the order when the time of the BIP 1 bar is a few seconds before the close of the next BIP 0 bar.

            With my response you have quoted, this is out of context. If the order is filled after the bar has closed and is being displayed on the trigger bar, then this would be misrepresented. That stipulation is the deciding factor: whether or not the bar has closed when the order is filled. If the order is filled before the close of the bar, then it would be displayed on that bar.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by selnomeria View Post
              yes, now your answer was more helpful,

              1)

              - yes, i understand completely, and you are right, but :


              - I dont fully agree with this, because it is backtesting, and if we were in live during all those moments, we had manually executed orders 1 minute before the daily bar was closed. so, in backtesting there should have been a parameter in code, allowing us to "simulate" (and maybe what you say "misrepresentation" ), because that "misrepresentation" could have been real, if we were live at that moment, because we would had executed trades 1 minute before daily close (and that is what we want - execution of orders near the CLOSE of daily bar) .


              - probably that could be the solution, thanks!


              - proabably i wanted this too!

              ------------
              So, I see that functionality will never be added in NT (even in future versions), but we have to do: use MarketReplay or Add 1 minute series.

              so, final question:

              Now, the only solution to achieve Trade before the close of Daily bar, we should have:
              Code:
              if (Time_prev < 15:58 and Time_curr>15:58) {
                  MyOrder....
              }
              So, I have now two choice:
              use MarketReplay and backtest strategy there...

              OR

              Add 1 minute series in strategy and backtest diretly on regular chart....


              Am I right? Or i have to add 1 min series and in addition I have to backtest it in Marketreplay? (I ask this because I've seen that without adding 1min series, in MarketReplay, it is being executed like it was real-time, thus i thought that adding 1min series was not necessary. but please explain this subject, that is my last question, and i think, this subject should also be mentioned in this topic :
              You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


              because we dont know the difference between adding 1min series into regular chart and backtesting strtegies there, or backtesting strategies in MarketReplay.


              HUGE THANKS!
              You are conflating different things. Market Replay is exactly that: a replay of the recorded market data, tick by tick, ALWAYS. That means that Market Replay is gated by the COBC setting. As the only data that can be processed by the Strategy Analyzer is the OHLC data, the Strategy Analyzer can only behave as if COBC is always true, so is not gated by the COBC setting.

              ref: http://ninjatrader.com/support/forum...13&postcount=5
              Last edited by koganam; 09-20-2017, 07:02 PM. Reason: Corrected capitalization.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by adeelshahzad, Today, 03:54 AM
              4 responses
              25 views
              0 likes
              Last Post adeelshahzad  
              Started by merzo, 06-25-2023, 02:19 AM
              10 responses
              823 views
              1 like
              Last Post NinjaTrader_ChristopherJ  
              Started by frankthearm, Today, 09:08 AM
              5 responses
              16 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              43 views
              0 likes
              Last Post jeronymite  
              Started by yertle, Today, 08:38 AM
              5 responses
              16 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X