[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] IBc GetPositionSize Question



PureBytes Links

Trading Reference Links


Hello,

I try to follow the last example in IBc readme. It seems that 
GetPositionSize method reports correct positon size for stock, but 
always returns 0 for a futures contact. Any one has same problem?

The example codes:

// Param block 
TriggerOrder= ParamTrigger("Place order","Click here to place 
order"); 
Mode=ParamToggle("Mode","Modify existing|Always place new order"); 
ACT = ParamList("Action", "BUY|SELL|SSHORT"); 
OT = ParamList("Order Type", "MKT|LMT|STP"); 
TIF = ParamList("Time In Force", "DAY|GTC|IOC"); 
Ticker = ParamStr("Ticker",Name()); 
NumShares = Param("Number of Shares",10,10,100,10); 
LimitPrice = LastValue(C) + Param("Limit Price offset",0,-
0.1,0.1,0.01); 
StopPrice = LastValue(C) + Param("Stop price offset",0,-
0.1,0.1,0.01); 
Transmit = ParamToggle("Transmit","Do NOT transmit|Transmit",0); 
TriggerCancel = ParamTrigger("Cancel Order","Click here to Cancel 
order"); 

Msg = ""; // this variable stores error message text 

// create instance of trading interface 
ibc = GetTradingInterface("IB"); 

// retrieve orderID from previous run, will be empty if no order was 
placed before 
OrderID = StaticVarGetText("OrderID"+Ticker); 

if( TriggerOrder ) 
{ 
// check if we are connected OK 
if( ibc.IsConnected() ) 
{ 
   if( Mode == 1 ) OrderID = ""; // if mode set to 'always new' then 
clear orderid 

   // place orders only if we do not have already open position on 
this symbol 
   // place or modify the order - don't transmit yet 
   OrderID = ibc.ModifyOrder( OrderID, Ticker, 
         ACT, NumShares, OT, LimitPrice, StopPrice, TIF, Transmit); 
   

   // store orderID for next run so we know which order to modify 

   StaticVarSetText("OrderID"+Ticker, OrderID); 
   
   if( Mode == 1 ) 
       Msg = "New order has been placed with ID = "; 
   else 
       Msg = "Order placed/modified with ID = "; 

   Msg = Msg + OrderID + " on " + Now(); 
} 
else 
{ 
   Msg = "Placing order failed because of no connection to TWS"; 
} 
} 

if( TriggerCancel ) 
{ 
  if( OrderId != "" ) 
   { 
    if( ibc.CancelOrder( OrderId ) ) 
       Msg = "Request to cancel order " + OrderID + " sent 
successfully"; 
    else 
       Msg = "Request to cancel order " + OrderID + " failed."; 
   } 
  else 
     Msg = "Can not cancel order becase OrderID is empty"; 

} 

// monitoring code 
Title = 
Msg + 
"\nLast TWS message: "+ ibc.GetLastError(0) + 
"\nAvailable funds: " + ibc.GetAccountValue("AvailableFunds")+ 
"  Gross Pos. Value: " + ibc.GetAccountValue("GrossPositionValue")+ 
"\nOrderID = "+OrderId+ 
"\nTicker = "+Ticker+ 
"\nAction = "+ACT+ 
"\nShares = "+NumToStr(NumShares,1.0)+ 
"\nOrderType = "+OT+ 
"\nLimitPrice = "+NumToStr(LimitPrice,1.3)+ 
"\nStopPrice = "+NumToStr(StopPrice,1.3)+ 
"\nTimeInForce= "+TIF+ 
"\nTransmit = "+NumToStr(Transmit,1.0)+"\n"+ 
"\nGetStatus = "+ibc.GetStatus( OrderID )+ 
"\nGetPositionSize = "+ibc.GetPositionSize( Ticker )+ 
"\nIsConnected = "+NumToStr(ibc.IsConnected(),1.0); 






------------------------ Yahoo! Groups Sponsor --------------------~--> 
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/