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

Buy limit order is not filled

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

    Buy limit order is not filled

    Hi,

    I try to submit a buy limit order at market on close and valid for the next day. The backtest is executed based on daily bars. I also add a 1 minute timeframe to have intraday granularity. But the buy limit order is ignored and I don't understand why. According to the high/low values of the concerning trading day, it should got filled, I guess.

    Here is the code:

    protectedoverridevoid Initialize()
    {
    Add(PeriodType.Minute, 1);
    CalculateOnBarClose = true;
    TraceOrders = true;
    }

    protectedoverridevoid OnBarUpdate()
    {
    if (BarsInProgress == 0)
    {
    Print("Time: " + Time[0].ToString());
    Print("High: " + High[0].ToString());
    Print("Low: " + Low[0].ToString());
    if (Close[0] > Close[1] && counter == 0)
    {
    EnterLongLimit(1, true, 1, Low[0] - 10 * TickSize, "Buy limit");
    counter = 1;
    }
    }
    }

    Here is the log:

    Time: 19.09.2007 00:00:00
    High: 1,6559
    Low: 1,6492

    19.09.2007 00:00:00 Entered internal PlaceOrder() method at 19.09.2007 00:00:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1,6491 StopPrice=0 SignalName='Buy limit' FromEntrySignal=''

    20.09.2007 00:00:00 Cancelled order due to end of session handling: BarsInProgress=1: Order='NT-00000/Back101' Name='Buy limit' State=Working Instrument='$EURCHF' Action=Buy Limit price=1,6491 Stop price=0 Quantity=1 Strategy='gtctest' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='e598d36379a94519a6370639446fdcee' Gtd='01.12.2099 00:00:00'

    Time: 20.09.2007 00:00:00
    High: 1,6534
    Low: 1,6444


    Regards
    Ralph

    #2
    I suspect "Exit on close" parameter is set to true, can you set this to false.
    RayNinjaTrader Customer Service

    Comment


      #3
      OK, I added this: ExitOnClose = false;

      But the behaviour is the same. From the log I got the impression, that the order was activ at the 20.09.2007 as desired but not executed and cancelled at the end of that day.

      Regards
      Ralph

      Comment


        #4
        When you run the strategy, do you set the Time In Force to GTC?
        RayNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Ray View Post
          When you run the strategy, do you set the Time In Force to GTC?
          Yes, I do.

          Comment


            #6
            Just checked our code and the line "Cancellled order due to end of session handling..." would trigger on the last bar of a session AND either

            - DAY TIF is used
            - Exit on close is set to true

            I can see in the trace ouput you posted that TIF is in fact GTC which means that Exit on close is set to true. Although you set this programatically, please ensure that when running the strategy, this paramter is in fact set to false.
            RayNinjaTrader Customer Service

            Comment


              #7
              Hi Ray,

              thanks for the explanation. No matter if I set TIF to DAY or GTC, the trace report always states, that the limit order is cancelled at 20.09.07 EOD. And the problem is, I don't expect this cancelation, but I do expect to see the order is getting filled.
              The range of the day 20.09.07 is High: 1,6534 Low: 1,6444 and the buy limit is 1,6491 that's in between the range. But the order wasn't filled.

              Regards
              Ralph

              Comment


                #8
                The TIF is not the problem --> Please set Exit on close in the strategy dialog to a value of false.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Hi Ray,

                  understand now what you mean, because I had a look into the Stratagy Analyser Documentation. However, the field "Exit on close" doesn't show up in the dialog window (only "Entries per direction" and "Entry handling").
                  I use the simulated version of NT 6.5.1000.5.

                  ???

                  Regards
                  Ralph

                  Comment


                    #10
                    Could you paste in an image of the Strategy dialog screen you see?
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Ray,

                      the dialog box is attached. When starting NT and open the dialog box first time, I can see the "Exit on close" entry. After executing the backtest and recalling the dialog box again, the statement is gone.

                      Regards
                      Ralph
                      Attached Files

                      Comment


                        #12
                        Thanks. I see the problem now. ExitOnClose disappears on Daily Bars, this is expected. However, since you have additional intraday bar, this is causing the Exit on close to be handled.

                        Do this, in OnBarUpdate() code something like:

                        if (CurrentBar == 0)
                        ExitOnClose = false;

                        and retry and see if this resolves this issue.
                        RayNinjaTrader Customer Service

                        Comment


                          #13
                          Hi Ray,

                          the behaviour is changing now. (see log below).

                          - The 19.09.07 is the first bar processed (Min. bars required = 8) and as you can see, ExitOnClose is set to false at this bar.
                          - On the same day the buy limit order is issued correctly (as before).
                          - The cancelation on 20.09.07 doesn't occure anymore (because of ExitOnClose=false).
                          - Looking at the chart window the buy limit order is filled on 21.09.07. That is one day to late, should have happen one day earlier. The fill is displayed only on the chart, but is not logged into the output window.

                          Conclusion: The order execution isn't scheduled correctly and the execution confirmation is missing in the output window.

                          Here is the actual log:


                          Time: 19.09.2007 00:00:00
                          ExitOnClose: False
                          19.09.2007 00:00:00 BarsInProgress==0 CurrentBar: 8
                          Time: 19.09.2007 00:00:00
                          High: 1,6559
                          Low: 1,6492
                          19.09.2007 00:00:00 Entered internal PlaceOrder() method at 19.09.2007 00:00:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1,6491 StopPrice=0 SignalName='Buy limit' FromEntrySignal=''

                          20.09.2007 00:00:00 BarsInProgress==0 CurrentBar: 9
                          Time: 20.09.2007 00:00:00
                          High: 1,6534
                          Low: 1,6444

                          21.09.2007 00:00:00 BarsInProgress==0 CurrentBar: 10
                          Time: 21.09.2007 00:00:00
                          High: 1,6537
                          Low: 1,6483

                          24.09.2007 00:00:00 BarsInProgress==0 CurrentBar: 11
                          ...

                          Comment


                            #14
                            What is the source for your daily data?
                            RayNinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Ray View Post
                              What is the source for your daily data?
                              Right, forgot to mention that: It is a 1 year history for EUR/CHF. I imported a 1-day data series and 1-minute data series. Source is IB.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DayTradingDEMON, Today, 09:28 AM
                              2 responses
                              15 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by Stanfillirenfro, Today, 07:23 AM
                              8 responses
                              23 views
                              0 likes
                              Last Post Stanfillirenfro  
                              Started by navyguy06, Today, 09:28 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              8 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by helpwanted, Today, 03:06 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Working...
                              X