Page 1 of 1

How do I manage my position like MQL5

Posted: Thu Aug 13, 2020 4:15 pm
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.

Re: How do I manage my position like MQL5

Posted: Fri Aug 14, 2020 10:09 am
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.

Re: How do I manage my position like MQL5

Posted: Fri Aug 14, 2020 2:58 pm
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.

Re: How do I manage my position like MQL5

Posted: Fri Sep 04, 2020 11:37 am
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");
	

Re: How do I manage my position like MQL5

Posted: Fri Sep 04, 2020 6:46 pm
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.