Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stoploss and profit targets

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

    stoploss and profit targets

    Hi

    When setting an entry using a limit order, that works fine, I also set the stoploss and profit target values using your methods;
    SetProfitTarget("buyOrder", CalculationMode.Pips, ProfitTarget);
    SetStopLoss("buyOrder", CalculationMode.Pips, StopLoss,true);
    SetProfitTarget("sellOrder", CalculationMode.Pips, ProfitTarget);
    SetStopLoss("sellOrder", CalculationMode.Pips, StopLoss,true);

    In the strategy I have a place where my orders are to be closed, I may not have hit my stops / targets, and therefore any corresponding stops / profit orders need to be cancelled.

    I close any positions I have first and then proceed to cancel these orders, but it does not seem to be correct. I get closed out and the price could be above any market prices observed. Is this potentially a problem with the stops / profits or with my closing the trade?

    I have included a code snippet of the entrties and exits.
    EnterLongLimit(0, true, Qty, entryPriceBuy , "buyOrder");
    ExitLong(1, "exitBuy", "buyOrder");

    EnterShortLimit(0, true, Qty, entryPriceSell, "sellOrder");
    ExitShort(1, "exitSell", "sellOrder");

    Do I need to reference these stops / profit orders within "OnOrderUpdate()" or should they work automatically when the order is closed and just shut themselves down.

    Thanks

    #2
    Hello fishbed,

    Thanks for opening the thread.

    The Exit methods in the Managed Approach will take you out of your position for as many contracts as you specify for the associated Entry Signal. When all of the open positions have been closed, the Profit Target and Stop Loss orders will be cancelled from OCO.

    For example, if you entered with 3 contracts and used Exit methods to take your self out 1 position at a time, you would need your exit condition to become true 3 times for the Profit Target and Stop Loss order to be cancelled.

    You will not need to cancel these orders in OnOrderUpdate(). It is also not within the design of the SetStopLoss() and SetProfitTarget() methods to allow cancelling in OnOrderUpdate().

    ExitLong() and ExitShort() will submit market orders to close positions. Slippage could effect the fill price on market orders for live orders, but I may suggest to use Trace Orders and test with Market Replay data to verify where the strategy is placing the order and where it is getting filled.

    You may wish to reference these methods in the Managed Approach section of the help guide - https://ninjatrader.com/support/help...d_approach.htm

    Using TraceOrders can be referenced here - http://ninjatrader.com/support/forum...ead.php?t=3627

    Please let me know if I can be of further help.
    JimNinjaTrader Customer Service

    Comment


      #3
      oco cancelled if order one order is partly filled

      Hi,
      I have a problem with OCO orders I tried it with managed and unmanaged code. Here is the example of unmanaged code.

      It works if the order is filled completely but, if my OCO order is partly filled both the target and the stop order is cancelled can you please tell me why? A OCO order should be only canceled if one side is filled completely not if it is partly filled.

      I ran replay but I noticed this during live trading:

      as you can see the target is filled partially so only 1 but both orders the target and the stop is cancelled so I not only that my target is not filled I end up with a unprotected long position


      NQ 09-17 Buy Market 2 0 0 Filled 2 5931,625 0 Buy Gtc Replay101 Market Replay Connection 07f7dc725d6d499aaae5bb074e2fe60d mmRobot 07f7dc725d6d499aaae5bb074e2fe60d 20.07.2017 14:37
      NQ 09-17 Sell Stop 1 0 5929,00 Cancelled 0 0 1 LongStop Exit Gtc Replay101 Market Replay Connection 6d55995e8af24451a829151182a57880 mmRobot 6d55995e8af24451a829151182a57880 20.07.2017 14:37
      NQ 09-17 Sell Limit 1 5932,50 0 Filled 1 5932,5 0 Target Exit Gtc Replay101 Market Replay Connection 21dc36d24af549c4a42a64bcba2f82d3 mmRobot 21dc36d24af549c4a42a64bcba2f82d3 20.07.2017 14:37
      NQ 09-17 Sell Stop 2 0 5929,00 Cancelled 0 0 2 LongStop Exit Gtc Replay101 Market Replay Connection 65768b2d7e3f459e86b68c9017da1c27 mmRobot 65768b2d7e3f459e86b68c9017da1c27 20.07.2017 14:37
      NQ 09-17 Sell Limit 2 5932,50 0 Cancelled 0 0 2 Target Exit Gtc Replay101 Market Replay Connection b4028549513244f99f90ae8973f1770b mmRobot b4028549513244f99f90ae8973f1770b 20.07.2017 14:37
      NQ 09-17 Buy Market 1 0 0 Filled 1 5931,5 0 BuyTrail Gtc Replay101 Market Replay Connection dafec80a25ec42669eb9a86857fa354b mmRobot dafec80a25ec42669eb9a86857fa354b 20.07.2017 14:37
      NQ 09-17 Sell Stop 1 0 5931,00 Accepted 0 0 1 TrailStop Trail Gtc Replay101 Market Replay Connection ffb7fed3c5e742728411ee16e3c05bf9 mmRobot ffb7fed3c5e742728411ee16e3c05bf9 20.07.2017 14:37



      21.07.2017 14:04:17 Entered internal SubmitOrder() method at 21.07.2017 14:04:17: Action=Sell OrderType=Market Quantity=2 LimitPrice=0 StopPrice=0 OcoId='' Name='Sell'
      21.07.2017 14:04:17 Entered internal SubmitOrder() method at 21.07.2017 14:04:17: Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 OcoId='' Name='SellTrail'
      21.07.2017 14:04:17 Entered internal SubmitOrder() method at 21.07.2017 14:04:17: Action=BuyToCover OrderType=Stop Quantity=2 LimitPrice=5913,75 StopPrice=5913,75 OcoId='Exit' Name='ShortStop'
      21.07.2017 14:04:17 Entered internal SubmitOrder() method at 21.07.2017 14:04:17: Action=BuyToCover OrderType=Limit Quantity=2 LimitPrice=5911,75 StopPrice=1,00 OcoId='Exit' Name='Target'
      21.07.2017 14:04:17 Entered internal SubmitOrder() method at 21.07.2017 14:04:17: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=5913,75 StopPrice=5913,75 OcoId='Trail' Name='TrailStop'
      21.07.2017 14:04:30 Cancelled OCO paired order: BarsInProgress=0: Order='NT-00002/Replay101' Name='ShortStop' State=Working Instrument='NQ 09-17' Action=BuyToCover Limit price=0 Stop price=5913,75 Quantity=2 Strategy='mmRobot' Type=Stop Tif=Gtc Oco='Exit' Filled=0 Fill price=0 Token='6456e08c2c754080a1341d6b83218abb' Gtd='01.12.2099 00:00:00'

      Comment


        #4
        Hello mm3368,

        It would be the expected behavior to see the OCO paired orders subtract contracts in the event of a partial fill.

        Could you attach your strategy and provide some steps I can take using Market Replay so I may provide further input?

        I look forward to being of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          oco cancelled if order one order is partly filled

          Hi, sorry for the delay I had to strip down my strategy to isolate the error

          to problem only happens if the main order is partial filled and the Target order is partial filled.I resubmit the stop and target till the main order is filled and as you can see as soon as Target is partial filled the rest of the OCO order is canceled and I have an unprotected long.

          Comment


            #6
            Hello mm3368,

            So I understand correctly, you do not receive an open position if the entry order is fully filled and you receive a partial fill on your OCO'd exits? Do the OCO orders update with the partial fill in this case?

            Could you provide the reduced strategy and some steps we could take to reproduce on our end? Reproducing in Market Replay would be the easiest way we could test this case for review.

            If you don't want to post the code here, you can write in to platformsupport [at] ninjatrader [dot] com with the text "ATTN Jim" and the thread URL. We can then continue correspondence through email and then share our findings here.

            I look forward to being of further assistance.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Island_Boy_Trading, Today, 07:39 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by cmarkb, Today, 07:19 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by wjadevries, Today, 03:29 AM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by Oracletrades, Yesterday, 09:10 PM
            1 response
            119 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by ginx10k, Today, 07:04 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X