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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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
-
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 wzgy0920, 04-20-2024, 06:09 PM
|
2 responses
27 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:43 PM
|
||
Started by wzgy0920, 02-22-2024, 01:11 AM
|
5 responses
32 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:33 PM
|
||
Started by wzgy0920, 04-23-2024, 09:53 PM
|
2 responses
49 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:29 PM
|
||
Started by Kensonprib, 04-28-2021, 10:11 AM
|
5 responses
193 views
0 likes
|
Last Post
by Hasadafa
Yesterday, 10:19 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
11 responses
3,235 views
0 likes
|
Last Post Yesterday, 08:07 PM |
Comment