My goal is to carefully control position and stop sizing as I approach a given daily loss limit.
If this is true it has me thinking that I would need to create a global variable that gets updated with each trade's P&L using something like this:
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.RealTimeTrad es[SystemPerformance.RealTimeTrades.Count - 1];
// Calculate the PnL for the last completed real-time trade
double lastProfitCurrency = lastTrade.ProfitCurr ency;
// 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));
}
}
In order to avoid re-inventing the wheel I wanted to make this post to run it past the fine folks at this forum to see if I'm on the right path or if I should adjust course?

Comment