NexusFi: Find Your Edge


Home Menu

 





PnL Question


Discussion in NinjaTrader

Updated
    1. trending_up 1,672 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
SodyTexas's Avatar
 SodyTexas 
Austin TX
 
Experience: Advanced
Platform: Ninjatrader, Python, & R
Broker: RJO
Trading: Futures, Spreads
Posts: 424 since Sep 2013
Thanks Given: 118
Thanks Received: 1,098

I'm Stumped,

What I am trying to do is store PnL in a DataSeries per trade (not per lot). For example, if I buy three contracts and it fills in two lots when closing the position. I want the PnL on the three contracts, not on a lot basis. The reasoning behind this is I want to avoid risk of ruin by controlling position sizing by PnL.

What I have so far:

 
Code
  
#region Variables
private DataSeries PnL;

protected override void Initialize()
{
PnL = new DataSeries(this);
}

protected override void OnBarUpdate()
{
//No PnL information in this 
}

protected override void OnExecution(IExecution execution)
{
if (Performance.RealtimeTrades.Count > 0)
{
	// Get the last completed real-time trade (at index 0)
Trade Trade1 = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
				
	// Calculate the PnL for the last completed real-time trade
double lastProfit = Trade1.ProfitCurrency * Trade1.Quantity;

if(lastProfit != PnL[1]) {PnL[0] = lastProfit; Print("PnL " +PnL[0]);}
Print("The last trade's profit is " + lastProfit);
The problem is it is returning the PnL for each lot, which will not benefit me in my position sizing calculation. Any thoughts on a work around.

P.S. - new to the Elite crowd, and very happy that I purchased the membership. If you have not done so and are thinking about it... DO IT!!!

Cheers,

SodyTexas


Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
$4.5M Floods Russia Nuclear Contract in 24 Hours -- Krem …
Prediction Markets & Event Contracts
El Clasico Draws $9.2M in Prediction Market Action -- Bi …
Prediction Markets & Event Contracts
May 26 Deadline Dies at 7.5% as US Strikes Iran During C …
Prediction Markets & Event Contracts
Sundays Verdict: Lebanon Locked at 99.85% as Iran June 7 …
Prediction Markets & Event Contracts
Trump Truth Social Fires Hormuz From 10% to 59% -- Arsen …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
15 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks




Last Updated on October 28, 2013


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts