How do I manage my position like MQL5

IBPlugin is further development of TWSLink.It is focused for the useage with MetaTrader. But as it is a DLL, you can use it everywhere on Windows which supports DLL, e.g. in Trade Station or C++ applications or make wrapper for Perl, Python etc.

Users who just registered, please write an email to
forum@trade-commander.de
with your username mentioned.
So we can distinguish you from bots.
Thank you
Post Reply
hkenrique
Posts: 28
Joined: Tue Jul 28, 2020 3:23 pm

How do I manage my position like MQL5

Post by hkenrique »

Hi,

For example if I placed an order and there will be a position in MT5 broker. Then I'd be able to query the position info with
PositionInfoString(ENUM_INFO_STRING)
PositionInfoInteger(ENUM_INFO_INTEGER)

In IB it seems being handled in a different way, it's only possible to get the position in size number.
How can I retrieve the other info like position symbol, open price and profit and open date time?

Is it actually managed via order? This way am I supposed to use the Plugin's order function to retrieve my filled orders to calculate the positions by myself?

Thank you.

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: How do I manage my position like MQL5

Post by board_admin »

Hello,
with IB it works a bit differently.
To get a position, you need to know the symbol.

Code: Select all

ibgPOSITIONS(uidc...)
uidc is the symbol id.

Unfortunately, there is no information about time when you opened position.

Function

Code: Select all

ibgPORTFOLIO_INFO(uidc...)
provides some additonal information like
realized pnl
unrealized pnl
average price
Both must be considered with a certain caution from MetaTrader user perspective.
The realized p&l is the daily realized p&l.
The unrealized p&l referes to the current opened postions.

Both p&l are in underlying symbol currency not in account currency.
You may have to mind exchange rate.

So, you need to calculate p&l on your own.
MetaTrader provides quotes and exchange rates.
The plugin provides position and average price.

Please note:
In IB, you only have net positions. Per contract one position per account.

hkenrique
Posts: 28
Joined: Tue Jul 28, 2020 3:23 pm

Re: How do I manage my position like MQL5

Post by hkenrique »

Hello,

Thank you for the reply.

I guess this way to accurately monitor my position I will need to know the current filled order status.

I see the document that there is a function to query the pending orders

Code: Select all

ibgORDER_PENDING_LIST(1,7,0);
I wonder if there is function to list the filled orders (I then can retrieve the info of my, say, last filled order).
Thanks.

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: How do I manage my position like MQL5

Post by board_admin »

With new version >= 1.5.0.0 you do this:

Code: Select all

	// [#2] List all non zero positions:
	Print("+++ positions START");
	// create a snapshot of current non zero positions (resolution down to (sub-) account)
	int total_objects=ibgCREATE_POSITION_SNAPSHOT(__connection_id);
	Print("#positions=",total_objects );
	// list all positions by index
	for(int idx=0;idx < total_objects;++idx)
    {
		// print out a string fingerprint of positions (12 is id of position fingerprint;4 id of signed position;5 id of avg. entry price)		
		string fingerprint=ibgPOSITION_INFO_STR(idx,tcpi_str_dmp);
		Print(fingerprint);
		// to get double values returned use function <ibgPOSITION_INFO_DBL>
	}
	Print("--- positions END");
	

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: How do I manage my position like MQL5

Post by board_admin »

Orders that are not in the new pending list, are filled, cancelled or invalid.
If you have an uid, you can call:

Code: Select all

ibgORDER_STATUS(uid)
to get order status.

The order uid is a 64 bit integer.
On TradeStation / MultiCharts, you need to store it in a double variable.
On MetaTrader in a long variable.

Post Reply