| 
 hi, 
  
I didn't test your code nor the code posted below 
but it might be that you have got the brackets not entirely 
correct. 
  
The code I posted below should do the 
following. 
  
When it first encounters a "Buy" then it will buy 1 
contract, then sell 2, resulting in 1 short position, then buy 2, resulting in 1 
long position etc. 
  
When it first encounters a "Sell" ...... similar as 
above, 
  
hope it works now, 
  
rgds, Ed 
  
  
  
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;      }    } 
  
else 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; 
  
     }     
   } 
  
}
  
  ----- Original Message -----  
  
  
  Sent: Thursday, June 09, 2005 7:08 
  PM 
  Subject: [amibroker] AUTOMATIC 
  TRADING 
  
  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;     }    
  } }
 
  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
 
 
  
  
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 
  |