Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit On Close with Multi Time Frame Strategy

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

    Exit On Close with Multi Time Frame Strategy

    Hello,

    I oberserved strange executions in the strategy analyzer when I use a MTF strategy with unmanaged orders. If the orders are placed in the secondary time frame, the entry order is executed on the bar of the next day and the exit order is executed immediately. The entry and exit times in the Trades tab show an exit time before the entry time.

    Attached is a sample strategy I used to pinpoint the problem, it is just the plain order logic, anything else removed.

    changing line 82 to "private int OrderBars = 0;" shows the correct result.
    Attached Files

    #2
    Hello mithnadril,
    To assist you further can you post a screenshot depicting the scenario you are facing.

    Also in your sample code you are submitting the orders on the primary bar series only and not in the secondary series.

    I look forward to assisting you further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      oops... the line 82 should read private int OrderBars =1 ... this change was from my own testing, the actual version is attached.

      The screen shows the trades tab ordered using the exit name. The date format ist german, Day . Month . Year, Ths sample uses FDAX data with default session template.

      the screenshot was made with start Jan 1, 2012, Data Series 5 minutes
      Attached Files

      Comment


        #4
        Hello mithnadril,
        In backtesting orders are submitted at the end of the bar. If you submit the order in the last bar of the session then orders get executed on the next day. However in a multi series environment the Exit on close is triggered on the primary bar only and as such you will have a scenario like this.

        Please further custom code your strategy and please make sure you are not submitting any entry order at the last bar of session.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Joydeep View Post
          Hello mithnadril,
          In backtesting ... in a multi series environment the Exit on close is triggered on the primary bar only.
          That would explain the strange behavior I'm seeing. Using only day-session bars, I have 60 minute bars and 1 minute bars. It doesn't seem to matter how I set "Exit on close seconds", my position always exits on the first bar of the next day. I expected the internal logic to use whatever finest granularity is available to the strategy to determine when to exit on close.

          I guess I need to use GetNextBeginEnd to calculate when the strategy is 1 bar from the last bar of the session, and send an exit order for any open position at that time.

          -Alex

          Comment


            #6
            Hello Alex,
            You can also use LastBarOfSession to check it.

            Code:
            BarsArray[0].LastBarOfSession
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Joydeep
              You can also use LastBarOfSession to check it
              Good point, but if the strategy uses CalculateOnBarClose=true, by the time LastBarOfSession=true, it's too late.
              -Alex

              Comment


                #8
                Hello Alex,
                Yes, true. In such scenario you have to custom code it further using the GetNextBeginEnd method.
                JoydeepNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by tsantospinto, 04-12-2024, 07:04 PM
                5 responses
                67 views
                0 likes
                Last Post tsantospinto  
                Started by cre8able, Today, 03:20 PM
                0 responses
                6 views
                0 likes
                Last Post cre8able  
                Started by Fran888, 02-16-2024, 10:48 AM
                3 responses
                49 views
                0 likes
                Last Post Sam2515
                by Sam2515
                 
                Started by martin70, 03-24-2023, 04:58 AM
                15 responses
                115 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by The_Sec, Today, 02:29 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X