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 NullPointStrategies, Today, 05:17 AM
      0 responses
      38 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      124 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      64 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      41 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X