NexusFi: Find Your Edge


Home Menu

 





Code example for displaying UNREALIZED PnL for ALL open positions for 1 Account?


Discussion in Traders Hideout

Updated
      Top Posters
    1. looks_one ratfink with 9 posts (15 thanks)
    2. looks_two resist with 8 posts (10 thanks)
    3. looks_3 vincentmarchi with 5 posts (0 thanks)
    4. looks_4 gregid with 5 posts (7 thanks)
      Best Posters
    1. looks_one Tasker_182 with 4 thanks per post
    2. looks_two ratfink with 1.7 thanks per post
    3. looks_3 gregid with 1.4 thanks per post
    4. looks_4 resist with 1.3 thanks per post
    1. trending_up 21,520 views
    2. thumb_up 38 thanks given
    3. group 6 followers
    1. forum 32 posts
    2. attach_file 4 attachments




 
Search this Thread

Code example for displaying UNREALIZED PnL for ALL open positions for 1 Account?

  #31 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426


resist View Post
I am working a lot backtesting my strategies using your indicator and I can confirm that itīs working fine if you start strategy (of course) after starting indicator. I have still position and feed in one multichart together, strategies are taking the global variable of totalvalue.

Working with MA makes no sense to me because I need the total value or average value in my strategy (I also added a calculation for average value as global variable, itīs working, too but has not improved strategy).

As I made some interesting observations my question to you:
Could you add a second account - I would like to test opening "dummy" positions on SIM parallel with real account. I think you got my question, if not, again: I want to open e.g. YM, CL, ES trades on SIM and CL on trading account but I need the total of all 4 positions.

Thank you again. @ratfink

Great, and a nice idea too, all we need is to make the totalValue into a per account list, I'll post a version.

Cheers

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
About a successful futures trader who didnt know anythin …
Psychology and Money Management
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #32 (permalink)
 resist 
Berlin Germany /Alicante Spain
 
Experience: Intermediate
Platform: NinjaTrader
Broker: DDT/Rithmic, Global/CQG, IB, Mirus(Ninja)/MarketDelta
Trading: Futures
Posts: 141 since Jan 2010
Thanks Given: 362
Thanks Received: 67

@ratfink,
I think we (you) do not need to make it working parallel on 2 acounts, I can calculate all (e.g. YM, ES, NQ and CL) together on SIM account with strategy - and run a trading strategy only trading CL on real account - only a sample. Only extra work is to have two charts with CL strategy running, one SIM one real - so everything can stay as it is, take your time for better ideas. )))

Reply With Quote
Thanked by:
  #33 (permalink)
trades4x
Vermont
 
Posts: 24 since Oct 2018
Thanks Given: 21
Thanks Received: 19



vincentmarchi View Post
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:

 
Code
double allPositions = 0;
foreach (Position position in Account.Positions)
{
    allPositions += position.GetProfitLoss(Close[0], PerformanceUnit.Currency);
	
}
		
Print("TotalUnrealized: " +allPositions.ToString()  );

Does this code go in OnBarUpdate or onExecutionUpdate?

Reply With Quote




Last Updated on March 21, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts