I want to know how one can get the current open unrealized PnL of 2 different instruments. Suppose a strategy opens 2 orders for 2 instruments in long and short positions, then is there a method to get current total unrelized pnL? Thanks.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to get current unrealised PnL of 2 or more instruments
Collapse
X
-
How to get current unrealised PnL of 2 or more instruments
Hello,
I want to know how one can get the current open unrealized PnL of 2 different instruments. Suppose a strategy opens 2 orders for 2 instruments in long and short positions, then is there a method to get current total unrelized pnL? Thanks.Tags: None
-
Hello,Code:else if (State == State.Configure) { //Add 2 data series of 2 instruments AddDataSeries(PrimaryInstrument, BarsPeriodType.Second,5); //index1 AddDataSeries(HedgeInstrument, BarsPeriodType.Second,5); //index2 } private void GoLongSpread() { EnterLong(1,Qty1,""); EnterShort(2,Qty2,""); } private void GoShortSpread() { EnterShort(1,Qty1,""); EnterLong(2,Qty2,""); } private void CloseSpread() { if(//BarsInProgress==1 && Positions[1].MarketPosition==MarketPosition.Long) { ExitLong(); } else if(//BarsInProgress==2 && Positions[2].MarketPosition==MarketPosition.Short) { ExitShort(); } if(//BarsInProgress==1 && Positions[1].MarketPosition==MarketPosition.Short) { ExitShort(); } else if(//BarsInProgress==2 && Positions[2].MarketPosition==MarketPosition.Long) { ExitLong(); } return; }
I have been working with the previous guidance for opening and closing the spread.
When opening the spread, the method works smoothly but when closing, it closes only the primary instrument and not the hedge or secondary instrument.
I have tried the Positions[index] and also BarsInProgress == index conditions , but both ways it does not close the spread fully.
I have also tried to code the individual order handling using Order objects and tracking the orders in OnOrderUpdate and OnExecution methods, but the EnterLong() or short methods are working equally well. Also for spread trading, it is necessary to scalein and scale out, so keeping track of orders with Order object becomes complicated.
The Flatten() method works for closing the spread order but disables the strategy.
Can you offer a solution for properly closing a spread order?
Thanks.
Comment
-
Chelsea B.NinjaTrader Customer Service
- Likes 1
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
126 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