Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to detect a Close order?

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

    How to detect a Close order?

    Hi, I looked through the documentation and searched here but cant seem a way to detect specifically when someone uses the Close button? Is this not sent as an order type with a specific flag I can identify? I am coding an add on and want to detect when users alter positions, close positions, etc.
    Thanks,
    -R

    #2
    Hello RaygunWizzle,

    To detect a close order you would need to subscribe to the addon framework account class OnOrderUpdate and OnExecutionUpdate events to see the order that is submitted to the account in realtime. The order would be submitted as a market order with the name Close. This would not be visible from a Strategy, you would need to use an indicator and add the addon framework account events.

    Comment


      #3
      Yes as I stated I am coding this in an add on. Here is my current OnExecutionUpdate and OnOrderUpdate classes:
      private void OnExecutionUpdate(object sender, ExecutionEventArgs e)
      {
      try
      {
      Dispatcher.InvokeAsync(() =>
      {
      ExecutionInstrument = e.Execution.Instrument;
      ExecutionQuantity = e.Quantity;
      ExecutionPrice = e.Price;
      outputBox6.Clear();
      outputBox6.AppendText("Execution:");
      outputBox6.AppendText(string.Format("{0}Instrument : {1}{0}Quantity: {2}{0}Price: {3}{0}MarketPosition: {4}{0}Time: {5}{0}",
      Environment.NewLine,
      e.Execution.Instrument.FullName,
      e.Quantity,
      e.Price,
      e.MarketPosition,
      e.Time));
      TradeAnalysis();
      });
      }
      catch (Exception error)
      {
      Dispatcher.InvokeAsync(() =>
      {
      outputBox6.Text = "TCFramework - OnExecutionUpdate Exception: " + error.ToString();
      });
      }

      }
      private void OnOrderUpdate(object sender, OrderEventArgs e)
      {
      try
      {
      Dispatcher.InvokeAsync(() =>
      {
      outputBox6.Clear();
      outputBox6.AppendText("Order:");
      outputBox6.AppendText(string.Format("{0}Instrument : {1}{0}OrderAction: {2}{0}OrderType: {3}{0}Quantity: {4}{0}LimitPrice: {5}{0}StopPrice: {6}{0}Time: {7}{0}",
      Environment.NewLine,
      e.Order.Instrument.FullName,
      e.Order.OrderAction,
      e.Order.OrderType,
      e.Quantity,
      e.LimitPrice,
      e.StopPrice,
      e.Time));

      if (e.Order.OrderType == OrderType.Market && (e.Order.OrderAction == OrderAction.BuyToCover || e.Order.OrderAction == OrderAction.Sell))
      {
      profitTarget = 0;
      stopLoss = 0;
      return;
      }

      if (e.Order.OrderType == OrderType.Limit)
      {
      if (CurrentMarketPosition == MarketPosition.Long && e.Order.LimitPrice > CurrentAveragePrice)
      {
      profitTarget = e.Order.LimitPrice;
      }
      else if (CurrentMarketPosition == MarketPosition.Short && e.Order.LimitPrice < CurrentAveragePrice)
      {
      profitTarget = e.Order.LimitPrice;
      }
      }

      else if (e.Order.OrderType == OrderType.StopMarket)
      {
      if (CurrentMarketPosition == MarketPosition.Long && e.Order.StopPrice < CurrentAveragePrice)
      {
      stopLoss = e.Order.StopPrice;
      }
      else if (CurrentMarketPosition == MarketPosition.Short && e.Order.StopPrice > CurrentAveragePrice)
      {
      stopLoss = e.Order.StopPrice;
      }
      }

      TradeAnalysis();
      });
      }
      catch (Exception error)
      {
      Dispatcher.InvokeAsync(() =>
      {
      outputBox6.Text = "TCFramework - OnOrderUpdate Exception: " + error.ToString();
      });
      }
      }​
      So under Execution update I can have it look for e.ExecutionType.Close ?

      Comment


        #4
        Hello RaygunWizzle,

        I would suggest adding a print that just outputs the Order and Execution objects so you can see the values for any type of order. The way to check for a close order is to look at the orders Name property which is equal to "Close".

        Comment


          #5
          If you're trying to figure out when someone closes a trade using the "Close" button, it might not be straightforward to spot it directly. What you could do is keep an eye on changes in how many stocks or money they have. If that number goes down without them making any new buys or sells, chances are they hit that "Close" button.

          Another idea is to look at the history of their trades. Sometimes, you can see a note or label saying a trade was closed. This could be a clue that they closed their position.​

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          605 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          351 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          560 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          561 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X