Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Code example for displaying UNREALIZED PnL for ALL open positions for 1 Account?
I am trying to get the UNREALIZED PnL of all instruments that have an open trade for instance - I have 6E open trade that at this current tick is at +$100 and I also have ES open at -$75 then I want to show the currentTotalUnrealizedPnL = +$25
Your second code snippet looks almost like what I need except that the calculation is going way off when I have a second position open in another instrument please see me screenshot below of the output of the code. This code:
The problem seems to be that it takes the Close[0] from current strategy (and its instrument) and applies the calculation to other instruments. For this to work you would have to provide the right close from right instrument for each of positions. At the moment I see no other way than by using multi instrument strategy with multiple bar series. I'll try to think if there is any alternative option tomorrow as I am now getting close to horizontal...
Still need to figure out a way to calculate the UNREALIZED profit 4 multiple instruments... any ideas or directions would be appreciated. I've hunted and hunted and tried alot of my own code, but I can't seem to get this. I must be missing something. Can someone please assist or if there is anyone else who has already done this, please let me know. Thanks so much! The basic idea is to have all trades close out when the total PnL is > $1,000 automatically so I don't have to calculate in my head when I have 4-5 trades open at once across multiple instruments and wont miss the opportunity to take the profit.
Still need to figure out a way to calculate the UNREALIZED profit 4 multiple instruments... any ideas or directions would be appreciated. I've hunted and hunted and tried alot of my own code, but I can't seem to get this. I must be missing something. Can someone please assist or if there is anyone else who has already done this, please let me know. Thanks so much! The basic idea is to have all trades close out when the total PnL is > $1,000 automatically so I don't have to calculate in my head when I have 4-5 trades open at once across multiple instruments and wont miss the opportunity to take the profit.
have you tried adding multiple instruments as suggested in my second post?
have you tried adding multiple instruments as suggested in my second post?
Oh so like, add all 7 instruments I'm trading to a single chart and add the strategy to that chart and try to pull each unrealized PnL separately and sum them in a variable? I will try to work on that today to see how that works. I was not aware I could add a bunch of instruments to a chart. Figured that would look really weird. heh!
Oh so like, add all 7 instruments I'm trading to a single chart and add the strategy to that chart and try to pull each unrealized PnL separately and sum them in a variable? I will try to work on that today to see how that works. I was not aware I could add a bunch of instruments to a chart. Figured that would look really weird. heh!
What you need to do is provide the right price (Close[0]) for the instrument.
So in your code in the loop you will do something like (pseudocode):
double currentPrice = 0;
if (position.Instrument.Name == "ES") currentPrice = Closes[0][0];
if (position.Instrument.Name == "6E") currentPrice = Closes[1][0];
if (position.Instrument.Name == "6A") currentPrice = Closes[2][0];
allPositions += position.GetProfitLoss(currentPrice, PerformanceUnit.Currency);
Search for multiinstrument strategies or indicators to learn how to add secondary series - these will be invisible, ie not visible on the chart so you don't need to worry about weird looking chart