Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help in collecting orders data

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

    Need help in collecting orders data

    Hi.

    I'm trying to collect data on my trades in the strategy ...(during run-time)

    So I want that every time an order is closed (due to close order or SL/TP):
    I'll be able to collect data about the trade:
    1. what is the PNL
    2. how many bars ago was the order entry.

    I tried to play with the "OnExecutionUpdate" and "OnPositionUpdate"
    but without success,

    please advice
    thanks
    Gil

    #2
    this is the (ugly) solution I found so far:
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    // Remember to check the underlying Order object for null before trying to access its properties
    if (execution.Order.OrderAction == OrderAction.BuyToCover || execution.Order.OrderAction == OrderAction.Sell || execution.Order.OrderType ==OrderType.Limit || execution.Order.OrderType ==OrderType.StopMarket)
    {
    Print("Exit, Entry price="+Close[BarsSinceEntryExecution()+1]);

    return;
    }

    if(execution.MarketPosition == MarketPosition.Long){
    Print("long close="+Close[0]);
    }
    if(execution.MarketPosition == MarketPosition.Short){
    Print("short close="+Close[0]);
    }

    }

    Comment


      #3
      Hello,

      Thank you for the post.

      Yes, in general, this should work, you could also store the CurrentBar when you submit the Entry, and then subtract that value from the CurrentBar at the time of the Execution to get a BarsAgo. While you are in a position, it would be suggested to use BarsSinceEntryExecution.

      Regarding the PnL, you could calculate this yourself using the entry and exit information or you could also review the trade performance collections: http://ninjatrader.com/support/forum...ead.php?t=4084

      I look forward to being of further assistance.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      41 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      27 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      45 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      37 views
      0 likes
      Last Post CarlTrading  
      Working...
      X