I have a simple trading system. Want to develop a auto trading code from Amibroker to TWS (Traders Workstation). The code I have is not working or placing several buy and sell signal. Description of the trading system: When 2 period EMA (Exponential Moving Average) crosses above 5 period EMA buy. When 2 period EMA crosses below 5 period EMA sell. Period: 30 minutes Trade US equities (Example: Apple stock). What I need: The chart should trigger buy and sell and execute the trade in TWS AFL Code: Buy = Cross( EMA(C, 2), EMA(C,5) ); Sell = Cross( EMA(C,5), EMA(C, 2) ); //BuyPrice = Open; //SellPrice = Open; Short = Sell; //ShortPrice = Open; Cover = Buy; //CoverPrice = Open; // trade on next bar open SetTradeDelays( 1, 1, 1, 1 ); BuyPrice = SellPrice = Close; // trade size: 25% of current portfolio equity //SetPositionSize( 25, spsPercentOfEquity ); SetTradeDelays(1,1,1,1); if ( LastValue( Buy ) ) { ibc = GetTradingInterface("IB"); // check if we are connected OK if( ibc.IsConnected() ) { // check if we do not have already open position on this stock if( ibc.GetPositionSize( Name() ) == 0) { // transmit order ibc.PlaceOrder( Name(), "Buy", 1, "MKT", 0, 0, "Day", False ); } } } if ( LastValue( Sell) ) { ibc = GetTradingInterface("IB"); // check if we are connected OK if( ibc.IsConnected() ) { // check if we do not have already open position on this stock if( ibc.GetPositionSize( Name() ) == 0) { // transmit order ibc.PlaceOrder( Name(), "Sell", 1, "MKT", 0, 0, "Day", False ); } } } Any help would be appreciated.
I can recommend this API if you're after a quick fix: http://code.google.com/p/ib-csharp/ Its relatively stable and is maintained. You just need to write the connection scripts to port your code over.
This will also give you what you want. I assume from your code your are trading of 30min bars? http://code.google.com/p/trade-manager/ Thanks James