I want to start auto trading with IB, that's why I write (or copy from amibroker website) following AFL:
//Auto Trading with IB//
if( LastValue( Buy ) )
{
ibc = GetTradingInterface("IB");
if( ibc.IsConnected() )
{
if( ibc.GetPositionSize("YM Jun16'17 @ECBOT") == 0 )
{
// transmit order
ibc.PlaceOrder("YM Jun16'17 @ECBOT","Buy",1,"STP",0,50,"GTD", True );
}
}
}
if( LastValue( Sell ) )
{
ibc = GetTradingInterface("IB")
if( ibc.IsConnected() )
{
ibc.PlaceOrder("YM Jun16'17 @ECBOT","Sell",1,"MKT",0,0,"GTD", True );
}
}
}
if( LastValue( Short ) )
{
ibc = GetTradingInterface("IB")
if( ibc.IsConnected() )
{
if( ibc.GetPositionSize("YM Jun16'17 @ECBOT") == 0 )
{
// transmit order
ibc.PlaceOrder("YM Jun16'17 @ECBOT","Short",1,"STP",0,50,"GTD", True );
}
}
}
if( LastValue( Cover ) )
{
ibc = GetTradingInterface("IB");
if( ibc.IsConnected() )
{
ibc.PlaceOrder("YM Jun16'17 @ECBOT","Cover",1,"MKT",0,0,"GTD", True );
}
}
}
However, when i dragged into the chart, amibroker alert me:
File: 'Formulas\Drag-drop\Trading system A for IB YM (Jun) 4.afl", Ln:96, Col:3
Error 30.
Syntax error, unexpected IF
I highligheted Ln 96 in blue here, which is "if( ibc.IsConnected() )" in SELL order. What's the problem? how can i fix it? pls help me, thx
//Auto Trading with IB//
if( LastValue( Buy ) )
{
ibc = GetTradingInterface("IB");
if( ibc.IsConnected() )
{
if( ibc.GetPositionSize("YM Jun16'17 @ECBOT") == 0 )
{
// transmit order
ibc.PlaceOrder("YM Jun16'17 @ECBOT","Buy",1,"STP",0,50,"GTD", True );
}
}
}
if( LastValue( Sell ) )
{
ibc = GetTradingInterface("IB")
if( ibc.IsConnected() )
{
ibc.PlaceOrder("YM Jun16'17 @ECBOT","Sell",1,"MKT",0,0,"GTD", True );
}
}
}
if( LastValue( Short ) )
{
ibc = GetTradingInterface("IB")
if( ibc.IsConnected() )
{
if( ibc.GetPositionSize("YM Jun16'17 @ECBOT") == 0 )
{
// transmit order
ibc.PlaceOrder("YM Jun16'17 @ECBOT","Short",1,"STP",0,50,"GTD", True );
}
}
}
if( LastValue( Cover ) )
{
ibc = GetTradingInterface("IB");
if( ibc.IsConnected() )
{
ibc.PlaceOrder("YM Jun16'17 @ECBOT","Cover",1,"MKT",0,0,"GTD", True );
}
}
}
However, when i dragged into the chart, amibroker alert me:
File: 'Formulas\Drag-drop\Trading system A for IB YM (Jun) 4.afl", Ln:96, Col:3
Error 30.
Syntax error, unexpected IF
I highligheted Ln 96 in blue here, which is "if( ibc.IsConnected() )" in SELL order. What's the problem? how can i fix it? pls help me, thx