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 a limit order at the opening of the next bar

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

    How to enter a limit order at the opening of the next bar

    Hello,

    How would I enter a limit order to buy at the opening price of the next bar on a range chart?

    This is how I am doing it in TradeStation with EasyLanguage:
    Buy ("Buy") Next Bar at open next bar limit;
    But I need to know how to do the same in NinjaTrader.

    Is this possible with NinjaTrader?

    #2
    TheEminiTrader, this would be possible if you submit the order at the open tick (FirstTickOfBar with CalculateOnBarClose = false) since then you would only know the open price of the next bar. You can only try submitting a limit order with a limit price of the close of the bar + - a tick for example, in most cases this should be close.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.

      I am stuck and looking to get the exact coding that I need to use in NinjaScript to accomplish the EasyLanguage statement:
      Code:
      Buy ("Buy") Next Bar at open next bar limit;
      I use this EasyLanguage code on Range bars and I need to do the same in NinjaTrader.

      Thank you in advance.


      Also, in NinjaTrader under "Tools" > "Options" > "Simulator" if I check the box for "enforce immediate fills" will I still need to set the "Delay comm" and Delay exchange" to 0?

      Does checking the box for "enforce immediate fills" override those two delay settings?

      Comment


        #4
        Correct enforcing 'immediate fills' should not have any delay then...please see my previous suggestion as to how to make your range bar order entry work in NinjaScript, since we treat the backtesting more conservative you could not place at the bar close for the next bar open limit, since this price is in reality not available at this point since technically when it is available you're past the open already, a workaround here would be trading on the tick after the open since then you would have the price needed.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thank you for your reply.

          So what you're saying is NinjaTrader is not able to do the same thing that TradeStation can do "Buy ("Buy") Next Bar at open next bar limit;"

          Comment


            #6
            Hello,

            Yes you can do this in NinjaTrader,

            In fact in backtesting and historical processing all orders run on the open price of the next bar as we feel this is a better more realistic fill price. So all you need to do is submit your EnterLong() or EnterLongLimit for example and fill processing takes place at the open price of the next bar.

            However in live you would be filled via market dynamics. As if you submit the order on bar close then it will naturally fill at the market price which is most likely the open price of the next bar.

            Let me know if I can be of further assistance.

            Comment


              #7
              Thank you for your reply.

              Since it is possible in NinjaTrader, can you give me the NinjaScript to "Buy ("Buy") Next Bar at open next bar limit;" for a range bar chart close of current bar is greater than a 10 period simple moving average.

              Thank you in advance.

              Comment


                #8
                Please note that I need that code to work the same in real time mode as it does in back test mode in a simulated account.

                Comment


                  #9
                  Hello TheEminiTrader,

                  You can't submit a limit order exactly at the open of the next bar, since it's not known at the time you submit the order. You can use the close price of the signal bar which will typically be near the open of the next bar.

                  EnterLongLimit(Close[0]);

                  NinjaScript provides you a lot of control, so if you need to make modifications to this order while the bar is in process you can do this. Even when COBC = true, you can get up to date prices using OnMarketData(), and make modifications to the order in OnOrderUpdate()

                  In order to see the strategy function similarly in backtest compared to real time, you should set CalculateOnBarClose = true. We do expect that there are discrepancies between a real time and a back test, as outlined here:
                  http://www.ninjatrader.com/support/h...ime_vs_bac.htm
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Backtest Restrictions with Strategy Analyzer

                    Originally posted by TheEminiTrader View Post
                    Please note that I need that code to work the same in real time mode as it does in back test mode in a simulated account.
                    You will encounter (2) problems when trying to backtest your strategy that to the best of my knowledge have existed since 2007 and are still not supported or solved in NinjaTrader 7:
                    1) OnMarketData does not get called when backtesting using the Strategy Analyzer
                    2) Tick data is never presented to OnBarUpdate when backtesting using the Strategy Analyzer no matter the setting of CalculateOnBarClose

                    These features work correctly for all other modes of strategy use, including Market Replay, Simulated execution or Live execution with real money.

                    However, it does make one's code much more complicated to work around these (2) issues (which are really just two aspects of the same, internal design limitation). To get this to give results that are anywhere close to what you would see with live data, one generally has to add an extra input datatseries - usually having a 1-tick-timeframe (or better: use 1-tick-Range bars for less memory use). And this is a real nuisance and adds huge complexity to a strategy.

                    The other factor one has to work around is that of trying to figure out how to do in BackTesting what would ordinarily best be found in OnMarketData. I'm not saying this cannot be done, I'm just saying that in my strategies I've had to have one version for backtesting and then a different one for use with live data (or run months of replay data through my live strategy which is slow at best.) And these approaches will perform somewhat differently, which somewhat defeats the purpose of having a Strategy Analyzer.

                    Ideally, the Strategy Analyzer should be changed so at least there's an option to process tick & OnMarketData, so backtesting a strategy will do the exact same thing that executing the strategy with a live datafeed and broker connection does.

                    It would probably be much slower than the current Strategy Analyzer, but I'd rather wait longer for a backtest than spend many days debugging the extra complexity that is otherwise required, and after all that end up with a result that isn't really the same.

                    I think this currently-required extra complexity translates into many neophyte users giving up on NinjaTrader for a live-trading platform. I, for one, am not about to "go live" on any strategy that I haven't been able to thoroughly backtest.

                    Comment


                      #11
                      Originally posted by TheEminiTrader View Post
                      Thank you for your reply.

                      Since it is possible in NinjaTrader, can you give me the NinjaScript to "Buy ("Buy") Next Bar at open next bar limit;" for a range bar chart close of current bar is greater than a 10 period simple moving average.

                      Thank you in advance.
                      Code:
                      if (Close[0] > SMA(Close, 10)[0]) BuyLongLimit(Close[0] + 1 * TickSize);
                      Last edited by koganam; 04-29-2011, 04:52 PM. Reason: Left out the "[0]" index marker

                      Comment


                        #12
                        Thank you for all your replies.

                        Comment


                          #13
                          Originally posted by KBJ View Post
                          Backtest Restrictions with Strategy Analyzer



                          You will encounter (2) problems when trying to backtest your strategy that to the best of my knowledge have existed since 2007 and are still not supported or solved in NinjaTrader 7:
                          1) OnMarketData does not get called when backtesting using the Strategy Analyzer
                          2) Tick data is never presented to OnBarUpdate when backtesting using the Strategy Analyzer no matter the setting of CalculateOnBarClose

                          These features work correctly for all other modes of strategy use, including Market Replay, Simulated execution or Live execution with real money.

                          However, it does make one's code much more complicated to work around these (2) issues (which are really just two aspects of the same, internal design limitation). To get this to give results that are anywhere close to what you would see with live data, one generally has to add an extra input datatseries - usually having a 1-tick-timeframe (or better: use 1-tick-Range bars for less memory use). And this is a real nuisance and adds huge complexity to a strategy.

                          The other factor one has to work around is that of trying to figure out how to do in BackTesting what would ordinarily best be found in OnMarketData. I'm not saying this cannot be done, I'm just saying that in my strategies I've had to have one version for backtesting and then a different one for use with live data (or run months of replay data through my live strategy which is slow at best.) And these approaches will perform somewhat differently, which somewhat defeats the purpose of having a Strategy Analyzer.

                          Ideally, the Strategy Analyzer should be changed so at least there's an option to process tick & OnMarketData, so backtesting a strategy will do the exact same thing that executing the strategy with a live datafeed and broker connection does.

                          It would probably be much slower than the current Strategy Analyzer, but I'd rather wait longer for a backtest than spend many days debugging the extra complexity that is otherwise required, and after all that end up with a result that isn't really the same.

                          I think this currently-required extra complexity translates into many neophyte users giving up on NinjaTrader for a live-trading platform. I, for one, am not about to "go live" on any strategy that I haven't been able to thoroughly backtest.
                          Yeah it is actually incredible how useless Strategy Analyzer and Strategy Performance is - you get such innacurate results whichever way you run testing - how is it possible to create and test a strategy through Ninjatrader 8 if you cant even get propper results?

                          Comment


                            #14
                            Hello TrendFollowingCapital,

                            Thanks for your post.

                            In NinjaTrader 8, there have been two new enhancements so that programmers do not have to manually add a secondary series and code the script to for high accuracy fills (Order Fill Resolution) and for intra-bar actions (Tick Replay).

                            Here is a link to our forums that goes into depth on using Order Fill Resolution and Tick Replay to ensure your backtests are as close to real time results as possible:

                            Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.


                            High Fill Order Resolution and TickReplay cannot be used together. If it is necessary to have both intra-bar fills and actions, it is still possible to add intra-bar granularity to a script in the code itself for order fill accuracy and use TickReplay to update indicators with Calculate set to OnPriceChange or OnEachTick historically.

                            I recommend testing with Tick Replay and possibly a 1 tick data series as well. You should see results significantly closer to what you'd see on live data.

                            Please let us know if we may be of further assistance to you.
                            Kate W.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by jclose, Today, 09:37 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post jclose
                            by jclose
                             
                            Started by WeyldFalcon, 08-07-2020, 06:13 AM
                            10 responses
                            1,413 views
                            0 likes
                            Last Post Traderontheroad  
                            Started by firefoxforum12, Today, 08:53 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post firefoxforum12  
                            Started by stafe, Today, 08:34 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post stafe
                            by stafe
                             
                            Started by sastrades, 01-31-2024, 10:19 PM
                            11 responses
                            169 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Working...
                            X