Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

getting position data once closed

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

  • jaboo
    replied
    beautiful! that makes complete sense thank you!

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    Hello jaboo,

    Thank you for the clarification.

    Please reference the following example that gets the entry order name of the trade that was just closed.

    SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].Entry.Order.Name

    Please let us know if you have any more inquiries.

    Leave a comment:


  • jaboo
    replied
    Thank you for the reply. I'm willing to bet i am just not explaining what im asking clearly enough so i'll give it another shot.

    at a very base level i want to know when an order exits with a profit for loss for that SPECIFIC order.

    Order x;
    Order y;

    if(a) x = enterLong("longA");
    if(b) y = enterLong("longB")

    ....a period of time elapses and the SL is hit on an order so it closes and therefor fires a tradeexecution.

    question -
    1. How can i tell that the order that JUST exited and fired the trade execution is either Order x or Order y. Because the ID is not unique i cannot reference order x or order y.


    SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].Exit.Order.Name <- this just gives me "Stop loss" or "Profit target" but again says nothing about which order (Order x, Order y) was exited.

    for added context, given certain conditions are met I will enter a trade. When i decide to enter a trade there is a lot of properties I want to save. Once this order is complete (exits) I want to save the result/

    example.

    class MyOrder : Order

    bool condition1;
    bool condition2;
    double pnl;



    Onbarupdate()

    if(condtionXYZ) MyOrder o = new MyOrder(true,false)


    .......time goes by

    OrderExecution() o.pnl = trade.profitpoints


    if i could get a unique id i could easily just reference the order by id.

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    Hello jaboo,

    Thank you for your reply.

    The orderids change when the id generated by the broker comes back and when historical orders become realtime. Each trade has an Entry and Exit Execution property. We recommend checking the order name from the Exit Execution in the Trade. Please refer to the following example.

    SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].Exit.Order.Name

    Here are Help Guide links about Trade, Execution, and Order in NinjaTrader.

    Trade - https://ninjatrader.com/support/help...nt8/?trade.htm

    Execution - https://ninjatrader.com/support/help...?execution.htm

    Order -https://ninjatrader.com/support/help...nt8/?order.htm

    Please let us know if we may assist further.


    Leave a comment:


  • jaboo
    replied
    to add. I realized a possible solution would be to track the OrderID and Order in a dictionary eg Dictionary<orderID, Order> and then in OnExecution grab the order by the OrderId. However in the docs it says that the OrderID is not unique and that it changes.If this is the case, at what point does the orderID change so i know to update the dictionary?

    Leave a comment:


  • jaboo
    replied
    Appreciate you getting back to me! I may not have explained correctly.

    If i have two orders

    Order A = LongMarket("Order A");
    Order B = LongMarket("Order B");

    For whatever reason Order A and Order B close at the same time (profit of sl hit). How can i know that the profit for Order A is X and profit for Order B is X.

    If i use Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1]; <- this will give me the last Order but it does not tell me if its Order A or Order B.

    Thanks!

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    Hello jaboo,

    Thank you for your post.

    Executions of Exit orders may be checked within OnExecutionUpdate if your Exits are given a unique signal name, or you may check when Position.MarketPostition == MarketPosition.Flat in OnPositionUpdate.

    Here are Help Guide links for more information about OnExecutionUpdate and MarketPosition.

    OnExecutionUpdate - https://ninjatrader.com/support/help...tionupdate.htm

    OnPositionUpdate - https://ninjatrader.com/support/help...tionupdate.htm

    MarketPosition - https://ninjatrader.com/support/help...etposition.htm

    SystemPerformance may be used to check the strategy's performance programmatically. SystemPerformance object holds all trades and trade performance data generated by a strategy.

    Please reference the Help Guide link below for information about using SystemPerformance.
    SystemPerformance - https://ninjatrader.com/support/help...erformance.htm

    Please let us know if we may further assist.

    Leave a comment:


  • jaboo
    started a topic getting position data once closed

    getting position data once closed

    Hi there,

    I am attempting to do some Machine Learning so i need to know the success/failure once a position closes. I did not see how to do this using method onexecution.

    Also, is there a way to know once the strategy has finished so i can loop through all my trades?

    Thanks!

Latest Posts

Collapse

Topics Statistics Last Post
Started by ultraketoburnx, Today, 03:09 AM
0 responses
1 view
0 likes
Last Post ultraketoburnx  
Started by ultraketoburnx, Today, 03:08 AM
0 responses
1 view
0 likes
Last Post ultraketoburnx  
Started by TomTownsend, Yesterday, 10:12 PM
1 response
13 views
0 likes
Last Post NinjaTrader_Jason  
Started by rdeste911, Today, 02:04 AM
0 responses
6 views
0 likes
Last Post rdeste911  
Started by aligator, Yesterday, 04:32 PM
1 response
26 views
0 likes
Last Post NinjaTrader_Jason  
Working...
X