I am having trouble finding these code lines:
1. What is the code for for "Total PnL" that shows on the "accounts" tab in the control center. I have the realized/unrealized PnL for the strategy, but want the code for the account PnL total
2. In the same image above, what is the code for Net Liquidation
3. What is the code line as an if statement for IF(last bar experienced an entry Long/Short) so instead of replicating the conditions of entry, it would be something like "if in the last bar I entered a trade" ... then I could continue with my 'Then' script.
Further, I am trying to understand what my current PnL is for a when I am achieving interim targets in a strategy. For instance, if I enter at a price of 100, then enter again at a price of 50, the position average price is now 75 and the PnL is calculated from there. However, if I take an interim target from the second entry at a price of 60, I have gained $10 in my PnL, but the trade is calculated from the Avg price of 75. When I do this over the course of several trades, my account PnL/the realized/unrealized for the strategy don't reflect what my account shows after I close a trade - I understand they are calculating through different methods. In the case of a series of trades like the above that take interim targets before going flat again, I have trouble determining what my actual PnL is at a given time. I am not asking for a bunch of code, just a few more pointers on how to calculate this in a script. I found the below scripts in the help guide and I think can be used as a reference, as I believe this is where to start.
protected override void OnBarUpdate()
{
if (SystemPerformance.RealTimeTrades.Count > 0)
{
// Check to make sure there is at least one trade in the collection
Trade lastTrade = SystemPerformance.RealTimeTrades[SystemPerformance.RealTimeTrades.Count - 1];
// Calculate the PnL for the last completed real-time trade
double lastProfitCurrency = lastTrade.ProfitCurrency;
// Store the quantity of the last completed real-time trade
double lastTradeQty = lastTrade.Quantity;
// Pring the PnL to the NinjaScript Output window
Print("The last trade's profit in currency is " + lastProfitCurrency);
// The trade profit is quantity aware, we can easily print the profit per traded unit as well
Print("The last trade's profit in currency per traded unit is " + (lastProfitCurrency / lastTradeQty));
}
}
Comment