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

[amibroker] AUTOMATIC TRADING



PureBytes Links

Trading Reference Links

Hi, I'm trying to automate orders with AmiBroker 4.7 and TWS but I'm not 
able to do it. I've written a "dummy" trading system which buys when 
close is higher than the last close and sells when close is lower than 
the last close (very useful in 1-minute charts to test orders).  The 
problem is that AB starts sending orders to Buy 2 contracts and stops. 
Maybe there's something wrong with brackets or another stupid thing but 
it would be very helpful for me if someone in the list provides an 
example code to automate orders (or test and arrange mine).

Thanks a lot and good trading,
Alberto Muņoz

This is the AFL code:

LastPosition=0;
Buy=C > Ref(C, -1);
Sell=C < Ref(C, -1);
Buy  = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

if( LastValue( Buy ) )
{
 ibc = GetTradingInterface("IB");

 if( ibc.IsConnected() )
 {
    if(LastPosition==0)
    {
        ibc.PlaceOrder( Name(), "Buy", 1, "MKT", 0, 0, "Day", False);
        LastPosition=1;
    }
 }

else
{
if( LastPosition==-1)
    {
      ibc.PlaceOrder( Name(), "Buy", 2, "MKT", 0, 0, "Day", False );
       LastPosition=1;
    }
   }
}

if( LastValue( Sell ) )
{
 ibc = GetTradingInterface("IB");
 if( ibc.IsConnected() )
 {
    if( LastPosition==0 )
    {
       ibc.PlaceOrder( Name(), "Sell", 1, "MKT", 0, 0, "Day", False );
         LastPosition=-1;
    }
 }

else
{
if( LastPosition==1 )
    {
       ibc.PlaceOrder( Name(), "Sell", 2, "MKT", 0, 0, "Day", False );
         LastPosition=-1;
    }
   }
}


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/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/