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.
      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      57 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      35 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      19 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      9 views
      0 likes
      Last Post cre8able  
      Working...
      X