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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      168 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      322 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      246 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      350 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      179 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X