Announcement

Collapse

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

Collapse

May be Bug and to get data on close order

Collapse
X
 
  • 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.
    Steps:
    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.
    Steps:
    I want to get the last record on close order(s) from the Trade Performance table, tab Trades($) trader number 8 in the picture:
    1.
    Code:
     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:
    Code:
    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.

    #2
    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 https://ninjatrader.com/support/help...ount_class.htm

    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

    Comment


      #3
      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.
      ************************************************** ***** ***************
      Code:
       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.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by usazencort, Today, 01:16 AM
      0 responses
      1 view
      0 likes
      Last Post usazencort  
      Started by kaywai, 09-01-2023, 08:44 PM
      5 responses
      603 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      6 responses
      22 views
      0 likes
      Last Post xiinteractive  
      Started by Pattontje, Yesterday, 02:10 PM
      2 responses
      21 views
      0 likes
      Last Post Pattontje  
      Started by flybuzz, 04-21-2024, 04:07 PM
      17 responses
      230 views
      0 likes
      Last Post TradingLoss  
      Working...
      X