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

Entering too late

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

    Entering too late

    I programmed a strategy, which calculated on a bar close, if there should be entered a position or not. If so, it enters on the open of the next bar. When I'm backtesting the strategy, everything works without any problems. Now I tested the strategy in realtime. The problem here is, that the strategy doens't enter always on the open of the next bar, but later anywhere. This ruins my whole performance I had while backtesting it with historical data. Is it possible, that this is caused, because the computer needs too long to calculate, whether there is an order or not? I've set "Calculate on bar close" to true.
    Can you help me?

    Regards,

    Sepp

    #2
    Hi Sepp, correct in backtesting this is expected, the trade entry occurs on bar after the your conditions have evaluated to true.

    In realtime testing there can of course be differences as you're now dealing with live fills and dynamic bid / ask rows at your price points - which order types are you using in the strategy?

    Please also review this link here, it summarizes expected discrepancies when comparing backtests and realtime results - http://www.ninjatrader-support.com/H...sBacktest.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      That's the problem - I'm only using "EnterLong()". No Limit, nothing. So it should enter right when the new bar is opened. But why doesn't it do that?

      Sepp

      Comment


        #4
        You would also see the spread factored in, as with a market order you buy the 'ask' when entering long...please post a screenshot of the behavior you see.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Ok, you're right, I forgot about the spread. I guess this is it, because the entry price is always around 1 tick offset, which has to be the spread.
          I'm wondering, if there is a command to set an buy/sell order with the limit price at the level, on which the first contract of the new bar was traded. So, assuming, the close of the old bar was 9925 and first trade of the new bar sets the open to 9926, is there any possibility to enter a buy order at 9926? I hope, you could follow me.

          Regards,

          Sepp

          Comment


            #6
            Sure, just place a Limit order at this price level then - http://www.ninjatrader-support.com/H...LongLimit.html

            You would need to be aware that per default when you're in the wizard those orders would expire and the end of the bar, so either resubmit them on the next bar, or unlock the code and set those to 'liveUntilCancelled'.

            BertrandNinjaTrader Customer Service

            Comment


              #7
              No, I don't think you understand properly. Imagine it's the close of the current bar. Now I want to enter a position on the open of the next bar. The order gets submitted now, I don't know yet what the open price of the next bar will be. Is there now a possibility to set an limit order with price set to the first price traded in the new bar?
              I'm thinking of something like EnterLongLimit(FirstTickofnextbar). You know what I mean? I hope you could follow properly.

              Regards,

              Sepp

              Comment


                #8
                Sepp,

                NinjaTrader does not let you peak into the future. You will not be able to submit an order at a future price. You only have the price information available to you as of the instant in time of when you submitted your order.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Yes, I know that.
                  While looking through your online help, there is an example with EnterLongLimit(GetCurrentBid()). I was wondering if this also would go with something like EnterLongLimit(GetCurrentPrice()). Doing this on the close of an old bar would generate a new order with the price on the same level, which would (hopefully) be what I want. Is there anything like this?

                  Regards,

                  Sepp

                  Comment


                    #10
                    Sepp,

                    No. That is not how it works. Right as you submit the order, there is NO future prices. There is no, going forward to a different price. Once your code goes EnterLongLimit(), only the current price information is available. There is nothing going forward since your order is already submitted.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Ok, but what about the GetCurrentPrice? There is GetCurrentBid and GetCurrentAsk, but I didn't found any GetCurrentPrice? Or GetLastPrice? Is there anything like this?

                      Regards,

                      Sepp

                      Comment


                        #12
                        Close[0] is the current price. When you are running with CalculateOnBarClose = false, the close price of the a building bar is the last traded price of the instrument.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Hmm, I know, that NT can't look into the future regarding limit order prices, but I was thinking on something like that: at the close of this bar, the strategy checks, if a new position should be opened. If so, it "waits" until the first trade of the new bar was made. Then it sets a limit order at this first traded price. As a command, I thought of something like EnterLongLimit(FirstTickofBar), but it shall work with a strategy which sets "Calculate on bar close" to true. Is there anything like this? I don't think that this is something like looking in the future, because it sets the order at the first traded price, no matter how high it is. Is this possible?

                          Regards,

                          Sepp

                          Comment


                            #14
                            Just leave the strategy running with updating on each tick (CalculateOnBarClose set to false then) and place your trade entry conditions in

                            Code:
                             
                            if (FirstTickOfBar)
                            { 
                            do 'on bar close' calcs, taking into account to reference one bar back further
                            }
                            This will allow you to act on the opening tick of the new bar, of course only in realtime trading, as in backtesting the tick formation is not known.

                            Thus to simulate intrabar fills, this concept needs to be worked in -

                            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
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Thank you, I will try this tomorrow.
                              I now have two other questions:

                              1.) Today, there was a EnterLongLimit() order on, let's say, 9950, which should be filled during the next bar. Although the low (even the open) of the next bar was at 9951, the order got filled. Why did this happen? Why did the order get filled on a price other then the one, which I wanted?

                              2.) I've run the strategy both, realtime and backtesting. It worked very well, but there is one quite big problem. The profit target in the realtime version didn't get filled always, but only if the profit target was at the high/low of the next bar, where it got filled in the backtest. I've set both strategies (in realtime and historical) with the algorithm to true, which means, that the order gets filled, if the price touches the price of the order. Although this was in fact like this, the order didn't get filled at all. Do you have an explanation for this?

                              Regards,

                              Sepp

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X