Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Submitting StopOrders at SessionStart

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

    Submitting StopOrders at SessionStart

    Hello,

    I´m trading FX with IB. So the brokers tradingsession is 23:15-23:00 MEZ. For my strategy I´m using 10min charts with session 7:00-19:00. So I have to use CancelOrder() at SessionEnd for canceling StopOrders (Enter- or Exit-Stops) at 19:00 MEZ. I´m not using ExitonClose() because I´d like to hold positions overnight.

    How can I resubmit the StopOrders at 7:00 in the morning? OnBarUpdate() is first called at 7:10 if I understand right.

    Thanks a lot.

    Joerg

    #2
    You would need to have CalculateOnBarClose = false and process intrabar to get granularity close to where you want to submit at.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I see. Now I´m using CalculateOnBarClose = true and start my session just 1 bar earlier. The cancellation of my Stop-Orders (the first part of my code below) works fine but the resubmitting at the next morning (second part of my code) does not work. If I reinsert the strategy after SessionStart it submits the ExitStopOrders but if the Strategy war already running it does not. The Strategy is active also in this case because Mar****rders (not shown in the example code) are working. So the Strategy is behaving realtime in another way than in the backtest/recalculation of old bars.

      How can I get the ExitStopOrders submitted at the end of the first bar of the new session?

      Thanks a lot.


      Code:
       
      [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (ToTime(Time[-[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) >= ToTime(SessionEnd))[/SIZE][/FONT]
      [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (EntryPos != [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) CancelOrder(EntryPos);[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (ExitPos != [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) CancelOrder(ExitPos);[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]}[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]{[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ExitPos = ExitLongStop(StL, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Long Exit Stop"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
      [SIZE=2][FONT=Courier New]ExitPos = ExitShortStop(StL, [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Short Exit Stop"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
      [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
       
      [/SIZE][/FONT]

      Comment


        #4
        Hi there, there is a simple property that should help you out tremendously: SessionBreak.
        Code:
        if (SessionBreak) // this represents the first bar of the new session
        {
            // re-submit stop orders
        }
        AustinNinjaTrader Customer Service

        Comment


          #5
          Thanks for the reply. I tried it with the following code in the OnBarUpdate()-method but it does not resubmit the orders (also at the 2th or 3th bar of the new session).

          If I reinsert the strategy into the chart the same code works and imediately submits the StopOrder but it does not in live mode?

          During the SessionBreak I have to reopen TWS. Is this the problem?

          Code:
          if (Bars.SessionBreak)
                      {
                          ExitLongStop(StL);
                          ExitShortStop(StL);
                      }
          Last edited by Joerg; 12-30-2009, 04:42 AM.

          Comment


            #6
            Joerg, please set TraceOrders = true in the Initialize() section of code. The order tracing tool will inform you why the orders are not being resubmitted. If you want, you can read this post by Josh, which explains a bit about the tool.
            AustinNinjaTrader Customer Service

            Comment


              #7
              I´´ve tried the TraceOrder = true Option and got the following message for the ExitShortStop() Order which should habe been transmitted at the SessionBegin or at least after the first Bar.

              HTML Code:
              06.01.2010 07:10:00 Entered internal PlaceOrder() method at 06.01.2010 07:10:00: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1,6070 SignalName='' FromEntrySignal=''
              06.01.2010 07:10:00 Ignored PlaceOrder() method: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1,6070 SignalName=Buy to cover' FromEntrySignal='' Reason='There already is a matching, terminal exit order in place'
              But I don´t have an Order entered manually. The only thing I can image I´m using CancelOrder() for another Order on another underlying the everning before. Does this switch NT completely to "advanced order handling"? But also in this case I have to submit the order somehow.

              What can I do?


              Thanks a lot.

              Joerg

              Comment


                #8
                Joerg, you unfortunately run into a known bug resolved for NinjaTrader 7, which prevents you from cancelling an order and then replacing it later.

                Workaround would be to amend / change the stop as needed, thus not having to cancel and replace it.

                Comment


                  #9
                  Changing would be no problem but does NT finds this order after an restart of TWS/reinsert of strategy?

                  Or is there a way to get the OrderNo out of TWS back into NT then?

                  Comment


                    #10
                    Hi Joerg, I see - unfortunately then you would need work with NinjaTrader 7 and this type of strategy then.

                    Comment


                      #11
                      Hello,

                      I use this strategy in NT7 now and today I had another curious behaviour. NT7 submitted the stop order at SessionStart (like it should), this order was filled immediately but when I recalculate the strategy (via reentering it in the chart) this fill gets lost and it does this trade as market order at the end of the first bar (which I coded in the script as backup).

                      So there seems to be a difference between realtime behaviour and backtest when trading stops at SessionBegin? Realtime the stop is submitted (and executed) but in backtest it loses the fill.

                      Thanks,

                      Joerg

                      Comment


                        #12
                        Hello Joerg,

                        Yes there can be differences between running a strategy real time versus a back test. The link below can provide some reasons why:
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Ryan,

                          thanks for the link, it helped a little. Let me ask the question more detailed:

                          Is it true that OnBarUpdate() is called at the first incoming tick of a new session in NT7 which was not the case in NT6.5 and which is not the case in backtest?

                          Thanks,

                          Joerg

                          Comment


                            #14
                            Joerg, which CalculateOnBarClose setting are you using in realtime trading with it? In a backtest this would be defaulted to 'true' as the intrabar formation is not known, you could simulate more granular fills then with submitting to a finer tick series for example.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            649 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            370 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            109 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            574 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            576 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X