Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Moving Stop Loss when reaching half position profit target

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

    Moving Stop Loss when reaching half position profit target

    In my strategy I enter 2 position of equal size in order to close one half of my total position when the profit target is reached.

    When this happens I want to set a new stop loss at the original entry price (breakeven stop loss) and then adjust the stop loss with the market moves.

    I use the following code to enter the trade, where Variable0 is my stop price and variable1 is my porfit target

    EnterLong(50, "1st");
    EnterLong(50, "2nd");
    SetStopLoss("1st", CalculationMode.Price, Variable0, true);
    SetStopLoss("2nd", CalculationMode.Price, Variable0, true);
    SetProfitTarget("1st", CalculationMode.Price, Variable1);

    Now I need to know when the 1st profit target is reached and that 1st position is closed.

    I thought I would use the following statement
    if (Position.Quantity == 50)

    but this is not working as it seems to be always false.

    Is there a better way to find out if my 1st half position was closed (i.e my Profit Target order was triggered)?

    Is there also a way to find out if my Stop Loss order triggered for each of the open positions?

    Thanks

    #2
    Hello agosinv,

    Thank you for your post.

    You can use IOrder objects to check the name and status of your orders: http://www.ninjatrader.com/support/h...nt7/iorder.htm

    In addition, we have a reference sample on OnOrderUpdate() and OnExecution() to submit protective stops and targets at the following link: http://www.ninjatrader.com/support/f...ead.php?t=7499

    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello agosinv,

      Thank you for your post.

      You can use IOrder objects to check the name and status of your orders: http://www.ninjatrader.com/support/h...nt7/iorder.htm

      In addition, we have a reference sample on OnOrderUpdate() and OnExecution() to submit protective stops and targets at the following link: http://www.ninjatrader.com/support/f...ead.php?t=7499

      Please let me know if you have any questions.
      OK. I modified my order entry statements as following:
      entryOrder1st = EnterLong(50, "1st");
      entryOrder2nd = EnterLong(50, "2nd");

      In this way I know when the order is filled. Since I included a couple of print statement in my code I can see the following in the output window

      Trade entered. The 1st order status is: Status:Working, Type:Market, Quantity:50
      Trade entered. The 2nd order status is: Status:Working, Type:Market, Quantity:50
      Trade entered. The current Strategy market quantity is: 0

      Trade entered. The 1st order status is: Status:Filled, Type:Market, Quantity:50
      Trade entered. The 2nd order status is: Status:Filled, Type:Market, Quantity:50
      Trade entered. The current Strategy market quantity is: 100

      This is GOOD. Now here is the problem. When the profit target on the 1st position is reached the status of the 1st and 2nd order is not updated and the following is what I see in the output window

      Trade entered. The 1st order status is: Status:Filled, Type:Market, Quantity:50
      Trade entered. The 2nd order status is: Status:Filled, Type:Market, Quantity:50
      Trade entered. The current Strategy market quantity is: 50

      What am I missing?

      Also: I wanted to monitor my stop loss and profit target orders

      Currently I use the following:
      SetStopLoss("1st", CalculationMode.Price, Variable0, true);
      SetStopLoss("2nd", CalculationMode.Price, Variable0, true);
      SetProfitTarget("1st", CalculationMode.Price, Variable1);

      Is there an IOrder type that can provide the status of these orders?

      Thank a lot

      Comment


        #4
        Hello agosinv,

        Thank you for your response.

        Now here is the problem. When the profit target on the 1st position is reached the status of the 1st and 2nd order is not updated and the following is what I see in the output window

        Trade entered. The 1st order status is: Status:Filled, Type:Market, Quantity:50
        Trade entered. The 2nd order status is: Status:Filled, Type:Market, Quantity:50
        Trade entered. The current Strategy market quantity is: 50
        The orders are filled, therefore they report as filled even though one has had it's Profit or Stop filled. You will need to set the IOrder object to null after the Stop or Profit has been filled.

        You can use the following sample to see how to monitor Stop Loss and Profit Target Orders: http://www.ninjatrader.com/support/f...ead.php?t=5790

        Please let me know if I may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by RideMe, 04-07-2024, 04:54 PM
        5 responses
        28 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by f.saeidi, Today, 08:13 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by DavidHP, Today, 07:56 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by kujista, Today, 06:23 AM
        3 responses
        9 views
        0 likes
        Last Post kujista
        by kujista
         
        Started by Mindset, Yesterday, 02:04 AM
        2 responses
        18 views
        0 likes
        Last Post NinjaTrader_RyanS  
        Working...
        X