Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss ignored

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

    SetStopLoss ignored

    I know I must be doing something wrong, but not sure what. I am a very experienced ninjascript programmer but I've always done my own stop-loss calculations. However, I need an emergency stop-loss that is broker triggered for extreme cases. So I wanted to use SetStopLoss. It does nothing in backtest. So then I thought, well maybe it is only active during live trading, so then I set the simulation flag, still nothing. What am I missing?

    Here is my SetStopLoss code:
    SetStopLoss( stop_loss_max*100, true );
    Print("Stop loss max: " + stop_loss_max*100);

    Here is my output from TraceOrders (and my prints):
    8/12/2013 5:15:47 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=0 Currency=500 Simulated=True
    Stop loss max: 500
    **NT** Enabling NinjaScript strategy 'ThreefoldChannel/0176477218dc44cc91924a5c2ce95e07' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=ByStrategyPosition ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=False Set order quantity by=DefaultQuantity ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes
    Period type: Minute
    12/11/2012 3:30:00 PM Entered internal PlaceOrder() method at 12/11/2012 3:30:00 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='S1' FromEntrySignal=''
    EnterShort
    12/11/2012 4:00:00 PM Cancelled order due to end of session handling: BarsInProgress=0: Order='NT-00001/Sim60' Name='Stop loss' State=Working Instrument='ES 09-13' Action=BuyToCover Limit price=0 Stop price=1419.5 Quantity=1 Strategy='ThreefoldChannel' Type=Stop Tif=Day Oco='NT-00000-1763' Filled=0 Fill price=0 Token='9e8bba6dc96b49dabe42330501ba7cbe' Gtd='12/1/2099 12:00:00 AM'
    12/12/2012 10:30:00 AM Entered internal PlaceOrder() method at 12/12/2012 10:30:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L1' FromEntrySignal=''
    EnterLong
    Ignore EnterShort: 12/12/2012 4:00:00 PM
    12/12/2012 4:00:00 PM Cancelled order due to end of session handling: BarsInProgress=0: Order='NT-00004/Sim60' Name='Stop loss' State=Working Instrument='ES 09-13' Action=Sell Limit price=0 Stop price=1404.25 Quantity=1 Strategy='ThreefoldChannel' Type=Stop Tif=Day Oco='NT-00002-1763' Filled=0 Fill price=0 Token='6b4c296bfce54e03965bc289848bedef' Gtd='12/1/2099 12:00:00 AM'
    Ignore EnterLong: 12/17/2012 4:00:00 PM
    12/21/2012 11:30:00 AM Entered internal PlaceOrder() method at 12/21/2012 11:30:00 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='S1' FromEntrySignal=''
    EnterShort
    12/21/2012 3:30:00 PM Entered internal PlaceOrder() method at 12/21/2012 3:30:00 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L1' FromEntrySignal=''
    EnterLong
    12/21/2012 3:30:00 PM Cancelled pending exit order, since associated position is closed: Order='NT-00007/Sim60' Name='Stop loss' State=Working Instrument='ES 09-13' Action=BuyToCover Limit price=0 Stop price=1420.75 Quantity=1 Strategy='ThreefoldChannel' Type=Stop Tif=Day Oco='NT-00004-1763' Filled=0 Fill price=0 Token='e5ff17e92de3471e9fee2eba767058e3' Gtd='12/1/2099 12:00:00 AM'
    12/21/2012 4:00:00 PM Cancelled order due to end of session handling: BarsInProgress=0: Order='NT-00010/Sim60' Name='Stop loss' State=Working Instrument='ES 09-13' Action=Sell Limit price=0 Stop price=1404 Quantity=1 Strategy='ThreefoldChannel' Type=Stop Tif=Day Oco='NT-00006-1763' Filled=0 Fill price=0 Token='e3fdd55bb1a446dea41b61433d7bc399' Gtd='12/1/2099 12:00:00 AM'
    12/24/2012 10:30:00 AM Entered internal PlaceOrder() method at 12/24/2012 10:30:00 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='S1' FromEntrySignal=''
    EnterShort
    12/24/2012 1:30:00 PM Cancelled order due to end of session handling: BarsInProgress=0: Order='NT-00013/Sim60' Name='Stop loss' State=Working Instrument='ES 09-13' Action=BuyToCover Limit price=0 Stop price=1421 Quantity=1 Strategy='ThreefoldChannel' Type=Stop Tif=Day Oco='NT-00008-1763' Filled=0 Fill price=0 Token='50003af07b3041b8996c5cde2799836d' Gtd='12/1/2099 12:00:00 AM'
    Ignore EnterLong: 12/31/2012 4:00:00 PM
    1/3/2013 10:30:00 AM Entered internal PlaceOrder() method at 1/3/2013 10:30:00 AM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='ES1' FromEntrySignal='S1'
    ExitShort

    ****
    The trade on 12/24/12 is short from 1411. The trade on 1/3/13 exits the short at 1445.2 for a loss of over $1700. My SetStopLoss is for $500, but does not get triggered.
    Last edited by tradetree; 08-12-2013, 03:41 PM.

    #2
    Hi tradetree, it looks like the Stop loss has been canceled due to the end of session handling from the trace excerpt you posted. The simulated flag in the Set call means that you would not have your exit order submitted / working live, but rather have NT simulate this order, so monitoring for the trigger price and then sending a market exit. This is to hide the order from the book.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,
      So does that mean I have to resubmit the SetStopLoss every OnBarUpdate? Is there something I am doing that creates this condition? I made this change and I still never hit a stop loss, even when the trade I pointed out goes to -$1700 with a $500 stop loss.
      Last edited by tradetree; 08-13-2013, 08:48 AM.

      Comment


        #4
        tradetree, you should not need to resubmit it - what TIF setting are you working with?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I have a TIF of "day". And I now have the SetStopLoss being called on every bar. Still no effect on trades that I can see.

          Comment


            #6
            With DAY I would expect the stoploss / targets to expire as well at the end of session - so my suggestion would be retrying with a TIF of GTC.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Bertrand,
              I don't understand what the TIF has to do with my situation? I moved the SetStopLoss to that it is in OnBarUpdate. But if the TIF is "day" it does not take the stop loss, even during the day. I am a bit concerned about the TIF being "GTC" because I had a problem once with the exchange and this setting. I forget now what the problem was, but it was in the after-hour and it did not take GTC after-hours or something. So ever since then I've been using "day". Of course my current strategy is in the regular session hour, so that may not matter, but it does concern me. At least I'd like to know what the TIF has to do with the SetStopLoss call?

              Comment


                #8
                I have further information. I had two orders rejected by the exchange today. The reason is that I placed market orders, but I changed the TIF to GTC for the strategy. So here is the problem: market orders must by TIF of "day". But I want market and not limit orders for most of my trades. On the other hand, StopLoss orders must be TIF of "GTC". How can I accomplish this in the same strategy? I want my orders to by of type "day" and I want stop loss to be of type "gtc".

                Comment


                  #9
                  tradetree, the TIF would be determining if your stop orders are cleared by the end of session handling or not - with a TIF of DAY I would expect them to get cancelled by this procedure, so not lasting overnight. In contrast to that GTC would persist them until the position is closed and order directly cancelled then.

                  The strategy overall can only have one TIF setting, so to address - I would suggest to set the TIF from the UI to the one you need to persist the stops.

                  Then on your order submission in the script change on the fly the TIF you would need to not get those orders rejected, then after order submission revert it back to the GTC one you need for the stops.



                  For our next major update, we're considering to enhance this are to provide more flexibility - I will make sure to count a vote on your behalf in as well in our trackings.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Bertrand,
                    Ok, so I set the TIF before every trade action. This means 99% of the time it is GTC with a stop loss order. How long after submitting a market order do I have to wait to set it back from "day" to "gtc"? Right now it will not be till the next bar that it goes back to "gtc". I coded it this way to make sure switching back to "gtc" would not get in the way of my market order, but perhaps once it is submitted while "day" it will persist?

                    Comment


                      #11
                      Once it's submitted should be fine and you should be able to switch it back basically immediately after order submission to .GTC
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Bertrand View Post
                        Once it's submitted should be fine and you should be able to switch it back basically immediately after order submission to .GTC
                        Thanks. This solves the issue within the constraints of the current system.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by RookieTrader, Today, 09:37 AM
                        3 responses
                        15 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by kulwinder73, Today, 10:31 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post kulwinder73  
                        Started by terofs, Yesterday, 04:18 PM
                        1 response
                        24 views
                        0 likes
                        Last Post terofs
                        by terofs
                         
                        Started by CommonWhale, Today, 09:55 AM
                        1 response
                        4 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by Gerik, Today, 09:40 AM
                        2 responses
                        7 views
                        0 likes
                        Last Post Gerik
                        by Gerik
                         
                        Working...
                        X