Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How does Limit order work in backtest?

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

    How does Limit order work in backtest?

    Hi,

    What is the difference between market order and limit order during backtest? .

    According to document of GetCurrentBid(), when accessed during a historical backtest, the close price of the evaluated bar is substituted.

    But If I replace EnterLongLimit() with EnterLong(), the back test on historical data is different.



    *****************************************
    Examples

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 20)
    return;

    // Only enter if at least 10 bars has passed since our last entry
    if (BarsSinceEntry() > 10 && CrossAbove(SMA(10), SMA(20), 1))
    EnterLongLimit(GetCurrentBid(), "SMA Cross Entry");
    }

    #2
    Hello,

    Thanks for the forum post and patience.

    This has to do in part with this information here on BackTest:



    Now this doesn't directly answer the question however I felt that it is important information none the less.

    As far as different results either EnterLong() (market) vs EnterLongLimit() (limit) by default market orders are always filled on the nextOpen whereas the Limit orders will fill at the limit price if NT can determan that the market action passed through it.

    -Brett

    Comment


      #3
      Brett,

      So it's very clear for how market oder is handled during backtest, but I am still not clear how limit order is treated.

      "..whereas the Limit orders will fill at the limit price if NT can determan that the market action passed through it" since we are talking about backtest, the only info we have is data bar(OHLC), could you clarify how NT handles it? I thought in backtest it is the same as market order, filled on the nextOpen.

      Thanks,

      Comment


        #4
        Basically if the nextOpen would fill it instead of just filling it at open it would fill at the limit price +/- your slippage you set for the backtest.

        -Brett

        Comment


          #5
          So, for backtest

          EnterLongLimit(GetCurrentBid(), "SMA Cross Entry");

          What exactly is the filling price of this entry?

          Thx,

          Comment


            #6
            Hello,

            It would be whatever it set in the first parameter for price. In this case you are using GetCurrentBid() which in historical pulls the current close.

            -Brett

            Comment


              #7
              Here is my understanding:

              market order EnterLong() will fill the entry at next bar opening price

              Limit order EnterLong(GetCurrentBid(), "") will fill the entry at current bar closing price.

              I see the difference if there is a gap between two bars.

              Am I right?

              Comment


                #8
                This is Correct.

                _Brett

                Comment


                  #9
                  Bret,

                  what can I do If I want to use Limit order but still want to fill at next bar opening price?

                  Comment


                    #10
                    Hello,

                    This would not be possible with our default fill type. You would have to modify how the fills in backest are done. This is possible however its not supported.

                    My Documents->NinjaTrader 7->bin->custom->type->defaultfilltype.cs

                    -Brett

                    Comment


                      #11
                      How about the ideal of modifying GetCurrentBid(), so that during backtest, it will take opening price of next bar instead of closing price of current bar? Is it possible?

                      Comment


                        #12
                        Hello,

                        I do not see any way to modify that unfortunately.

                        Curious why not just use Market Orders if you want that price. You could have a strategy for backtesting and then have a strategy for live if you wanted to use the limits live.

                        -Brett

                        Comment


                          #13
                          I want to have automatic system which needs backtest results to generate entry signal(limit order) in real time. For example like NT sample code "simpleMAcrossover".

                          It seems to me it makes more sense to have a limit order to fill at opening price of next bar during backtest. This is more close to real time trading. It is not always the case we can fill the order at current bar closing price, considering the gap between two bars, especially between current day's close and next day's opening.


                          *********************************
                          10.4.3.31 GetCurrentBid()
                          Definition
                          Returns the current bid price.
                          Method Return Value
                          A
                          double value representing the current bid price. Note: When accessed during a historical

                          backtest, the close price of the evaluated bar is substituted

                          Comment


                            #14
                            This would require a custom fill type as the NinjaTrader Default fill type does not allow this.

                            -Brett

                            Comment


                              #15
                              Get my own custom fill type done, Thanks.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by arvidvanstaey, Today, 02:19 PM
                              4 responses
                              11 views
                              0 likes
                              Last Post arvidvanstaey  
                              Started by samish18, 04-17-2024, 08:57 AM
                              16 responses
                              61 views
                              0 likes
                              Last Post samish18  
                              Started by jordanq2, Today, 03:10 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post jordanq2  
                              Started by traderqz, Today, 12:06 AM
                              10 responses
                              18 views
                              0 likes
                              Last Post traderqz  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              5 responses
                              48 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X