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 Mindset, 04-21-2026, 06:46 AM
          0 responses
          88 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          135 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          68 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          119 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          69 views
          0 likes
          Last Post PaulMohn  
          Working...
          X