Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sold price is much lower than SetStopLoss()

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

    Sold price is much lower than SetStopLoss()

    Hi all,

    I am backtesting a strategy. I use the following code to set my stop loss. Most of the time, the stop loss triggered at the correct place, but once in a while, I see the sold price is much lower than the stop loss price. In this case, the stop loss was set at 1.21553, but the sold price was at 1.21251. Am I doing something wrong or is there a reason for this?



    Code:
    SetStopLoss("Target1", CalculationMode.Price, stop, true);
    SetProfitTarget("Target1", CalculationMode.Price, target);
    this.order1 = EnterLongStopMarket(2, true, this.SharesToBuy, entry, "Target1");
    Thanks!
    Last edited by op1031; 01-24-2021, 03:40 AM.

    #2
    Hello op1031,

    Welcome to the NinjaTrader forums!

    With market or stop market orders, these can be affected by slippage. When the stop is touched the order will fill at the market price, which may have moved away from the stop price. This will be more pronounced in fast moving markets.

    To check the calculated prices before calling the set methods, print the these with the time of the bar to the output window.
    https://ninjatrader.com/support/foru...121#post791121
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      To check the calculated prices before calling the set methods, print these with the time of the bar to the output window.
      I set the stop loss right before I make the EnterLongMarketStop order, and at that point, I was able to see the value of the stop loss which was 1.21553 in the debug mode, but the exit is 1.21251 for some reason. To be honest, I don't quite understand what I need to print... could you be more specific?

      I checked on the minute data I have, and there were definitely a few candles that hit 1.21553, so I don't quite understand why the backtest simulator would not exit at the correct price.
      I also noticed that my Exit time is always at half an hour. For example, it would print the exit time is 2/13/2019 7:30:00 AM or 7/15/2019 8:30:00 AM, and so on (It is always at the 30 minute mark. I wonder if my 1 HOUR primary time frame has something to do with it).

      When I set the stop loss, I specify to use bar index = 2, which is the minute bar. I thought I set the stop loss and it would just execute the stop loss when the price is hit regardless of what time frame I use, am I mistaken?

      Comment


        #4
        Hello op1031,

        Along with TraceOrders enabled in State.Configure, add a print that prints the time of the bar, the stop variable, and the GetCurrentBid().

        We will need to verify that the stop variable value is at least 1 tick below the bid.

        Stop order methods are attached to the primary series. If the chart is an hour chart, the stop would fill with close prices from the hour chart.

        You cannot supply Set methods with a Bars series index. There is no parameter for this. The set methods will always be attached to the primary.
        https://ninjatrader.com/support/help...etstoploss.htm
        Last edited by NinjaTrader_ChelseaB; 01-25-2021, 08:32 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          You cannot supply Set methods with a Bars series index. There is no parameter for this. The set methods will always be attached to the primary.
          Sorry, I remembered it wrong. I set it at EnterLongStopMarket.

          I just want to clarify how stoploss works. My primary is 1 hour bar. Let's say I set the stop at $100.30, the 1 hour bar at 9:30AM triggered my stop loss has a high of $100.50 and the low of $100.00. Will my stoploss gets executed at the end of the 9:30AM? or does it get triggered whenever $100.30 is hit?
          My thought is that the stop trigger will execute whenever $100.30 is hit, as a result, it would generate a market sell order. Am I mistaken?

          We will need to verify that the stop variable value is at least 1 tick below the bid.
          I only have minute data and not tick data. Since the simulator doesn't have tick data, how does the simulator execute a market sell order?

          Comment


            #6
            Hi Chelsea,

            I lost track of the trade, so here is a new example with trace log. To sum it up, it is a short trade with entry @ 1.17912, stoploss set @ 1.18, profit target @ 1.17824. The analyzer shows that the trade hit stoploss and exited @ 1.18104 which is the bid price of the hourly bar at 7:00AM.
            So this means, stoploss doesn't execute when it's hit; instead, it executes at the bid price of the end of a primary bar. Could you confirm this is how it's designed?


            TRACE:
            Code:
            OnOrderTrace TS=11/12/2020 5:05:00 AM MSG=Strategy 'rafkus/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='11/12/2020 5:05:00 AM' Mode=Price Value=1.18 IsSimulatedStop=True IsMarketIfTouched=False bid=1.17937 1.18
            OnOrderTrace TS=11/12/2020 5:05:00 AM MSG=Strategy 'rafkus/-1': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='11/12/2020 5:05:00 AM' Mode=Price Value=1.17824 IsSimulatedStop=False IsMarketIfTouched=False bid=1.17937 1.18
            OnOrderTrace TS=11/12/2020 5:05:00 AM MSG=Strategy 'rafkus/-1': Entered internal SubmitOrderManaged() method at 11/12/2020 5:05:00 AM: BarsInProgress=2 Action=SellShort OrderType=StopMarket Quantity=100 LimitPrice=0 StopPrice=1.1791'2 SignalName='11/12/2020 5:05:00 AM' FromEntrySignal='' bid=1.17937 1.18
            OnOrderTrace TS=11/12/2020 5:05:00 AM MSG=Strategy 'rafkus/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Target2' Mode=Price Value=1.18 IsSimulatedStop=True IsMarketIfTouched=False bid=1.17937 1.18
            OnOrderTrace TS=11/12/2020 5:05:00 AM MSG=Strategy 'rafkus/-1': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Target2' Mode=Price Value=1.17736 IsSimulatedStop=False IsMarketIfTouched=False bid=1.17937 1.18
            OnOrderTrace TS=11/12/2020 5:05:00 AM MSG=Strategy 'rafkus/-1': Entered internal SubmitOrderManaged() method at 11/12/2020 5:05:00 AM: BarsInProgress=2 Action=SellShort OrderType=StopMarket Quantity=100 LimitPrice=0 StopPrice=1.1791'2 SignalName='Target2' FromEntrySignal='' bid=1.17937 1.18
            OnExecutionUpdate TS=11/12/2020 5:14:00 AM Q=100 price=1.17912 name=11/12/2020 5:05:00 AM bid=1.17988 EUPDATE
            OnPositionUpdate Q=100 price=1.17912 bid=1.17988 POSUPDATE
            OnExecutionUpdate TS=11/12/2020 5:14:00 AM Q=100 price=1.17912 name=Target2 bid=1.17988 EUPDATE
            OnPositionUpdate Q=200 price=1.17912 bid=1.17988 POSUPDATE
            OnOrderTrace TS=11/12/2020 6:00:00 AM MSG=Strategy 'rafkus/-1: Cancelled pending exit order, since associated position is closed, orderId='NT-00207-1751' account='Backtest' name='Profit target' orderState=Working instrument='EURUSD' orderAction=BuyToCover orderType='Limit' limitPrice=1.17824 stopPrice=0 quantity=100 tif=Gtc oco='NT-00112-1751' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-12 05:00:00' gtd='2099-12-01' statementDate='2021-01-25' bid=1.18104 0
            OnExecutionUpdate TS=11/12/2020 7:00:00 AM Q=100 price=1.18104 name=Stop loss bid=1.18104 EUPDATE
            OnPositionUpdate Q=100 price=1.17912 bid=1.18104 POSUPDATE
            OnOrderTrace TS=11/12/2020 6:00:00 AM MSG=Strategy 'rafkus/-1': Cancelled OCO paired order: BarsInProgress=0, orderId='NT-00207-1751' account='Backtest' name='Profit target' orderState=Cancelled instrument='EURUSD' orderAction=BuyToCover orderType='Limit' limitPrice=1.17824 stopPrice=0 quantity=100 tif=Gtc oco='NT-00112-1751' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-12 05:00:00' gtd='2099-12-01' statementDate='2021-01-25' bid=1.18104 0
            OnOrderTrace TS=11/12/2020 6:00:00 AM MSG=Strategy 'rafkus/-1: Cancelled pending exit order, since associated position is closed, orderId='NT-00209-1751' account='Backtest' name='Profit target' orderState=Working instrument='EURUSD' orderAction=BuyToCover orderType='Limit' limitPrice=1.17736 stopPrice=0 quantity=100 tif=Gtc oco='NT-00113-1751' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-12 05:00:00' gtd='2099-12-01' statementDate='2021-01-25' bid=1.18104 0
            OnExecutionUpdate TS=11/12/2020 7:00:00 AM Q=100 price=1.18104 name=Stop loss bid=1.18104 EUPDATE
            OnPositionUpdate Q=0 price=0 bid=1.18104 POSUPDATE
            OnOrderTrace TS=11/12/2020 6:00:00 AM MSG=Strategy 'rafkus/-1': Cancelled OCO paired order: BarsInProgress=0, orderId='NT-00209-1751' account='Backtest' name='Profit target' orderState=Cancelled instrument='EURUSD' orderAction=BuyToCover orderType='Limit' limitPrice=1.17736 stopPrice=0 quantity=100 tif=Gtc oco='NT-00113-1751' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-12 05:00:00' gtd='2099-12-01' statementDate='2021-01-25' bid=1.18104 0

            How can I make the simulator exit at the moment the stoploss is hit? I am guessing the answer is that I have to have tick data, and a tick data series to sell when the tick data hits stoploss, is that correct? Can I set my primary series as tick then let setstoploss take care of the stoploss by itself?

            I was reluctant to set my primary time frame to a lower time frame because I saw this in one of the samples so I thought the primary series always need to be in the highest time frame. Did I misunderstand?
            Very Important: This secondary bar series needs to be smaller than the primary bar series.
            Note: The primary bar series is whatever you choose for the strategy at startup.
            Last edited by op1031; 01-26-2021, 01:41 AM.

            Comment


              #7
              Hello op1031,

              This information does not tell us if the submission price is less than the bid.

              Along with TraceOrders enabled in State.Configure, add a print that prints the time of the bar, the stop variable, and the GetCurrentBid().

              Stop market orders fill immediately at market price when touched during trading hours.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks for the explanations
                The issue is resolved. I was not trading in the primary time frame, so I guess that's why it was giving out unexpected results.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by futurenow, Today, 07:17 PM
                0 responses
                3 views
                0 likes
                Last Post futurenow  
                Started by Emma1, Today, 07:15 PM
                0 responses
                1 view
                0 likes
                Last Post Emma1
                by Emma1
                 
                Started by n8dogg59, 05-10-2019, 08:00 AM
                14 responses
                621 views
                0 likes
                Last Post brownsfan019  
                Started by [email protected], Today, 06:03 PM
                0 responses
                1 view
                0 likes
                Last Post bpatel20@gmail.com  
                Started by Johnny Santiago, Today, 04:36 PM
                2 responses
                13 views
                0 likes
                Last Post -=Edge=-  
                Working...
                X