Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with getting in too late

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

    Help with getting in too late

    Hi,

    I am a newbie in coding so please excuse me if this question is silly or very basic. I am writting a strategy but everytime I look on the back testing graph it gets in on the next bar rather than during the bar. I have unticked the box to calculate on bar close but all the entries are on the next open. The code is very simple and just says when the current high is above the previous 30 minutes high then enter long. How can I get it to enter during that minutes bar instead of entering on the next minutes open.

    Thanks for any help and advice!

    Freddy

    #2
    Hi Freddy,

    Thanks for the post and welcome to the NinjaTrader forums. Yes, this is expected in backtesting and any historical orders. A condition evaluates true, then order submitted to the next bar. CalculateOnBarClose will always be true historically / in a backtest.


    You can follow principles in this reference sample to backtest with an intrabar granularity.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your help, one more question please,

      When backtesting with limit orders, should limit longs be using the ask price and limit shorts the bid price? Also, when using the data series for these backtests, is it ok to use the last prices, or should separate tests be made with bids and asks?

      Thanks!

      Freddy

      Comment


        #4
        Backtesting does not look at bid / ask data. These are real time values only.

        Some providers do provide historical data built with bid / ask data and this is the option you're seeing there. It doesn't change how limit orders are filled, but the actual data used to construct the bars. Last is the typical record of transactions most people expect when viewing chart bars and is generally good to use when backtesting.

        For filling on limit orders, there are two built in choices you can select (Historical Fill Processing)

        The two system fill algorithms are:
        Default
        An algorithm that takes a conservative and more realistic approach to filling limit and stop limit orders.
        • Limit orders only fill if the limit price was penetrated
        • Limit orders are always filled at the limit price specified never better (for example, if a limit order is submitted on bar n, NinjaTrader will check if the order is filled on bar n+1, if this bar gaps down and the limit order was a buy, the order would be filled at the limit price and NOT the high of bar n+1)

        Liberal
        An algorithm that takes a liberal approach to filling limit and stop limit orders.
        • Limit orders fill if the limit price was touched
        • On gap down bars, buy limit orders will fill at the high of the gap down bar
        • On gap up bars, sell limit orders will fill at the low of the gap up bar
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          OK, that clears things up about the bid/ask. I was also wondering about making Donchian Channels for fixed periods of time in the day, i.e. instead of a rolling 10 minute Donchian Channel, how would one make a Donchian Channel that takes the high/low of 9:30-9:39,9:40-9:49, etc?

          Thanks!

          Comment


            #6
            This is possible with custom coding. For a start, see this reference sample on getting the highest highs and lowest lows from a specified time range:
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Thanks!

              I have just purchased subscription to Kinetick but having some problems. Firstly how can i add the NYSE and AMEX list to be able to download as have payed for this. Secondly when trying to download tick data for 2 months it sometimes only gives 1 weeks worth of data when on the site it claims you should have up to 120 days. Is this an isssue to contact them directly with or can you help?

              Thanks

              Freddy

              Comment


                #8
                Kinetick provides access to the data, but there's unfortunately not a list provided of all stocks.

                The easiest way to add stocks that you don't have already is just type the ticker + enter from an existing chart. If it doesn't already exist, NinjaTrader will create in instrument manager. You may also want to view this thread for user contributed stock lists:


                The amount of historical data available is limited during market hours. To view the full 120 days, request data after 4:30 PM eastern.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks that solves that!



                  When I open the reference sampling i am not sure how to apply them, could you please tell me if i should copy paste into the strategy i already have or a help guide how to apply it as i am completely lost,

                  Thanks

                  freddy

                  Comment


                    #10
                    First, save the .zip file to your computer. Then import using using File > Utilities > Import NinjaScript.

                    Once imported, you can view and edit the source code using Tools > Edit NinjaScript > indicator / strategy.

                    If you want to keep the sample source code in-tact but make your own modifications, save a copy by right clicking in the editor > Save as to provide a new name.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks, i can get to the stage of opening it up in the editor but i dont understand how i can combine it with a strategy that i already have. If i have a strategy and want to add the code of being able to submit orders with an intrabar granularity how can i combine my strategy with the source code of this.

                      Thanks for all your help.

                      Freddy

                      Comment


                        #12
                        The samples are designed to show concepts, and then you can integrate those concepts into your own custom strategy. You can copy-paste certain parts and integrate into your strategy once you understand the function of everything. They're not necessarily designed as plug and play solutions.

                        If you are looking for a professionally developed custom code solution, please consider explaining your requirements to one of our 3rd party NinjaScript consultant:
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          ok i understand, one more question (for now...), when you back test is it possible to see a graph of the combined results as profit and loss?

                          Thanks

                          Freddy

                          Comment


                            #14
                            You can graph cumulative profit using the graph tab after running a backtest.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              yes i understand this for when you have individual stocks but if you have backtested 10 and want them all together in one graph is this possible?

                              Freddy

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              65 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              41 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              23 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              26 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              52 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X