Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90


May be Bug and to get data on close order

  • Filter
  • Time
  • Show
Clear All
new posts

    May be Bug and to get data on close order

    Hi. two questions
    ************************************************** ************************************************** ******
    question 1:
    marked as number "1" in the picture.
    Task: exiting a position by named linked orders.
    Location: Trade Performance table//tab Trades($)
    Problem: shows incorrect name values.
    1. order(s) closing: the ExitLong(SignalName, FromEntrySignal) method with parameters:
    1. SignalName ='ES :196:LONG.CLOSE'
    2. FromEntrySignal='ES :196:LONG'
    The trace of close order (bottom of the picture) shows the correct execution of orders related by name.
    but the table shows incorrect Entry name data.
    The execution time of two successively closed orders does not affect this behavior.
    Q1?: it is my bug or Yours?
    ************************************************** ************************************************** ******
    question 2:
    marked as number "2" in the picture.
    Task: to get the realized/unrealized profit loss on close order(s). TotalPnl in real Time
    Location: Base window. tab Accounts//Trade Performance table, tab Trades($)
    Problem: I get secondary data in close order or I don't find a method to get data.
    I want to get the last record on close order(s) from the Trade Performance table, tab Trades($) trader number 8 in the picture:
     var lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1] ;
     // or RealTimeTrades or SystemPerformance.RealTimeTrades.TradesPerformance ;
    There is no method lastTrade.getCumulativeNetProfit(??). Although I can get the lastTrade.Entry(Exit).Names/Times/Prices of open/close orders.
    if I used this method, I can't get ALL trades per day from the table, but only those trades that were made during the working of the strategy.
    and can't get the real Last row of the Trades($) table. I get a second row(before last)

    2. on close order I want to get data from the tab Accounts:
    in if (State == State.SetDefaults){
    lock (Account.All)myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
    in override void OnExecutionUpdate(....){
    var RealPnl = myAccount.Get(AccountItem.RealizedProfitLoss, Currency.UsDollar);
    real: RealPnl = -222.50; expected: -272.50
    in the picture, the green arrows show the values ​​that I need to get, and the red arrow shows the value that I get in reality.
    ps. but if I print it data in Open order I get the correct data for all.

    I want to get on close order(s):
    Q2?: tab Accounts:
    the realized/unrealized profit loss from the account tab. TotalPnl in real Time
    Q3?: Trades tab:
    3.1. a list of ALL trades for the day
    3.2. a real Last record with the Trader's Number(8) and a cumulative net profit: -272.50
    ************************************************** ************************************************** ******
    Click image for larger version  Name:	Q5.png Views:	0 Size:	87.8 KB ID:	1212511

    Thanks in advance.
    Attached Files
    Last edited by Danila; 08-18-2022, 06:02 AM.

    Hello Danila,

    Thank you for your reply.

    In the trade performance window, trades are made by linking executions in a FIFO manner. Signal names will not be taken into account.

    Strategies will only be aware of trades that occurred during that run of the strategy. You would have to access the account. See this help guide example on adding an account object to your script

    You can follow that example and set up an account object in your indicator. You can then use the Executions collection within the Account class to loop through and match exits with entries, as the Account class does not have a trade collection like the strategy does. You can then match them by the order names, and calculate the PnL of each trade, and add them up to get the cumulative net profit. There's not a simple way to do that, unfortunately, you'd have to code that logic.

    Please let us know if we may be of further assistance to you.

    Kate W.NinjaTrader Customer Service


      Hi Kate!
      Thanks for your answer, the way You suggested is accepted.
      1. FIFO made.
      Click image for larger version  Name:	A1.png Views:	0 Size:	13.2 KB ID:	1212638

      2. by Accounts. I find an easy way to get this PnL without additions/subtractions, etc.
      ************************************************** ***** ***************
       in on if (State == State.SetDefaults)
        lock (Account.All) myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
        realPnLAllTradesOnCloseOrder = myAccount.Get(AccountItem.RealizedProfitLoss, Currency.UsDollar);
      in override void OnExecutionUpdate(....)
      var lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
      var comulativePnLCurrentIntstrument = SystemPerformance.AllTrades.TradesPerformance.NetProfit;
      realPnLAllTradesOnCloseOrder += lastTrade.ProfitCurrency;
      //"Total" can be also to get  in the onBarUpdate()
      Thank you for Your help.


      Latest Posts


      Topics Statistics Last Post
      Started by flightbooking, Today, 08:20 AM
      0 responses
      Last Post flightbooking  
      Started by roblogic, 11-25-2022, 07:04 AM
      4 responses
      Last Post NinjaTrader_Jesse  
      Started by dibDab, Today, 03:58 AM
      1 response
      Last Post NinjaTrader_Emily  
      Started by nurushaik, 11-23-2022, 01:08 PM
      7 responses
      Last Post NinjaTrader_ChelseaB  
      Started by chandiram2, Yesterday, 11:25 PM
      1 response
      Last Post Tasker-182