Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Separating the unrealized gain for two trades in the same strategy
Collapse
X
-
Separating the unrealized gain for two trades in the same strategy
I need to calculate the unrealized P&L for more than 1 position in the same strategy. It is my understanding that <Position> calculates all open trades in a strategy. I have been assigning the unrealized gain/loss of the first trade to a variable and then subtracting from the total when there are two trades but this seems awkward and I'm wondering if there is not a better way?Tags: None
-
Hello galsermil,
There is only one position per instrument in a NinjaScript Strategy. (There is also one position per instrument per account)
Multiple trades would affect the quantity and average price of that single position. Meaning a buy order at 100 and a second buy order of 110 would result in a position of long 2 with an average price of 105.
Are you meaning that you have different instruments added with AddDataSeries()?
Each instrument added with AddDataSeries() that has a position will be in the Positions collection.
A trade has both an entry order and an exit order. So if this is a trade, the orders of that trade would not affect the open position as that position is now closed with the exit order of that trade.
The trade would then be in the SystemPerformance TradeCollection.
The Position.GetUnrealizedPnl() (or Positions[series index].GetUnrealizedPnL()) will only return the unrealized pnl of the open position. (Where there is an entry order but no exit order)
You could add this to the SystemPerformance of closed trades.
Below is a link to an example.
Hello, I've updated the DailyLossLimit and DailyLosLimitMultiTrade examples that were posted on the forum for NinjaTrader 7 for NinjaTrader 8. These are often requested and I felt they are good examples to have for NT8. DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241 (http://ninjatrader
Chelsea B.NinjaTrader Customer Service
-
Hello galsermil,
NinjaTrader does not track unrealized pnl for each individual order, only the position.
You will need custom coded logic to save the orders to a variable or array, and compare the current price to the entry fill price and calculate with the fill quantity.
The orders will update in OnOrderUpdate().
Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
50 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
127 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|
Comment