自动交易下 Bracket 订单,股票成功,外汇出错。

Discussion in 'AmiBroker' started by bonnyshi, Sep 5, 2008.

  1. 用 AmiBroker Auto-Trading interface for interactive Brokers 1.2.0 Beat 上面的例子,在美国股票上已经试验成功可以下 Bracket 订单。


    然后我把它改了一下,想用在外汇 EUR.USD 下bracket订单,就无法成功。

    TP=C+0.0100 // take profit + 100 point
    ST=c-0.0100 // Stop Loss - 100 point

    parentID= ibc.PlaceOrder( Name(), "BUY", 25000, "MKT", 0, 0, "GTC",True);
    ibc.PlaceOrder( Name(), "SELL",25000, "LMT",TP,0,"GTC",True,1,"", parentID );
    ibc.PlaceOrder( Name(), "SELL",25000, "STP",0,ST,"GTC",True,1,"", parentID );



    parentID 可以成功挂单,但是执行到下面两个 bracket 订单时,显示错误。我找不出那里错误。请各位大大帮我看一下。

    先谢谢了。
     
  2. 你要把所有的code 贴上来才能判断。

    AFL 就是这样,单单几行代码有时是看不出问题所在的。
     



  3. 程序思路:

    均线5 金叉 均线13 时, 市价买入,止盈+100点。 止损-100点。

    调试程序是用 DebugView 还是 Interpretation Window 比较方便?


    _SECTION_BEGIN("Price");
    SetChartOptions(0,chartShowArrows|chartShowDates);
    _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
    Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
    _SECTION_END();



    _SECTION_BEGIN("Fast");
    P1 = ParamField("Price field",-1);
    Fast = Param("Periods", 5, 2, 200, 1 );
    Plot( EMA( P1, Fast ), _DEFAULT_NAME(), ParamColor( "Color", colorWhite ), ParamStyle("Style") | styleNoRescale );
    _SECTION_END();

    _SECTION_BEGIN("Slow");
    P2 = ParamField("Price field",-1);
    Slow = Param("Periods", 13, 2, 300, 1 );
    Plot( EMA( P2, Slow), _DEFAULT_NAME(), ParamColor( "Color", colorYellow), ParamStyle("Style") | styleNoRescale );
    _SECTION_END();



    Buy = Cross((EMA(Close,Fast)),(EMA(Open,Slow)));
    Sell = Cross(EMA(Open,Slow),(EMA(Close,Fast)));


    // plot arrows
    shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
    PlotShapes( shape, IIf( Buy, colorLime, colorRed ), 0, IIf( Buy, Low, High ));




    BuyOrderID = StaticVarGetText("BuyOrderID");
    SellOrderID = StaticVarGetText("SellOrderID");



    SetPositionSize( 1, spsShares );

    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)
    {
    ST=C-0.0100; // stop los - 100 pip
    TP=C+0.0100; // take profti +100 pip
    // transmit order
    parentID= ibc.PlaceOrder( Name(), "BUY", 25000, "MKT", 0, 0, "GTC",False);
    ibc.PlaceOrder( Name(), "SELL",25000, "LMT",TP,0,"GTC",False,1,"", parentID );
    ibc.PlaceOrder( Name(), "SELL",25000, "STP",0,ST,"GTC",True,1,"", parentID );

    }
    }
    }