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.
The following user says Thank You to resist for this post:
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.
The following 3 users say Thank You to ratfink for this post:
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?
The following 2 users say Thank You to resist for this post:
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.)
[nb no space in futures.io (formerly BMT) user name notifications eg @ratfink]
The following 2 users say Thank You to ratfink for this post: