Managing multiple positions - is there a "comment" field in position?
Managing multiple positions - is there a "comment" field in position?
Hello,
I am trying to manage multiple positions in IB, where ibgCREATE_POSITION_SNAPSHOT seems to present a nice realization.
Now, I need to be able to differentiate the positions created by different strategies, they can be of the same symbol or different symbols.
In MT5 I normally use magic number but I do not see it in the IB system.
I am thinking about using "comment" in the OrderSend function which will write to Order Reference in IB system.
But is there a way I can retrieve this "comment" from the position functions (through ibgPOSITION_INFO_XXX functions)? Or there is another way to realize this? like __conid or sth else?
Thank you.
I am trying to manage multiple positions in IB, where ibgCREATE_POSITION_SNAPSHOT seems to present a nice realization.
Now, I need to be able to differentiate the positions created by different strategies, they can be of the same symbol or different symbols.
In MT5 I normally use magic number but I do not see it in the IB system.
I am thinking about using "comment" in the OrderSend function which will write to Order Reference in IB system.
But is there a way I can retrieve this "comment" from the position functions (through ibgPOSITION_INFO_XXX functions)? Or there is another way to realize this? like __conid or sth else?
Thank you.
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: Managing multiple positions - is there a "comment" field in position?
A position is an accumulation of executions.
There is always only one position per Symbol.
ibgORDER_SEND_STR
has a field where you can set a comment. This comment is pegged to order (and execution).
The atribute identfier is 49 -> see help of IBPlugin.
But you can not peg a comment to a position.
There is always only one position per Symbol.
ibgORDER_SEND_STR
has a field where you can set a comment. This comment is pegged to order (and execution).
The atribute identfier is 49 -> see help of IBPlugin.
But you can not peg a comment to a position.
Re: Managing multiple positions - is there a "comment" field in position?
Hi,
Thanks that has answered my question.
Thanks that has answered my question.
Re: Managing multiple positions - is there a "comment" field in position?
Hi,
Continuing our discussion about the comment field.
So I sent an order with some comment but it seems I cannot get the comment with
Order Info: comment:, pid:-703489356
Comment is empty. But I was able to get the comment in previous version before the 2020 Sep upgrade.
I can see my comment written into Order Ref in IB TWS. It's within the 9~ field (the value of my comment is: 10005,1610646493) :
Order Ref: |0~348364093889204|1~0|2~12087792|3~100000|4~ibg|6~|9~10005,1610646493
Please let me know if anything is not correct here.
Thanks.
Continuing our discussion about the comment field.
So I sent an order with some comment but it seems I cannot get the comment with
the output is:
string comment=ibgORDER_INFO_STR(i,49); //comment of order
long pid=ibgORDER_INFO_INT64(i,55); //pid of order
PrintFormat("Order Info: comment:%s, pid:%d",comment,pid);
Order Info: comment:, pid:-703489356
Comment is empty. But I was able to get the comment in previous version before the 2020 Sep upgrade.
I can see my comment written into Order Ref in IB TWS. It's within the 9~ field (the value of my comment is: 10005,1610646493) :
Order Ref: |0~348364093889204|1~0|2~12087792|3~100000|4~ibg|6~|9~10005,1610646493
Please let me know if anything is not correct here.
Thanks.
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: Managing multiple positions - is there a "comment" field in position?
This function makes only sense, when prior called:
Have you done this ?
Code: Select all
ibgCREATE_PENDING_ORDER_SNAPSHOT
Re: Managing multiple positions - is there a "comment" field in position?
Hi,
Yes I have done this but cannot retrieve the comment.
full code:
Yes I have done this but cannot retrieve the comment.
full code:
Code: Select all
int orderNum=ibgCREATE_PENDING_ORDER_SNAPSHOT(IB_PLUGIN_DEF_CONNID,__conid,1);
for(int i=0;i<orderNum;++i)
{
string comment=ibgORDER_INFO_STR(i,49); //comment of order
unsigned long pid=ibgORDER_INFO_INT64(i,55); //pid of order
PrintFormat("Order Info: comment:%s, pid:%d",comment,pid);
}
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: Managing multiple positions - is there a "comment" field in position?
Are you sure there are strict pending orders for that conid ?
Strict means, you can see them in TWS with one of the pending status colors (blue,green)
Strict means, you can see them in TWS with one of the pending status colors (blue,green)
Re: Managing multiple positions - is there a "comment" field in position?
Yes you can see my loop is able to retrieve the parent order id of the orders (490385839). but comment is void:
CS 0 00:34:41.005 HFTLiteClassicIB (EURUSD,M1) CONNECTIONID: 1
MF 0 00:34:41.006 HFTLiteClassicIB (EURUSD,M1) Order Info: comment:, pid:490385839
NR 0 00:34:41.006 HFTLiteClassicIB (EURUSD,M1)
CF 0 00:34:41.006 HFTLiteClassicIB (EURUSD,M1) Order Info: comment:, pid:490385839
DS 0 00:34:41.006 HFTLiteClassicIB (EURUSD,M1)
CS 0 00:34:41.005 HFTLiteClassicIB (EURUSD,M1) CONNECTIONID: 1
MF 0 00:34:41.006 HFTLiteClassicIB (EURUSD,M1) Order Info: comment:, pid:490385839
NR 0 00:34:41.006 HFTLiteClassicIB (EURUSD,M1)
CF 0 00:34:41.006 HFTLiteClassicIB (EURUSD,M1) Order Info: comment:, pid:490385839
DS 0 00:34:41.006 HFTLiteClassicIB (EURUSD,M1)
Re: Managing multiple positions - is there a "comment" field in position?
Hi,
I also tested the code:
comment = ibgORDER_ATTRIBUTE(IB_PLUGIN_DEF_CONNID,orderId,10);
this code works in the old version to retrieve the comment but seems not working in the new version any more.
I suspect there is some defect in the dll.
It's an important function for me so please take a look.
I also tested the code:
comment = ibgORDER_ATTRIBUTE(IB_PLUGIN_DEF_CONNID,orderId,10);
this code works in the old version to retrieve the comment but seems not working in the new version any more.
I suspect there is some defect in the dll.
It's an important function for me so please take a look.
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: Managing multiple positions - is there a "comment" field in position?
There are in fact some changes to version of last year.
Please use the help. it was thoroughly revised.
For order attributes, the attribute table is what matters.
I could not reproduce the problem. I get the order comment returned correctly with attribute id = 49.
This function call
should return order comment, always presumed it is still pending.
Seems you are using MetaTrader. Please mind, the uid is long (64 bit signed integer) not unsigned long.
This attribute string for ibgORDER_SEND_STR sets comment to "my_comment"
This, makes no sense for your purpose
Because 10 is block order flag. Just pass 49,as above to get comment.
Mind the orderid. In your code you query orderid by
which is wrong because this is the uid of the parent order.
What you should pass is the 1011, the code for uid.
>>Please apologize the mess in the ids. <<
Each function that refers somehow to an order attribute, uses the same order attribute table.
Please use the help. it was thoroughly revised.
For order attributes, the attribute table is what matters.
I could not reproduce the problem. I get the order comment returned correctly with attribute id = 49.
This function call
Code: Select all
string comment=ibgORDER_INFO_STR(i,49);
Seems you are using MetaTrader. Please mind, the uid is long (64 bit signed integer) not unsigned long.
This attribute string for ibgORDER_SEND_STR sets comment to "my_comment"
Code: Select all
"#1=50000#53=BUY#6=LMT#49=my_comment#2=1.17"
Code: Select all
comment = ibgORDER_ATTRIBUTE(IB_PLUGIN_DEF_CONNID,orderId,10);
Mind the orderid. In your code you query orderid by
Code: Select all
long pid=ibgORDER_INFO_INT64(i,55); //p
What you should pass is the 1011, the code for uid.
>>Please apologize the mess in the ids. <<
Each function that refers somehow to an order attribute, uses the same order attribute table.
Re: Managing multiple positions - is there a "comment" field in position?
thank you for your detailed explanation.
maybe it's something with my order send function that caused the comment cannot be retrieved?
my code that sends the order:
order_send definition:
maybe it's something with my order send function that caused the comment cannot be retrieved?
my code that sends the order:
Code: Select all
long uid= __ib.order_send(__conid_EURUSD
,ibOrderType // defined in file include/trade-commander.com/ibplugin_types.mqh
,size
,0
,targetPrice
,stopLossPrice
,takeProfitPrice
,comment
,0
,0);
Code: Select all
long order_send(int uid_symbol
,ENUM_ORDER_TYPE cmd
,int shares
,double lmt_price=0.0
,double stp_price=0.0
,double stop_loss=0.0
,double take_profit=0.0
,string comment=""
,int id_allocation=0
,color arrow_color=clrNONE)
{
if(IsTesting == false)
{
if(uid_symbol < 0)
uid_symbol=_uidc;
string action="";
string otype="";
MT_OTYPE_TO_IB(cmd,action,otype);
long ticket= ibgORDER_SEND (_connectionid, uid_symbol,action,otype,shares,lmt_price,stp_price,stop_loss,take_profit, comment,id_allocation);
if(arrow_color != clrNONE)
{
}
return ticket;
}
else
return -1;
}
Last edited by hkenrique on Fri Jan 15, 2021 1:29 pm, edited 1 time in total.
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: Managing multiple positions - is there a "comment" field in position?
What is not working with your code ?
Re: Managing multiple positions - is there a "comment" field in position?
I'm just trying to find out why my comment cannot be retrieved.
If you don't see a problem of the above order send function then probably it's fine.
If you don't see a problem of the above order send function then probably it's fine.
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: Managing multiple positions - is there a "comment" field in position?
I checked it always outside MetaTrader and got the comment with both function calls.
But when testing in MetaTrader, i also get no comment returned.
Sorry for this. Need to investigate.
But when testing in MetaTrader, i also get no comment returned.
Sorry for this. Need to investigate.
Re: Managing multiple positions - is there a "comment" field in position?
thanks. I will stick with the old version for now.
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: Managing multiple positions - is there a "comment" field in position?
Dont do this please. It works differently.
The problem seems only to be in function ibgORDER_SEND in MetaTrader.
Just use
instead or wait for fix.
MetaTrader has a convenient string implementation
which allows to easily create the attribute string for this function
using StringFormat function or just the + operator;
Help for this function with link for table of attributes:
file:///C:/Program%20Files/trade-commander.com/IBPlugin/documentation/fct_ibgORDER_SEND_STR.html
-----
Just stick with the ibplugin_demo, where i skipped the wrapper
and use direct DLL calls. This is most transparent.
In the attribute string, the comment is introduced by:
This way, you should be able to get the comment returned without
using old version.
The problem seems only to be in function ibgORDER_SEND in MetaTrader.
Just use
Code: Select all
ibgORDER_SEND_STR
MetaTrader has a convenient string implementation
which allows to easily create the attribute string for this function
using StringFormat function or just the + operator;
Help for this function with link for table of attributes:
file:///C:/Program%20Files/trade-commander.com/IBPlugin/documentation/fct_ibgORDER_SEND_STR.html
-----
Just stick with the ibplugin_demo, where i skipped the wrapper
and use direct DLL calls. This is most transparent.
In the attribute string, the comment is introduced by:
Code: Select all
#49=My Comment
using old version.
-
- Site Admin
- Posts: 244
- Joined: Mon Apr 24, 2017 3:24 pm
Re: Managing multiple positions - is there a "comment" field in position?
New version uploaded:
https://trade-commander.com/de/ibpluginsetup/
Just over install, make sure MetaTrader closed before installation.
Please checkout, if you get comment and let me know. Thank you.
https://trade-commander.com/de/ibpluginsetup/
Just over install, make sure MetaTrader closed before installation.
Please checkout, if you get comment and let me know. Thank you.
Re: Managing multiple positions - is there a "comment" field in position?
Hi,
It works now. Thanks a lot for the help.
It works now. Thanks a lot for the help.