Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get exit price unmanaged approach

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

    How to get exit price unmanaged approach

    Hello,

    I'm using a sample from you, which define stop and profit the following way:

    if (entryOrder != null && entryOrder == execution.Order)
    {
    // This second if-statement is meant to only let fills and cancellations filter through.
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {
    // Simple stop and target
    stopOrder = ExitLongStopMarket(0, true, 1, execution.Price - 10 * TickSize, "stop", "long limit entry");
    targetOrder = ExitLongLimit(0, true, 1, execution.Price + 20 * TickSize, "target", "long limit entry");

    // Resets the entryOrder object to null after the order has been filled
    if (execution.Order.OrderState != OrderState.PartFilled)
    {
    entryOrder = null;
    }
    }
    }

    Once one of these 2 prices are reached, filled the exit order and then exit the position, I would like to get the resultant real exit price for this position and assign this to a variable. Could I see some example?


    Thanks,
    Federico
    Last edited by federicoo; 04-06-2022, 11:56 AM.

    #2
    Hello federicoo,

    Thank you for the post.

    To find exit prices you would either need to use the price which you submitted it at if you need it before the fill or you would have to wait for the fill and then observe the fill event.

    With what you have you can access the prices by using the order variables:

    Code:
    [B]stopOrder [/B]= ExitLongStopMarket(0, true, 1, execution.Price - 10 * TickSize, "stop", "long limit entry");
    [B]targetOrder [/B]= ExitLongLimit(0, true, 1, execution.Price + 20 * TickSize, "target", "long limit entry");
    for example stopOrder.StopPrice



    The alternative would be to wait for the order event and make a condition just like your entry order condition:

    Code:
    if (stopOrder != null && stopOrder == execution.Order)
    {
    
    }

    Comment


      #3
      Thanks Jesse, I'm trying with this:

      protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
      {
      if (stopOrder != null && stopOrder == execution.Order)
      {
      Print (@"I'm here!");
      }
      }

      but nothing happen, despite having closed too many trades in historic data. Could it be that this condition is not verify and the print is not written if it is not in real time?

      Comment


        #4
        Hello federicoo,

        From the given example I don't see a problem, you would need to check what is happening by using a print outside the condition.

        Try printing like the following:

        Code:
        protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
        {
            Print (execution.ToString());
        
           if (stopOrder != null && stopOrder == execution.Order)
           {
               Print (@"I'm here!");
           }
        }
        That will just output all execution data, once you are testing the situation check if the target fills and is observed in OnExecutionUpdate. If you see the execution event that indicates a problem with the variable or condition. An alternative would be to check for the orders name:

        Code:
        if (execution.Order.Name == "stop")

        Comment


          #5
          Thanks Jesse,

          It is working now.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          53 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X