Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StopLoss-weirdness

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

    StopLoss-weirdness

    Ellow panel,

    I am making good progress on writing my own strategy; I am currently in the final testing stages.

    My strategy uses 65-Renko bars and I automated entry, StopLoss, Breakeven and trail. I allow two long positions (called LLA1 and LLA2) to be open at the same time. I use a second timeframe of one Tick for finer granularity and my positions are opened on that one.
    I am backtesting (nothing goes live yet) and for testing purposes I switched TraceOrders on.

    I noticed that sometimes my initial StopLoss is not being registered during backtesting. This causes my long position to go far below the stoploss I set and only to be closed at the end of the trading day.

    See, for example screenshots 1 (chart) and 2 (output):

    • position LLA2 opened around 0529 AM, and my StopLoss (called 'InitialStopLLA2') was set at 172.025. As you can clearly see price went against me fairly quickly but I was not stopped out until around 0842 AM, Price had been below my SL for a lengthy period already. Can anyone please shed some light on how this is possible ??

    And, for screenshots 3 and 4:
    • a different LLA2 opened at 1950 PM, but my initial stopLoss was never sent to or accepted by the 'server', but my trail was, but did not get accepted. The reason stated is "Reason='SignalName does not have a matching FromEntrySignal to exit'". I don't get this either: I have hundreds of different LLA2's being opened and closed during the same backtest and they all react well to my SL/Trail/BE. What could be the problem here ??

    Both of these trades were during 'normal' trading times, so I do not think spread or lack of volume are the issue here.


    I am not very proficient in this backtesting-business and would like to find out if others have this problem (or similar ones) as well and how I can fix them. Or just give me a good reason not to be bothered by all this
    Attached Files

    #2
    Hello Spinn,

    The stop limit you are using has the same limit price as the stop price. This can cause your order to be skipped over.

    When the stop is touched at 172.025 the price quickly falls and the limit placed at 172.025 continues working at 172.025. It doesn't fill because the price was moving as the order became a limit. The order fills when price comes back up to 172.025.
    (A limit fills at the specified price or better and won't fill at a worse price.)

    Try setting the price of the limit a few ticks lower than the price of the stop and it will be more likely to get a fill.
    (Unless you want to make sure it only fills exactly at 172.025 in which case a situation like this could arise, in that it won't fill unless it can fill at exactly 172.025 due to the price of the limit).


    With the second issue, its a bit harder to tell.
    Are you making sure that the entry order is in a filled state before attempting to place the attached exit?
    If not this would violate the internal order handling rules.

    "Methods that generate orders to exit a position will be ignored if:
    A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction."
    http://ninjatrader.com/support/helpG...d_approach.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, NinjaTrader_ChelseaB, and hello again

      The first problem was indeed solved quickly by adjusting the Limit, so all is good there.

      For the second issue: I believe my code only allows for the initial stop to be set AFTER the entry is filled:

      Code:
      //Initial Stop on Open for LLA1
                  if (entryOrder50 != null && execution.Order == entryOrder50 && entryOrder50.OrderState == OrderState.Filled && !initialSetLLA1)    
                      {
                      stop50 = ExitLongStopLimit(1,true, DefaultQuantity, (entryOrder50.AvgFillPrice - ((Stop+30) * TickSize)), (entryOrder50.AvgFillPrice - (Stop * TickSize)), "initialStopLLA1", "LLA1");
                      initialSetLLA1 = true;         // set initial stop only once
                      Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") +  " Open SL LLA1 @ AvgFill - 225 = " + (entryOrder50.AvgFillPrice - (Stop * TickSize)));
                  }
      But weird stuff still happens. The attached screenshot shows a position being opened early in the morning, not having its stop set at all and only closing at the end of the trading day, way beneath my wanted SL-level.

      This is the output:
      11-2-2016 1:42:32 Entered internal PlaceOrder() method at 11-2-2016 1:42:32: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LLA1' FromEntrySignal=''
      11-02-2016, 01:42:32 Long Lime Arrow 1 @ 163,835
      11-2-2016 1:42:32 Entered internal PlaceOrder() method at 11-2-2016 1:42:32: BarsInProgress=1 Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=0,18 StopPrice=0,20 SignalName='BEstopLLA1' FromEntrySignal='LLA1'
      11-2-2016 1:42:32 Ignored PlaceOrder() method: Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=0,18 StopPrice=0,20 SignalName='BEstopLLA1' FromEntrySignal='LLA1' Reason='This was an exit order but no position exists to exit'
      11-02-2016, 01:42:32 BE LLA 1 set @ 0,2
      Seems to me the strategy skipped the placement of the initial stoploss alltogether (for reasons unknown) , but that it tried to set a BE (but also failed).

      As always, I am grateful for your expert opinion
      Attached Files

      Comment


        #4
        Hello Spinn,

        I am not seeing that the print within the condition that places the exit order is appearing in the output.

        Are you certain that the condition is evaluating as true?

        Print(Time[0].ToString("dd/MM/yyyy") + ", " + Time[0].ToString("HH:mm:ss") + " Open SL LLA1 @ AvgFill - 225 = " + (entryOrder50.AvgFillPrice - (Stop * TickSize)));

        Where is the output of this print?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          (sorry for the delay, I was rather busy these last few days)

          I have been making changes in my code, and am now unable to reproduce this specific instance of the problem. I do however still encounter problems with stop-levels being 'skipped'.

          For instance this initial StopLoss:

          10-02-2016, 20:10:31 Flat, so Trail = False. TrailStop reset.
          10-2-2016 20:10:31 Entered internal PlaceOrder() method at 10-2-2016 20:10:31: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LLA1' FromEntrySignal=''
          10-02-2016, 20:10:31 Long Lime Arrow 1 @ 164,74
          10-02-2016, 20:10:31 Order 50 filled at 164,75
          10-2-2016 20:10:31 Entered internal PlaceOrder() method at 10-2-2016 20:10:31: BarsInProgress=1 Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=164,55'5 StopPrice=164,53 SignalName='initialStopLLA1' FromEntrySignal='LLA1'
          10-02-2016, 20:10:31 Initial SL LLA1 @ AvgFillPrice - (Stop * TickSize) = 164,555
          10-02-2016, 20:12:53 $ $ $ Open PnL: 55,0000000000068
          10-02-2016, 20:14:48 $ $ $ Open PnL: 120,000000000005
          10-02-2016, 20:15:35 $ $ $ Open PnL: -9,99999999999091
          10-02-2016, 20:15:43 $ $ $ Open PnL: -74,9999999999886
          10-02-2016, 20:15:44 $ $ $ Open PnL: -139,999999999986
          10-02-2016, 20:19:51 $ $ $ Open PnL: -9,99999999999091
          10-02-2016, 20:25:35 $ $ $ Open PnL: 55,0000000000068
          10-02-2016, 20:39:07 $ $ $ Open PnL: -74,9999999999886
          10-02-2016, 20:42:29 $ $ $ Open PnL: -139,999999999986
          10-02-2016, 20:42:32 $ $ $ Open PnL: -205,000000000013
          10-02-2016, 20:42:33 $ $ $ Open PnL: -270,00000000001
          10-02-2016, 20:42:34 $ $ $ Open PnL: -335,000000000008
          10-02-2016, 20:42:36 $ $ $ Open PnL: -400,000000000006
          10-02-2016, 20:42:39 $ $ $ Open PnL: -270,00000000001
          10-02-2016, 20:42:47 $ $ $ Open PnL: -400,000000000006
          10-02-2016, 20:43:31 $ $ $ Open PnL: -465,000000000003
          10-02-2016, 20:43:32 $ $ $ Open PnL: -530,000000000001
          10-02-2016, 20:43:51 $ $ $ Open PnL: -594,999999999999
          10-02-2016, 20:43:54 $ $ $ Open PnL: -659,999999999997
          10-02-2016, 20:44:18 $ $ $ Open PnL: -530,000000000001
          10-02-2016, 20:45:21 $ $ $ Open PnL: -465,000000000003
          10-02-2016, 20:48:22 $ $ $ Open PnL: -594,999999999999
          10-02-2016, 20:48:29 $ $ $ Open PnL: -659,999999999997
          10-02-2016, 20:48:34 $ $ $ Open PnL: -724,999999999994
          10-02-2016, 20:48:36 $ $ $ Open PnL: -789,999999999992
          10-02-2016, 20:49:37 $ $ $ Open PnL: -659,999999999997
          10-02-2016, 20:49:43 $ $ $ Open PnL: -594,999999999999
          10-02-2016, 20:50:21 $ $ $ Open PnL: -724,999999999994
          10-02-2016, 20:51:13 $ $ $ Open PnL: -594,999999999999
          10-02-2016, 20:54:24 $ $ $ Open PnL: -530,000000000001
          10-02-2016, 20:55:07 $ $ $ Open PnL: -659,999999999997
          10-02-2016, 20:57:23 $ $ $ Open PnL: -724,999999999994
          10-02-2016, 20:57:26 $ $ $ Open PnL: -789,999999999992
          10-02-2016, 20:57:49 $ $ $ Open PnL: -659,999999999997
          10-02-2016, 20:58:38 $ $ $ Open PnL: -594,999999999999
          10-02-2016, 21:00:07 $ $ $ Open PnL: -724,999999999994
          10-02-2016, 21:02:31 $ $ $ Open PnL: -789,999999999992
          10-02-2016, 21:06:41 $ $ $ Open PnL: -659,999999999997
          10-02-2016, 21:09:15 $ $ $ Open PnL: -789,999999999992
          10-02-2016, 21:15:41 $ $ $ Open PnL: -854,99999999999
          10-02-2016, 21:20:49 $ $ $ Open PnL: -724,999999999994
          10-02-2016, 21:24:37 $ $ $ Open PnL: -659,999999999997
          10-02-2016, 21:41:45 $ $ $ Open PnL: -594,999999999999
          10-02-2016, 21:47:04 $ $ $ Open PnL: -530,000000000001
          10-02-2016, 22:04:18 $ $ $ Open PnL: -465,000000000003
          10-02-2016, 22:05:51 $ $ $ Open PnL: -400,000000000006
          10-02-2016, 22:14:50 $ $ $ Open PnL: -530,000000000001
          10-02-2016, 22:26:30 $ $ $ Open PnL: -594,999999999999
          10-02-2016, 22:27:24 $ $ $ Open PnL: -659,999999999997
          10-02-2016, 22:28:20 $ $ $ Open PnL: -724,999999999994
          10-02-2016, 22:33:32 $ $ $ Open PnL: -594,999999999999
          10-02-2016, 22:33:58 $ $ $ Open PnL: -530,000000000001
          10-02-2016, 22:43:43 $ $ $ Open PnL: -465,000000000003
          10-02-2016, 22:50:45 $ $ $ Open PnL: -400,000000000006
          10-02-2016, 22:58:02 $ $ $ Open PnL: -530,000000000001
          10-02-2016, 22:59:54 $ $ $ Open PnL: -460,000000000008
          10-2-2016 22:59:54 Cancelled pending exit order, since associated position is closed: Order='NT-00143/Sim101' Name='initialStopLLA1' State=Working Instrument='$GBPJPY' Action=Sell Limit price=164,555 Stop price=164,53 Quantity=1 Strategy='LiSL210Test' Type=StopLimit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='fd69ea9bfd01495ea153ae6ab53eb974' Gtd='1-12-2099 0:00:00'
          10-02-2016, 22:59:54 Long Lime Arrow 1 Flat, so SL reset
          entry50 nul
          which came from this code:

          Code:
          //Initial Stop on Open for LLA1
                          if (entryOrder50 != null & execution.Order == entryOrder50 && entryOrder50.OrderState == OrderState.Filled && !initialSetLLA1
                          )    
                          {
                          Print (Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") + " Order 50 filled at " + (entryOrder50.AvgFillPrice));
                          stop50 = ExitLongStopLimit (1,true, DefaultQuantity, (entryOrder50.AvgFillPrice - (195 * TickSize)), (entryOrder50.AvgFillPrice - (220 * TickSize)), "initialStopLLA1", "LLA1");
                          initialSetLLA1 = true;         // set initial stop only once
                          Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") +  " Initial SL LLA1 @ AvgFillPrice - (Stop * TickSize) = " + (entryOrder50.AvgFillPrice - (Stop * TickSize)));
                      }
          Order is being filled ok, stoploss is being set ok as well. And then price falls way below and I am not stopped out.

          The blue line in the attached screenshot is the level where my order should have been closed.
          Attached Files

          Comment


            #6
            Hello Spinn,

            The buy entry filled at 164,555.

            The exit stop limit is placed with the stop at 164,53 and the limit is placed higher instead of lower at 164,55'5.

            (I actually expected this order to be rejected)

            However, if it was not rejected and became working, then the stop would have touched as the price fell to 164,53 and then would become a limit. The limit would not fill until the price reverse direction and travels back up to 164,55'5.

            Are you looking at the ticks on a chart and you are seeing that after 20:12:53 the price fell below 164,53 and then reversed direction and travelled back up to 164,55'5 before 22:59:54?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              So, I switched the numbers around in my ExitLongStopLimit, like so:

              Code:
              stop50 = ExitLongStopLimit (1,true, DefaultQuantity, (entryOrder50.AvgFillPrice - (220 * TickSize)), (entryOrder50.AvgFillPrice - (195 * TickSize)), "initialStopLLA1", "LLA1");
              and this is the output:

              10-02-2016, 20:10:31 Flat, so Trail = False. TrailStop reset.
              10-2-2016 20:10:31 Entered internal PlaceOrder() method at 10-2-2016 20:10:31: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LLA1' FromEntrySignal=''
              10-02-2016, 20:10:31 Long Lime Arrow 1 @ 164,74
              10-02-2016, 20:10:31 Order 50 filled at 164,75
              10-2-2016 20:10:31 Entered internal PlaceOrder() method at 10-2-2016 20:10:31: BarsInProgress=1 Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=164,53 StopPrice=164,55'5 SignalName='initialStopLLA1' FromEntrySignal='LLA1'
              10-02-2016, 20:10:31 Initial SL LLA1 @ AvgFillPrice - (Stop * TickSize) = 164,555
              10-02-2016, 20:12:53 $ $ $ Open PnL: 55,0000000000068
              10-02-2016, 20:14:48 $ $ $ Open PnL: 120,000000000005
              10-02-2016, 20:15:35 $ $ $ Open PnL: -9,99999999999091
              10-02-2016, 20:15:43 $ $ $ Open PnL: -74,9999999999886
              10-02-2016, 20:15:44 $ $ $ Open PnL: -139,999999999986
              10-02-2016, 20:19:51 $ $ $ Open PnL: -9,99999999999091
              10-02-2016, 20:25:35 $ $ $ Open PnL: 55,0000000000068
              10-02-2016, 20:39:07 $ $ $ Open PnL: -74,9999999999886
              10-02-2016, 20:42:29 $ $ $ Open PnL: -139,999999999986
              10-02-2016, 20:42:32 $ $ $ Open PnL: -205,000000000013
              10-02-2016, 20:42:33 $ $ $ Open PnL: -270,00000000001
              10-02-2016, 20:42:34 $ $ $ Open PnL: -335,000000000008
              10-02-2016, 20:42:36 $ $ $ Open PnL: -400,000000000006
              10-02-2016, 20:42:39 $ $ $ Open PnL: -270,00000000001
              10-02-2016, 20:42:47 $ $ $ Open PnL: -400,000000000006
              10-02-2016, 20:43:31 $ $ $ Open PnL: -465,000000000003
              10-02-2016, 20:43:32 $ $ $ Open PnL: -530,000000000001
              10-02-2016, 20:43:51 $ $ $ Open PnL: -594,999999999999
              10-02-2016, 20:43:54 $ $ $ Open PnL: -659,999999999997
              10-02-2016, 20:44:18 $ $ $ Open PnL: -530,000000000001
              10-02-2016, 20:45:21 $ $ $ Open PnL: -465,000000000003
              10-02-2016, 20:48:22 $ $ $ Open PnL: -594,999999999999
              10-02-2016, 20:48:29 $ $ $ Open PnL: -659,999999999997
              10-02-2016, 20:48:34 $ $ $ Open PnL: -724,999999999994
              10-02-2016, 20:48:36 $ $ $ Open PnL: -789,999999999992
              10-02-2016, 20:49:37 $ $ $ Open PnL: -659,999999999997
              10-02-2016, 20:49:43 $ $ $ Open PnL: -594,999999999999
              10-02-2016, 20:50:21 $ $ $ Open PnL: -724,999999999994
              10-02-2016, 20:51:13 $ $ $ Open PnL: -594,999999999999
              10-02-2016, 20:54:24 $ $ $ Open PnL: -530,000000000001
              10-02-2016, 20:55:07 $ $ $ Open PnL: -659,999999999997
              10-02-2016, 20:57:23 $ $ $ Open PnL: -724,999999999994
              10-02-2016, 20:57:26 $ $ $ Open PnL: -789,999999999992
              10-02-2016, 20:57:49 $ $ $ Open PnL: -659,999999999997
              10-02-2016, 20:58:38 $ $ $ Open PnL: -594,999999999999
              10-02-2016, 21:00:07 $ $ $ Open PnL: -724,999999999994
              10-02-2016, 21:02:31 $ $ $ Open PnL: -789,999999999992
              10-02-2016, 21:06:41 $ $ $ Open PnL: -659,999999999997
              10-02-2016, 21:09:15 $ $ $ Open PnL: -789,999999999992
              10-02-2016, 21:15:41 $ $ $ Open PnL: -854,99999999999
              10-02-2016, 21:20:49 $ $ $ Open PnL: -724,999999999994
              10-02-2016, 21:24:37 $ $ $ Open PnL: -659,999999999997
              10-02-2016, 21:41:45 $ $ $ Open PnL: -594,999999999999
              10-02-2016, 21:47:04 $ $ $ Open PnL: -530,000000000001
              10-02-2016, 22:04:18 $ $ $ Open PnL: -465,000000000003
              10-02-2016, 22:05:51 $ $ $ Open PnL: -400,000000000006
              10-02-2016, 22:14:50 $ $ $ Open PnL: -530,000000000001
              10-02-2016, 22:26:30 $ $ $ Open PnL: -594,999999999999
              10-02-2016, 22:27:24 $ $ $ Open PnL: -659,999999999997
              10-02-2016, 22:28:20 $ $ $ Open PnL: -724,999999999994
              10-02-2016, 22:33:32 $ $ $ Open PnL: -594,999999999999
              10-02-2016, 22:33:58 $ $ $ Open PnL: -530,000000000001
              10-02-2016, 22:43:43 $ $ $ Open PnL: -465,000000000003
              10-02-2016, 22:50:45 $ $ $ Open PnL: -400,000000000006
              10-02-2016, 22:58:02 $ $ $ Open PnL: -530,000000000001
              10-02-2016, 22:59:54 $ $ $ Open PnL: -460,000000000008
              10-2-2016 22:59:54 Cancelled pending exit order, since associated position is closed: Order='NT-00155/Sim101' Name='initialStopLLA1' State=Working Instrument='$GBPJPY' Action=Sell Limit price=164,53 Stop price=164,555 Quantity=1 Strategy='LiSL210Test' Type=StopLimit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d6ada00ea7ff4a1c872e29917b4f6a3a' Gtd='1-12-2099 0:00:00'
              10-02-2016, 22:59:54 Long Lime Arrow 1 Flat, so SL reset
              entry50 nul
              Bottom line: position still not being closed, even with Limit (25 * TickSize) LOWER than Stop

              Comment


                #8
                Hello Spinn,

                At what time after 8:10 PM (and before 10:59 PM) did the price drop from 164,75 down to 164,55'5?

                It may be helpful to print the current price along with the orderstate and prices of the order.

                Print(string.Format("{0} | name: {1} | order state: {2} | current price: {3} | stop price: {4} | limit price {5}", Time[0], myOrder.Name, myOrder.OrderState, Close[0], myOrder.StopPrice, myOrder.LimitPrice));

                With a sell stop limit order placed with the stop price below the current price with the limit price below the stop price, I would expect this order to fill once the price comes down and touches the stop price.
                Once touched, the limit would be place far below market price and should fill right away as long as there is volume to fill the order.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Ok, we want the price to print on every tick, right ??

                  So I added this:

                  Code:
                  if (Position.MarketPosition != MarketPosition.Flat )
                                  {
                                  Print(string.Format("{0} | name: {1} | order state: {2} | current price: {3} | stop price: {4} | limit price {5}", Time[0], entryOrder50.Name, entryOrder50.OrderState, Close[0], entryOrder50.StopPrice, entryOrder50.LimitPrice));
                                  }
                  inside "protected override void OnBarUpdate()"

                  I thought this would print the prices every incoming tick (once a position is open), but instead I get this:

                  02-02-2016, 02:09:38 Flat, so Trail = False. TrailStop reset.
                  02-02-2016, 02:13:09 Flat, so Trail = False. TrailStop reset.
                  2-2-2016 2:13:09 Entered internal PlaceOrder() method at 2-2-2016 2:13:09: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LLA1' FromEntrySignal=''
                  02-02-2016, 02:13:09 Long Lime Arrow 1 @ 173,445
                  02-02-2016, 02:13:09 Order 50 filled at 173,49
                  2-2-2016 2:13:09 Entered internal PlaceOrder() method at 2-2-2016 2:13:09: BarsInProgress=1 Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=173,27 StopPrice=173,29'5 SignalName='initialStopLLA1' FromEntrySignal='LLA1'
                  02-02-2016, 02:13:09 Initial SL LLA1 @ AvgFillPrice - (Stop * TickSize) = 173,295
                  2-2-2016 2:13:11 | name: LLA1 | order state: Filled | current price: 173,51 | stop price: 0 | limit price 0
                  02-02-2016, 02:13:11 $ $ $ Open PnL: 19,9999999999818
                  2-2-2016 2:15:08 | name: LLA1 | order state: Filled | current price: 173,38 | stop price: 0 | limit price 0
                  02-02-2016, 02:15:08 $ $ $ Open PnL: -110,000000000014
                  2-2-2016 2:23:07 | name: LLA1 | order state: Filled | current price: 173,51 | stop price: 0 | limit price 0
                  02-02-2016, 02:23:07 $ $ $ Open PnL: 19,9999999999818
                  2-2-2016 2:26:42 | name: LLA1 | order state: Filled | current price: 173,575 | stop price: 0 | limit price 0
                  02-02-2016, 02:26:42 $ $ $ Open PnL: 84,9999999999795
                  2-2-2016 2:30:38 | name: LLA1 | order state: Filled | current price: 173,64 | stop price: 0 | limit price 0
                  02-02-2016, 02:30:38 $ $ $ Open PnL: 149,999999999977
                  2-2-2016 3:03:40 | name: LLA1 | order state: Filled | current price: 173,51 | stop price: 0 | limit price 0
                  02-02-2016, 03:03:40 $ $ $ Open PnL: 19,9999999999818
                  2-2-2016 3:04:41 | name: LLA1 | order state: Filled | current price: 173,64 | stop price: 0 | limit price 0
                  02-02-2016, 03:04:41 $ $ $ Open PnL: 149,999999999977
                  The actual price does plot, but the Stop/Limit doesn't. Where did I go wrong ?

                  Comment


                    #10
                    Hello Spinn,

                    You are showing the price of the entry order which is already filled (and might have been a market order which wouldn't have stop or limit price).

                    I am somewhat confused. Was the entry order the order that did not fill?
                    I thought we were trying to find why a Stop Limit order did not fill, is this not the case?

                    Where did you put this print? (In what method?)

                    If you want this to print every tick, this could be in OnBarUpdate with Calculate on close set to false while processing real-time data.
                    Or a secondary series could be added of 1 tick which would also work historically.

                    If you wanted to print this on each bar close i think that would be ok too. (However, I should have advised to print the high and low of the bar instead of the close price)
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I adjusted to print the "stop50" orders instead of the "entryOrder50". Stops/Limits now print correctly

                      Furthermore, I have a secondary series added, like so:

                      Code:
                      protected override void Initialize()
                              {
                                  //Add secondary Timeframe for backtesting / optimalisation
                                  Add(PeriodType.Tick, 1);
                      I put the code in OnBarUpdate, since we want it to print on every tick (but it doesn't):

                      Code:
                       protected override void OnBarUpdate()
                                  {if
                                      (BarsInProgress == 0)
                                  
                                  {    
                                  if (Position.MarketPosition != MarketPosition.Flat )
                                      {
                                      Print(string.Format("{0} | name: {1} | order state: {2} | current price: {3} | stop price: {4} | limit price {5}", Time[0], stop50.Name, stop50.OrderState, Close[0], stop50.StopPrice, stop50.LimitPrice));
                                      
                                      }
                      This is the output from the order that did not fill:

                      10-02-2016, 20:10:31 Flat, so Trail = False. TrailStop reset.
                      10-2-2016 20:10:31 Entered internal PlaceOrder() method at 10-2-2016 20:10:31: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LLA1' FromEntrySignal=''
                      10-02-2016, 20:10:31 Long Lime Arrow 1 @ 164,74
                      10-02-2016, 20:10:31 Order 50 filled at 164,75
                      10-2-2016 20:10:31 Entered internal PlaceOrder() method at 10-2-2016 20:10:31: BarsInProgress=1 Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=164,53 StopPrice=164,55'5 SignalName='initialStopLLA1' FromEntrySignal='LLA1'
                      10-02-2016, 20:10:31 Initial SL LLA1 @ AvgFillPrice - (Stop * TickSize) = 164,555
                      10-2-2016 20:12:53 | name: initialStopLLA1 | order state: Working | current price: 164,805 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:12:53 $ $ $ Open PnL: 55,0000000000068
                      10-2-2016 20:14:48 | name: initialStopLLA1 | order state: Working | current price: 164,87 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:14:48 $ $ $ Open PnL: 120,000000000005
                      10-2-2016 20:15:35 | name: initialStopLLA1 | order state: Working | current price: 164,74 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:15:35 $ $ $ Open PnL: -9,99999999999091
                      10-2-2016 20:15:43 | name: initialStopLLA1 | order state: Working | current price: 164,675 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:15:43 $ $ $ Open PnL: -74,9999999999886
                      10-2-2016 20:15:44 | name: initialStopLLA1 | order state: Working | current price: 164,61 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:15:44 $ $ $ Open PnL: -139,999999999986
                      10-2-2016 20:19:51 | name: initialStopLLA1 | order state: Working | current price: 164,74 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:19:51 $ $ $ Open PnL: -9,99999999999091
                      10-2-2016 20:25:35 | name: initialStopLLA1 | order state: Working | current price: 164,805 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:25:35 $ $ $ Open PnL: 55,0000000000068
                      10-2-2016 20:39:07 | name: initialStopLLA1 | order state: Working | current price: 164,675 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:39:07 $ $ $ Open PnL: -74,9999999999886
                      10-2-2016 20:42:29 | name: initialStopLLA1 | order state: Working | current price: 164,61 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:42:29 $ $ $ Open PnL: -139,999999999986
                      10-2-2016 20:42:32 | name: initialStopLLA1 | order state: Working | current price: 164,545 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:42:32 $ $ $ Open PnL: -205,000000000013
                      10-2-2016 20:42:33 | name: initialStopLLA1 | order state: Working | current price: 164,48 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:42:33 $ $ $ Open PnL: -270,00000000001
                      10-2-2016 20:42:34 | name: initialStopLLA1 | order state: Working | current price: 164,415 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:42:34 $ $ $ Open PnL: -335,000000000008
                      10-2-2016 20:42:36 | name: initialStopLLA1 | order state: Working | current price: 164,35 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 20:42:36 $ $ $ Open PnL: -400,000000000006
                      ...
                      ...
                      ...
                      10-02-2016, 22:33:32 $ $ $ Open PnL: -594,999999999999
                      10-2-2016 22:33:58 | name: initialStopLLA1 | order state: Working | current price: 164,22 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 22:33:58 $ $ $ Open PnL: -530,000000000001
                      10-2-2016 22:43:43 | name: initialStopLLA1 | order state: Working | current price: 164,285 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 22:43:43 $ $ $ Open PnL: -465,000000000003
                      10-2-2016 22:50:45 | name: initialStopLLA1 | order state: Working | current price: 164,35 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 22:50:45 $ $ $ Open PnL: -400,000000000006
                      10-2-2016 22:58:02 | name: initialStopLLA1 | order state: Working | current price: 164,22 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 22:58:02 $ $ $ Open PnL: -530,000000000001
                      10-2-2016 22:59:54 | name: initialStopLLA1 | order state: Working | current price: 164,29 | stop price: 164,555 | limit price 164,53
                      10-02-2016, 22:59:54 $ $ $ Open PnL: -460,000000000008
                      10-2-2016 22:59:54 Cancelled pending exit order, since associated position is closed: Order='NT-00163/Sim101' Name='initialStopLLA1' State=Working Instrument='$GBPJPY' Action=Sell Limit price=164,53 Stop price=164,555 Quantity=1 Strategy='LiSL210Test' Type=StopLimit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ffe4c2e3fb1f4c4db37f9e848f198f4e' Gtd='1-12-2099 0:00:00'
                      10-02-2016, 22:59:54 Long Lime Arrow 1 Flat, so SL reset
                      entry50 nul
                      This clearly shows that price dived below 164.555 (Stop) and even below 164.53 (Limit), but position didn't close.


                      This is the code to open a position (in OnBarUpdate, obviously)

                      Code:
                      entryOrder50 = EnterLong(1,DefaultQuantity, "LLA1");
                      And this is how I set the SL (in OnExecution)

                      Code:
                      if (entryOrder50 != null & execution.Order == entryOrder50 && entryOrder50.OrderState == OrderState.Filled && !initialSetLLA1
                                      )    
                                      {
                                      Print (Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") + " Order 50 filled at " + (entryOrder50.AvgFillPrice));
                                      stop50 = ExitLongStopLimit (1,true, DefaultQuantity, (entryOrder50.AvgFillPrice - (220 * TickSize)), (entryOrder50.AvgFillPrice - (195 * TickSize)), "initialStopLLA1", "LLA1");
                      I am pretty much lost now

                      Comment


                        #12
                        Hi Spinn,

                        I am understanding your confusion. I'm am also confused with this output. This shows the price dropping below the order and the order continues working.

                        I'd like to test this script on my end.

                        If you are ok sharing this, please post an export to your next post.
                        If not, please send an export to platformsupport [at] ninjatrader [dot] com. In the email include a link to this forum thread.

                        To export a NinjaTrader 7 NinjaScript do the following:
                        1. Click File -> Utilities -> Export NinjaScript
                        2. Enter a unique name for the file in the value for 'File name:'
                        3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
                        4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


                        By default your exported file will be in the following location:
                        • (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript\<export_file_name.z ip>


                        Below is a link to the help guide on Exporting NinjaScripts.
                        http://www.ninjatrader.com/support/h...nt7/export.htm


                        I also wanted to say thanks for adding those prints in, they are very informative.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by yertle, Yesterday, 08:38 AM
                        7 responses
                        28 views
                        0 likes
                        Last Post yertle
                        by yertle
                         
                        Started by bmartz, 03-12-2024, 06:12 AM
                        2 responses
                        20 views
                        0 likes
                        Last Post bmartz
                        by bmartz
                         
                        Started by funk10101, Today, 12:02 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post funk10101  
                        Started by gravdigaz6, Yesterday, 11:40 PM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by MarianApalaghiei, Yesterday, 10:49 PM
                        3 responses
                        10 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Working...
                        X