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

[amibroker] Re: Autotrading with IB Interface - help needed



PureBytes Links

Trading Reference Links

I suggest you keep and maintain a list of trade status yourself to
prevent redundant order submitting. IB has its limitations,
synchronization for one.
As for string match, type keyword "String manipulation" in ami's user
guide. you'll find what you need. :)

Hope above helps.
BR

--- In amibroker@xxxxxxxxxxxxxxx, "trustdnb" <trustdnb@xxx> wrote:
>
> I am attempting to use the autotrading interface for Interactive
> Brokers and am trying to keep the system from entering a new order if
> there is already an order in IB that is pending/partially filled/etc.
> 
> I wrote a quick loop to check for pending orders.  The loop iterates
> through the Pending list, and checks each symbol against the symbol
> for the current trade.  If the current symbol if found in the pending
> list then it sets the "check" flag to 1.  For some reason this does
> not work as intended.  
> 
> This is the relevant bit of code:
> 
> 	check = 0;
> 	symbols = ibc.GetPendingList( 1, "" );  
> 	for( i = 0; ( symbol = StrExtract( symbols, i ) ) != ""; i++ )
> 	{
>   		//printf("Symbol: " + symbol + "\n" );
> 		if (Name() == symbol) {check = 1;}
> 	}
> 
>       if( ibc.GetPositionSize( Name() ) == 0 && check == 0)
>        {	
>          ...[Enter Order]..
>        }
> 
> It seems that the value of "symbol" does not equal the value of
> "Name()" even when the current ticker is in the symbol list, though
> I'm not sure why.  Any guesses?  Alternatively, is there a "grep" type
> command in AFL?  
> 
> ///////////FULL CODE///////////////////////////
> 
> if( LastValue( Buy ) )
> {
>    ibc = GetTradingInterface("IB");
> 
>    // check if we are connected OK
>    if( ibc.IsConnected() )
>     {
> 
> 	//Check if current symbol already has an order pending
> 	check = 0;
> 	symbols = ibc.GetPendingList( 1, "" );  
> 	for( i = 0; ( symbol = StrExtract( symbols, i ) ) != ""; i++ )
> 	{
>   		//printf("Symbol: " + symbol + "\n" );
> 		if (Name() == symbol) {check = 1;}
> 	}
> 
>        // place order only if we do not have already open position on
> this symbol and no pending orders
> 
>       if( ibc.GetPositionSize( Name() ) == 0 && check == 0)
>        {		   
> 			OrderID = ibc.PlaceOrder(Name(), "BUY", LastValue( Shares ),
> "STOPLMT", LastValue( BuyPrice ) + Buy_slip, LastValue( BuyPrice ),
> "Day", False, 100 ); // place order but do not transmit yet
> 			//Enter protective stop on buy order
> 			ibc.PlaceOrder(Name(), "SELL", LastValue( Shares ), "STOPLMT",
> LastValue(BuyPrice) - LastValue( stop ) - Sell_slip,
> LastValue(BuyPrice) - LastValue( stop ), "GTC", False, 100, "",
> OrderID ); 	
> 
>        }
>     }
> }
>




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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/