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

Sellstop order gets filled state before it's filled in Backtest

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

    Sellstop order gets filled state before it's filled in Backtest

    I'm breaking my head over this. Can't figure out what's going on. To illustrate the problem I've create a simple MA-crossover strategy.

    The problem: SellStop, stoploss and profit orders get the filled state, right after submission of the initial Sellstop order. I'm running this in a backtest on a 2000 tickchart.

    I've added DownArrows to clarify my problem.

    Any help is appreciated
    Attached Files

    #2
    Hello erikjan,

    The entry is placed after a bar closes (meaning if this were to fill immediately it would show on the bar after the currently closed bar that triggered the order. Once the entry fills OnExecution is triggered (before the bar closes) and places a ExitShortStop 1 tick above the high of the most recently closed bar. If the previous bars high plus 1 tick is within the High and Low of the currently building bar the order fills on the current bar.

    What is the behavior you want to happen?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'd expect my order to get filled on the bar after the red down arrow:

      short_scalp = EnterShortStop(1, Low[0]-1*TickSize, "f2el_scalp");

      This is sellstop on one tick below the current bar. It can only be triggered once that is touched. I'd expect the orange arrow to appear after the red one, not on the same bar.

      I'm trying to build a tick-by-tick auto breakeven system. This is just an simple example of the problem I'm having.

      Comment


        #4
        Hello erikjan,

        In that case, do not submit the order in OnExecution as this would fill if it is within the high and low of the bar it was triggered on.

        Instead, submit the order on the next bar in OnBarUpdate. Then the order will show on the next bar as it won't be submitted until the trigger bar closes.

        For more accurate fills, add intra-bar granularity of 1 tick.
        (This would not guarantee the order would be on the next bar but would ensure that the order would only fill if a tick price is a valid price after the order is submitted (the way this would work in real-time), instead of using the high and low of the bar)
        Last edited by NinjaTrader_ChelseaB; 07-27-2016, 09:41 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks. So is this a backtest quirk only then?

          Comment


            #6
            Hello erikjan,

            No, if you place an order and the order fills before the bar closes, it would still appear on the same bar even in real-time.
            If you place an order after a bar has closed, it will appear on the next bar (since its submission time is after the time the trigger bar closed).
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              The 'filled' status means the sellstop was hit, and I'm short, right? I don't see the stop price was hit on that bar. It was hit on the next bar. I'm still confused ;p

              Comment


                #8
                Hello erikjan,

                I am only able to view the chart that you have posted.

                The chart shows that f2el_scalp a sell stop order was placed after the 12:35 bar closed. This code is in OnBarUpdate and places the order after the trigger bar had closed. This entered the market into a short position.
                Immediately after entering the short position, just after the next bar opened (I am not able to see a time stamp on the bar so I'm not sure of the time of the bar that comes after 12:36) and while it was still open, two buy orders were placed. 'f2el scalp stop' as a buy stop market and 'f2el scalp target' as a buy limit.
                The 'f2el scalp target' then filled as its price was between the high and the low of the bar it was submitted on the opening of.

                I think I am not quite understanding what the incorrect behavior is.

                From your first post, you mention "SellStop, stoploss and profit orders get the filled state, right after submission of the initial Sellstop order".
                I understood this as you do not want the exit to fill on the same bar as the entry.

                In post #3 you mention "I'd expect my order to get filled on the bar after the red down arrow:". If you are talking about the "f2el_scalp" order, that is what is happened. The entry order is filled on the bar after the red down arrow. Am I not understanding this correctly?

                When you mention "This is sellstop on one tick below the current bar. It can only be triggered once that is touched. I'd expect the orange arrow to appear after the red one, not on the same bar.", this is where I am starting to get confused. Are you talking about the entry order or the exit order.
                The 'f2el scalp target' is being filled on the same bar as the entry because its being placed when the bar opens (as the entry order fills just after the previous bar closes). The price of the order is within the bar, so the order fills.

                In real-time, the exact same thing can happen. If an order is submitted at the beginning of the bar in OnExecution, and a valid price is hit while the bar is forming, that order will fill on the same bar it was submitted on.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Rapine Heihei, Today, 08:19 PM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by Rapine Heihei, Today, 08:25 PM
                0 responses
                4 views
                0 likes
                Last Post Rapine Heihei  
                Started by f.saeidi, Today, 08:01 PM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by Rapine Heihei, Today, 07:51 PM
                0 responses
                6 views
                0 likes
                Last Post Rapine Heihei  
                Started by frslvr, 04-11-2024, 07:26 AM
                5 responses
                96 views
                1 like
                Last Post caryc123  
                Working...
                X