Positions at broker into Scanner?

Questions about MultiCharts and user contributed studies.
ericvp
Posts: 30
Joined: 11 Jan 2012
Has thanked: 14 times
Been thanked: 6 times

Positions at broker into Scanner?

Postby ericvp » 03 Jul 2012

Hi All,

I would like to perform some calculations on positions I currently hold at my broker. I have no problem getting the broker position data I need (updated in real time) in a Multicharts Order and Position Tracker window. I don't anticipate any problem doing all the calculations I need to do in a Real-Time Market Scanner window. But, I can't figure out how to get the data from the Order and Position Tracker window over to the Real-Time Market Scanner window. I am hoping there is an easy way to do this that I haven't been able to find in the documentation or online.

Does anyone have any pointers or suggestions on how I might go about doing this?

Thanks!
Eric

Additional info:
(1) For my calculations, I need the following data from my broker: (i) the list of instrument names, (ii) quantity held (long or short), and (iii) average price paid. All other data (historical data, and real-time market data) I need, I can easily get in to the Real-Time Scanner (or perhaps into Portfolio Backtester, if that is a better way to go).
(2) I am not using Multicharts to drive the actual trading in this account.
(3) I typically have about 100 positions, so I can't use an approach that requires a chart per instrument, or manually entering instrument names.
(4) I'd like to avoid an approach that requires exporting the open positions data to a file and then importing that file into the scanner, if that loses the real time updating capability. But, if that is the only way to go, that is better than nothing.

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Positions at broker into Scanner?

Postby JoshM » 03 Jul 2012

ericvp wrote:(1) For my calculations, I need the following data from my broker: (i) the list of instrument names,

As far as I know, that can't be pulled from the broker through PowerLanguage. However, if you make an indicator that shows the current market position (see below), you could auto-sort the Real-time market scanner on this, so that it would be relatively easy to see which instrument has an open position and which not.


ericvp wrote:(ii) quantity held (long or short),

You could use the I_CurrentContracts and I_MarketPosition for this (when used in an indicator).

ericvp wrote: and (iii) average price paid.

You could use I_AvgEntryPrice, I_AvgEntryPrice_at_Broker, or I_AvgEntryPrice_at_Broker_for_the_Strategy for this (see this wiki page).

ericvp wrote:(2) I am not using Multicharts to drive the actual trading in this account.

In theory MultiCharts should be notified about the orders placed by another application, so the market position according to MultiCharts will then the same as the broker position (though this depends on correct symbol mapping settings).

I'm not sure though what the I_MarketPosition function will return then; the MultiCharts strategy position (which would be sure in such a case) or the broker position.

ericvp wrote:(3) I typically have about 100 positions, so I can't use an approach that requires a chart per instrument, or manually entering instrument names.

I thought it's possible to insert multiple instruments at once for the real-time market scanner, but I'm not sure.


An approach with an indicator that you may try is: (untested)

Code: Select all

Plot1(I_CurrentContracts * I_MarketPosition,    "Quantity");
Plot2(I_AvgEntryPrice_At_Broker,            "AvgEntryPrice");

(Which would be the indicator applied to the real-time market scanner).
These users thanked the author JoshM for the post:
ericvp

ericvp
Posts: 30
Joined: 11 Jan 2012
Has thanked: 14 times
Been thanked: 6 times

Re: Positions at broker into Scanner?

Postby ericvp » 03 Jul 2012

Thanks for suggesting this great approach, Josh. I think this will work well.

JoshM wrote:ericvp wrote:
(1) For my calculations, I need the following data from my broker: (i) the list of instrument names,

As far as I know, that can't be pulled from the broker through PowerLanguage. However, if you make an indicator that shows the current market position (see below), you could auto-sort the Real-time market scanner on this, so that it would be relatively easy to see which instrument has an open position and which not.

I see that the Real-Time Market Scanner will support up to 5000 Instruments, so I can just input the entire universe of potential Instruments into the list, and then sort based on a non-zero market position value at the broker, as you suggest. I'll make all the other calculations contingent on that non-zero value, so things don't bog down, and I don't hit the limits from my data providers.

Thanks!
Eric

ericvp
Posts: 30
Joined: 11 Jan 2012
Has thanked: 14 times
Been thanked: 6 times

Re: Positions at broker into Scanner?

Postby ericvp » 08 Jul 2012

I feel like I must be missing something obvious here.

When I attempt to use any of the functions suggested by JoshM, I do not seem to be able to pull data from my broker (IB). I am still able to pull all position information from my broker through the Multicharts Order and Position Tracker. But, I get "0" returned for each Instrument using using each of the following functions:
i_CurrentContracts
i_CurrentShares
i_MarketPosition
i_MarketPosition_at_Broker
i_AvgEntryPrice_at_Broker

After reviewing the documentation and searching online, I suspected something to do with Auto Trading being turned off. I do not see a way to turn it on from within the Real-Time Market Scanner. When I turned it on for one Instrument from within a Chart window in the same workspace, I still got zero values returned by the above functions.

Any thoughts on what I might be missing?
Eric

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Positions at broker into Scanner?

Postby JoshM » 09 Jul 2012

ericvp wrote:I feel like I must be missing something obvious here.

Nope, you're not missing anything. I'm mistaken here - the indicator reserved words (with I_ ... ) don't work in an indicator for the Market Scanner. That's quite a disappointment and a problem for your goal.

An alternative would be to create a chart for each instrument, and use a global variable to send the data from that chart to the market scanner - however that's not a real solution since you already said that's not doable for your situation/setup.

So I'm out of ideas, perhaps other users have an idea? Alternatively, you can wait for the portfolio trading to be implemented or you can add a feature request (you certainly would have my vote :) ) but this all is quite a lengthy road.
These users thanked the author JoshM for the post:
ericvp

ericvp
Posts: 30
Joined: 11 Jan 2012
Has thanked: 14 times
Been thanked: 6 times

Re: Positions at broker into Scanner?

Postby ericvp » 09 Jul 2012

JoshM, thanks for the response. I guess I'll go with my non-ideal plan B that requires an intermediary file output from my broker's software, and read in by Multicharts.

Like you, I am anxiously awaiting the Portfolio Trader functionality. I just hope they make it workable for portfolios on the order of 100 Instruments (ie, too large to have a chart per Instrument).

Thanks,
Eric
These users thanked the author ericvp for the post:
JoshM

Dru
Posts: 107
Joined: 28 Aug 2007
Has thanked: 4 times
Been thanked: 171 times

Re: Positions at broker into Scanner?

Postby Dru » 10 Jul 2012

A small MC .NET PR :-)
MultiCharts .NET will help you. There are low-level trading infrastructure ("PowerLanguage.TradeManager") accessible from any type of study. Access to trading capabilities of any broker (profile) and access to all trading events (order statuses, position's updates, connection states, etc.)
These users thanked the author Dru for the post (total 2):
JoshMTJ

ericvp
Posts: 30
Joined: 11 Jan 2012
Has thanked: 14 times
Been thanked: 6 times

Re: Positions at broker into Scanner?

Postby ericvp » 10 Jul 2012

I look forward to the MC .NET general availability, so I can check it out.

Thanks,
Eric


Return to “MultiCharts”