double GetOrderPNLDollars(Order order,OrderRecord orderRecord)
{
if(orderRecord.EntryBar == CurrentBar) // just set value to $0 if we're still on the same bar
{
return 0;
}
else
{
double priceDiff = 0;
if(Position.MarketPosition == MarketPosition.Long)
{
priceDiff = (GetCurrentAsk(0) - orderRecord.EntryPrice) * order.Quantity;
}
if(Position.MarketPosition == MarketPosition.Short)
{
priceDiff = (orderRecord.EntryPrice - GetCurrentAsk(0)) * order.Quantity;
}
// Convert the PNL from ticks to dollars
return Math.Round((priceDiff * Bars.Instrument.MasterInstrument.PointValue ),2);
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Tracking per-entry PNL?
Collapse
X
-
Tracking per-entry PNL?
I have a strategy where I am setting stops at increments of an order value, rather than using the absolute pricepoint. To do this, I generate the current profit per order, and then I check to see if the price is a multiple of the increment and if so, set a stop. The problem is that I can't get it right. I've tracked the value in the order signal to compare to NT UI, but there are discrepancies. Should this work?
screenshot attached showing inconsistencyCode:Tags: None
-
Hello Skifree,
Thanks for your post.
I am unsure as to what orderRecord is referring to in the code you shared as this is not a documented/supported method or property. GetOrderPnLDollars() is also not a supported or documented method or property.
To get the price of an entry order that is placed, you could consider tracking the Order object in OnExecutionUpdate() and accessing the Price of the Order object.
For example, you could check if (entryOrder != null && entryOrder == execution.Order), check if the execution.Order.OrderState is OrderState.Filled, and get the execution.Price value. Then you could use the execution.Price value in your calculations.
See the help guide documentation below for more information.
OnExecutionUpdate(): https://ninjatrader.com/support/help...tionupdate.htm
OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm
SampleOnOrderUpdate(): https://ninjatrader.com/support/help...and_onexec.htm
<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
Hello Skifree,
Thanks for your notes.
If you are wanting to get the PnL of a strategy instance you could use GetUnrealizedProfitLoss(). This would return the PnL for the current open strategy position, which could be any number of entries into a direction.
See this help guide page for more information about Position.GetUnrealizedProfitLoss: https://ninjatrader.com/support/help...profitloss.htm
If you would like the Unrealized PnL of each individual entry order for a strategy that is placing multiple entry orders, you would need to calculate this value yourself using your own custom logic.
Something you could consider is to calculate that value by using either the Close price at the time of the entry or the entry's average price, then calculate that value from the current Close price.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
52 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
70 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
43 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
48 views
0 likes
|
Last Post
|

Comment