not sure, what are you trading? Forex? Because there is a problem when your ticksize is less than 0.0001. In this case like I said best to use 0.5 or 1 instead of round( TickSize * 10000 ).
personally I do not have this issue with the order status. I currently trade futures only and the ticksize is always greater than 0.0001
I can give you code I use below. This is basically copied from what Tomasz put in http://www.amibroker.com/at/
see code below. So this code I call for instance to sell 1 future I call:
ibc = GetTradingInterface( "IB" );
ps = ibc.GetPositionSize( StaticVarGetText( "symbol" + cid ) );
sendOrder_proc( StaticVarGetText( "symbol" + cid ), StaticVarGet( "transmitOnOffFlag" + cid ),
ps - 1, StaticVarGet( "tz" + cid ), LastValue( C ), LastValue( C ), cid, StaticVarGetText( "MKToLMT" + cid ) );
Say( "Sell 1 Future" );
to add 1 future I call:
ibc = GetTradingInterface( "IB" );
ps = ibc.GetPositionSize( StaticVarGetText( "symbol" + cid ) );
sendOrder_proc( StaticVarGetText( "symbol" + cid ), StaticVarGet( "transmitOnOffFlag" + cid ),
ps + 1, StaticVarGet( "tz" + cid ), LastValue( C ), LastValue( C ), cid, StaticVarGetText( "MKToLMT" + cid ) );
Say( "Add 1 Future" );
to close the position I call:
ibc = GetTradingInterface( "IB" );
ps = ibc.GetPositionSize( StaticVarGetText( "symbol" + cid ) );
sendOrder_proc( StaticVarGetText( "symbol" + cid ), Nz( StaticVarGet( "transmitOnOffFlag" + cid ) ),
0, StaticVarGet( "tz" + cid ), LastValue( C ), LastValue( C ), cid, StaticVarGetText( "MKToLMT" + cid ) );
Say( "Close Position" );
so this just as an example what I do
procedure sendOrder_proc( symb, transmitOnOffFlag, pstn, tz, ask_pp, bid_pp, cidi, orderType )
{
//_TRACE( "tz: " + tz );
// launch IB controller
ibc = GetTradingInterface( "IB" );
// check if we are connected OK
if( ibc.IsConnected() )
{
ps = ibc.GetPositionSize( symb );
// calculate number of shares
nos = pstn - ps;
// transaction price
ask_price = ask_pp;
bid_price = bid_pp;
if( orderType == "MKT" )
{
ask_price = 0;
bid_price = 0;
}
else
if( orderType == "LMT" )
{
ask_price = ask_pp;
bid_price = bid_pp;
}
if( nos > 0 )
{
// retrieve orderID from previous run, will be empty if no order was placed before
OrderID = StaticVarGetText( "OrderID" + cidi );
// place order
if( ibc.IsOrderPending( OrderID ) )
{
OrderID = ibc.ModifyOrder( OrderID, symb, "BUY", nos, orderType, ask_price, 0, "Day", transmitOnOffFlag, tz );
}
else
{
OrderID = ibc.PlaceOrder( symb, "BUY", nos, orderType, ask_price, 0, "Day", transmitOnOffFlag, tz );
}
// store orderID for next run so we know which order to modify
StaticVarSetText( "OrderID" + cidi, OrderID );
}
else
if( nos < 0 )
{
// retrieve orderID from previous run, will be empty if no order was placed before
OrderID = StaticVarGetText( "OrderID" + cidi );
// place order
if( ibc.IsOrderPending( OrderID ) )
{
OrderID = ibc.ModifyOrder( OrderID, symb, "SELL", abs( nos ), orderType, bid_price, 0, "Day", transmitOnOffFlag, tz );
}
else
{
OrderID = ibc.PlaceOrder( symb, "SELL", abs( nos ), orderType, bid_price, 0, "Day", transmitOnOffFlag, tz );
}
// store orderID for next run so we know which order to modify
StaticVarSetText( "OrderID" + cidi, OrderID );
}
}
}