Code example for displaying UNREALIZED PnL for ALL open positions for 1 Account? - Traders Hideout | futures io social day trading
futures io futures trading


Code example for displaying UNREALIZED PnL for ALL open positions for 1 Account?
Updated: Views / Replies:4,032 / 31
Created: by vincentmarchi Attachments:4

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 4  
 
Thread Tools Search this Thread
 

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

  #21 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received


ratfink View 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.

Hi @resist

Unless you were doing historical testing?, it was only created as a live monitor.

Travel Well
Reply With Quote
The following user says Thank You to ratfink for this post:
 
  #22 (permalink)
Elite Member
ITAJAI SC/BRAZIL
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: Clear Corretora
Favorite Futures: DOLFUT, WINFUT
 
Posts: 184 since Jun 2014
Thanks: 760 given, 132 received

that would be nice


ratfink View Post

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.)

that would be nice

Reply With Quote
The following user says Thank You to MrTrader for this post:
 
  #23 (permalink)
Elite Member
Berlin Germany /Alicante Spain
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: DDT/Rithmic, Global/CQG, IB, Mirus(Ninja)/MarketDelta
Favorite Futures: Futures
 
Posts: 148 since Jan 2010
Thanks: 362 given, 66 received



ratfink View Post
Hi @resist


Unless you were doing historical testing?, it was only created as a live monitor.

@ratfink (I learned )
yes live with Topsteptrader account but I will retest it later with Sim101 account - should it work with Replay? I think so.

Reply With Quote
The following user says Thank You to resist for this post:
 
  #24 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received


resist View Post
@ratfink (I learned )
yes live with Topsteptrader account but I will retest it later with Sim101 account - should it work with Replay? I think so.

Yes, should do fine. Cheers.

Travel Well
Reply With Quote
The following user says Thank You to ratfink for this post:
 
  #25 (permalink)
Elite Member
Berlin Germany /Alicante Spain
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: DDT/Rithmic, Global/CQG, IB, Mirus(Ninja)/MarketDelta
Favorite Futures: Futures
 
Posts: 148 since Jan 2010
Thanks: 362 given, 66 received

@ratfink

if I put in my strategy (in OnBarUpdate() area)

{
rfkCList.set(Instrument.FullName, Close[0]);
}

would that be enough?

Reply With Quote
The following user says Thank You to resist for this post:
 
  #26 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received


resist View Post
@ratfink

if I put in my strategy (in OnBarUpdate() area)

{
rfkCList.set(Instrument.FullName, Close[0]);
}

would that be enough?

Yes, should be fine.

Travel Well
Reply With Quote
The following user says Thank You to ratfink for this post:
 
  #27 (permalink)
Elite Member
Berlin Germany /Alicante Spain
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: DDT/Rithmic, Global/CQG, IB, Mirus(Ninja)/MarketDelta
Favorite Futures: Futures
 
Posts: 148 since Jan 2010
Thanks: 362 given, 66 received


ratfink View Post
Yes, should be fine.

Thank you VERY MUCH. @ratfink

Short report:
I tried with Replay101 account and I think it works also if feed indicatr is in another chart than position indicator but position indicator has always to be started last.

It also works from strategy directly (see above) but I think itīs running out of sync.
If you restart position indicator and next restart strategy than it seems that it is sync and right values.

I also put in a position counter and average position calculation (total value / counter).

Just now I am thinking about calling position indicator directly in each strategy, but that would mean that position indicator is not started once but because I run multiple strategies (separate for long and short and as I told before separate for each contract) about 22 times.
Now I have doubts if there could occur problems with the global settings when position indicator is called more than one time.

I would call the indicator that way:
private rfkPositionMonitor ratfink; // Variables section
ratfink=rfkPositionMonitor ("Replay101"); // initialize section - account name I would make a get set later

What do you think about multiple times calling position indicator via strategy?

Reply With Quote
The following user says Thank You to resist for this post:
 
  #28 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received


resist View Post
Thank you VERY MUCH. @ratfink

Short report:
I tried with Replay101 account and I think it works also if feed indicatr is in another chart than position indicator but position indicator has always to be started last.

It also works from strategy directly (see above) but I think itīs running out of sync.
If you restart position indicator and next restart strategy than it seems that it is sync and right values.

I also put in a position counter and average position calculation (total value / counter).

Just now I am thinking about calling position indicator directly in each strategy, but that would mean that position indicator is not started once but because I run multiple strategies (separate for long and short and as I told before separate for each contract) about 22 times.
Now I have doubts if there could occur problems with the global settings when position indicator is called more than one time.

I would call the indicator that way:
private rfkPositionMonitor ratfink; // Variables section
ratfink=rfkPositionMonitor ("Replay101"); // initialize section - account name I would make a get set later

What do you think about multiple times calling position indicator via strategy?

The idea is that the position indicator only exists once, it should not be called from multiple places.

The feed indicator (or code) can be called any number of times, but is only required to be called once per instrument.

A synchronisation issue should only show up if some things are running COBC=false and some are running COBC=true, even then it will be a transient currency amount that your strategy positions would be experiencing anyway. Unless of course there are bugs to fix.

You can simply access the ongoing total value directly in your strategy e.g.:

 
Code
Print("Pos value " + rfkMonitor.totalValue);

Happy to work on developing this as we go, but it shouldn't need to be complicated.

Cheers

Travel Well
Reply With Quote
The following user says Thank You to ratfink for this post:
 
  #29 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received

Just checked in my setup, I have the Feeds running in COBC=false (this is the code default), otherwise price update can be delayed due to Ninja random chart/strat/indy processing order.

To get a test/illustration clear in your mind, do the following:

1) Make no changes to your existing strategies.

2) Create a separate Ninja Workspace, will be running in background.

3) Add two charts to this new workspace.

3a) To the first chart add one series for each of your instruments, e.g. 1min, or your t/f choice.
3b) To each instrument series in this chart add one feed indicator, making sure to select the correct series source each time. They will be invisible as Overlay is true and no plots are made.

4) Make the other chart of whatever series has the widest session span e.g. ES, again 1min or your t/f choice.
4a) Just add the positionMonitor to this other chart. If COBC is true (the code default) it will be a delayed position update at that bar, or if switched to false it will be a live rolling update.

You should see that the position total plots fine all the while regardless of when you start and stop strategies, or use ChartTrader.

If only one instrument is active you should see the the monitor value matches ChartTrader's value (can be in a third chart) so long as the monitor is switched to COBC=false. I left the default set at true to match strategies which are usually run in COBC=true.

Let me know if this helps.

Thought: If it is easier/better maybe use the Market Analyser route that @Tasker_182 suggested?

Edit: just realised you maybe can't get back the info you want that way, I don't know the MA hardly at all.

Cheers

Travel Well

Last edited by ratfink; August 9th, 2015 at 04:01 PM.
Reply With Quote
The following 3 users say Thank You to ratfink for this post:
 
  #30 (permalink)
Elite Member
Berlin Germany /Alicante Spain
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: DDT/Rithmic, Global/CQG, IB, Mirus(Ninja)/MarketDelta
Favorite Futures: Futures
 
Posts: 148 since Jan 2010
Thanks: 362 given, 66 received


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

Reply With Quote
The following user says Thank You to resist for this post:

Reply



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

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to track outside account positions in TWS? swinger IB Trader Workstation 1 February 18th, 2015 01:51 AM
Only Close Open Positions? davetapson AmiBroker 0 September 23rd, 2014 04:59 AM
Open Traders Positions Athan The Elite Circle 10 March 31st, 2013 01:29 AM
Displaying net PNL patbateman NinjaTrader 0 September 30th, 2012 09:02 PM
Account position: How to differentiate positions arjfca The Elite Circle 5 February 5th, 2011 03:27 PM


All times are GMT -4. The time now is 02:37 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-14 in 0.15 seconds with 40 queries on phoenix via your IP 54.221.76.68