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,305 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?

  #11 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623

Here is the reference in NT help guide:
NinjaTrader Version 7

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Deepmoney LLM
Elite Quantitative GenAI/LLM
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Futures True Range Report
The Elite Circle
ZombieSqueeze
Platforms and Indicators
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
Battlestations: Show us your trading desks!
26 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
  #12 (permalink)
 
vincentmarchi's Avatar
 vincentmarchi 
Dallas Texas United States
 
Experience: Master
Platform: NinjaTrader
Trading: Emini ES, Crude CL, Gold GC, Currency Futures
Posts: 9 since Feb 2013

My brother, you are the bomb diggity dizzle! Thank you for the direction! I will work on this and post results when I get it working! Thank you soooo much! Genius!

Follow me on Twitter Started this thread Reply With Quote
  #13 (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



vincentmarchi View Post
My brother, you are the bomb diggity dizzle! Thank you for the direction! I will work on this and post results when I get it working! Thank you soooo much! Genius!

Have you found a way to show total unrealized P/L of all actual open positions in NinjaTrader and could you provide a code snippet?
I try to run several (about 10) charts with automated strategy on each and I want to track the total P/L if all position together every minute, first for statistic, later I want to change strategies to stop trading.

As I read here I could code a multiinstrument strategy but I think that s very difficult for me, therefore I want first only to track open P/L to the output window or a dataseries or something else similar.

Reply With Quote
Thanked by:
  #14 (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

here is a picture what I mean, I want to track the total profit of this minute 23:

then I get minute 24:

and next next next minute - so I get a picture how PnL was developing until closing strategies automatically.

Reply With Quote
Thanked by:
  #15 (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,425


resist View Post
so I get a picture how PnL was developing until closing strategies automatically.

Had a quick go at this and a basic solution seems to work quite well.

The attached file includes two indicators, rfkPositionMonitor that you add to any one single chart, it will plot a value for the combined currency total of open positions and report to the output window on each bar close. Assumes the chart session spans all others, your choice of timeframe, I've used 1 minute for testing here.

You need to specify the account name to monitor in the Parameters section, default is Sim101.

The second is a slave feed indicator (rfkPositionFeed) that you add to one chart of any instrument you wish to monitor, it simply provides a global feed of closing price for the monitor to use. Alternatively you could just cut and paste the rfkCList.set line into your strategy then you don't need the feed indicator.

The totalValue is global so can be accessed wherever you want.

Have a look/play and we can discuss problems or ways to go or just do your own thing if it's a good enough base. It seems to work fine but treat as Alpha code, I will start a support thread if required, or you may just want to cut/paste code into strategies and/or your own monitor scheme instead.

Cheers

Travel Well
Attached Files
Elite Membership required to download: rfkPositionMonitor_1_0A1.zip
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #16 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


resist View Post
Have you found a way to show total unrealized P/L of all actual open positions in NinjaTrader and could you provide a code snippet?
I try to run several (about 10) charts with automated strategy on each and I want to track the total P/L if all position together every minute, first for statistic, later I want to change strategies to stop trading.

As I read here I could code a multiinstrument strategy but I think that s very difficult for me, therefore I want first only to track open P/L to the output window or a dataseries or something else similar.

Why not just use the Market Analyzer? You can add columns to show realized and unrealized, current position, position size as well as a totaling row.


Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
Thanked by:
  #17 (permalink)
 MrTrader 
ITAJAI SC/BRAZIL
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Clear Corretora
Trading: DOLFUT, WINFUT
Posts: 332 since Jun 2014
Thanks Given: 1,314
Thanks Received: 225

@Tasker_182, with MA you cannot disable trading automatcally, by bots. At least until NT8 I believe.

@ratfink, I hope test it too.
Do we have to declare any using clause before adding to a strategy that line you suggested ?

Reply With Quote
Thanked by:
  #18 (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,425


MrTrader View Post
@Tasker_182, with MA you cannot disable trading automatcally, by bots. At least until NT8 I believe.

@ratfink, I hope test it too.
Do we have to declare any using clause before adding to a strategy that line you suggested ?

Nope. Just refer to it using the class name prefix, same as in the indycode.

In fact I just realised you can probably call the existing indicators directly from strategies but i haven't tested it. Irrelevant as they're just guinea/pounds pigs/fowl or whatever.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #19 (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 tested it. itīs a great step in the right direction ithink. thank you.

You have to open a multi instrument chart and to put in the feed indicator for each instrument once in that multiindicator chart, also position indicator once, than it works.

I added to the position indicator a snippet to print an output of the total open profit to output window, too. That works already, too.

to add one line to my strategies or to add the feed indicator in the also on my workspace opened 11 single instrument charts didnīt work, feed and position have to be in same chart. nd there has to be a feed with input of each instrument.

Next step is the question how to tell my strategies to TP or SL (betteer to §close§) all open positions when a profit threshold (depending also on the quantity of positions) is hit - wilkl be difficult I think.

Is here somewhere a thred where somebody else tried that?

Reply With Quote
Thanked by:
  #20 (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,425



resist View Post
@ ratfink

I tested it. itīs a great step in the right direction ithink. thank you.

You have to open a multi instrument chart and to put in the feed indicator for each instrument once in that multiindicator chart, also position indicator once, than it works.

I added to the position indicator a snippet to print an output of the total open profit to output window, too. That works already, too.

to add one line to my strategies or to add the feed indicator in the also on my workspace opened 11 single instrument charts didnīt work, feed and position have to be in same chart. nd there has to be a feed with input of each instrument.

Next step is the question how to tell my strategies to TP or SL (betteer to §close§) all open positions when a profit threshold (depending also on the quantity of positions) is hit - wilkl be difficult I think.

Is here somewhere a thred where somebody else tried that?

Hi @resist, Glad you found it a useful start.

I have no idea why you don't see it working when feed and monitor are in different charts, that's how this was tested and I run loads of my own other similar stuff, both single and multi-threaded, with no problems.

The only issue to be aware of is if you are editing and recompiling anything then all instances in active charts/strats need an F5 so they get to use the same assembly. Otherwise just opening closing workspaces, adding and removing indicators or whatever works as normal.

Communication back to the strategy is easy too, I can add an example of that when I am next on PC (ChromeBook only at moment.)

Cheers

[nb no space in futures.io (formerly BMT) user name notifications eg @ratfink]

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




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