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.
How do I manage my position like MQL5
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: How do I manage my position like MQL5
Hello,
with IB it works a bit differently.
To get a position, you need to know the symbol.
uidc is the symbol id.
Unfortunately, there is no information about time when you opened position.
Function
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.
with IB it works a bit differently.
To get a position, you need to know the symbol.
Code: Select all
ibgPOSITIONS(uidc...)
Unfortunately, there is no information about time when you opened position.
Function
Code: Select all
ibgPORTFOLIO_INFO(uidc...)
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
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
I wonder if there is function to list the filled orders (I then can retrieve the info of my, say, last filled order).
Thanks.
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);
Thanks.
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: How do I manage my position like MQL5
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");
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: How do I manage my position like MQL5
Orders that are not in the new pending list, are filled, cancelled or invalid.
If you have an uid, you can call:
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.
If you have an uid, you can call:
Code: Select all
ibgORDER_STATUS(uid)
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.