DOC

MT4

By Harry Hart,2014-10-12 21:33
9 views 0
MT4

    1. //平掉全部仓位

    2. void closeAllOrders(int type)

    3. {

    4. for(int c=0;c<OrdersTotal();c++)

    5. {

    6. OrderSelect(c,SELECT_BY_POS,MODE_TRADES);

    7. if (OrderSymbol()==Symbol() && OrderType()==OP_BUY && type==0)

    8. {

    9. OrderClose(OrderTicket(), OrderLots(),Bid,3, White);

    10. }

    11. if (OrderSymbol()==Symbol() && OrderType()==OP_SELL && type==1)

    12. {

    13. OrderClose(OrderTicket(), OrderLots(), Ask,3, White);

    14. }

    15. if (OrderSymbol()==Symbol() && OrderType() > 1)

    16. {

    17. OrderDelete(OrderTicket());

    18. }

    19. }

    20. }

    Equity增加100或者减少100都平掉全部仓位

    extern double Equity=1000;

    void closeAllOrders(int type)

    {

    for(int c=0;c<OrdersTotal();c++)

    {

    OrderSelect(c,SELECT_BY_POS,MODE_TRADES);

    if (OrderSymbol()==Symbol() && OrderType()==OP_BUY && type==0)

    {

    OrderClose(OrderTicket(), OrderLots(),Bid,3, White);

    }

    if (OrderSymbol()==Symbol() && OrderType()==OP_SELL && type==1)

    {

    OrderClose(OrderTicket(), OrderLots(), Ask,3, White);

    }

    if (OrderSymbol()==Symbol() && OrderType() > 1)

    {

    OrderDelete(OrderTicket());

    }

    }

    }

    //pppppp

    int init()

    {

    Equity=AccountEquity();

    return(0);

    }

    int deinit()

    {

    return(0);

    }

    int start()

    {

    if (AccountEquity()-Equity>=100)

    {

    Equity=AccountEquity(); closeAllOrders(0); closeAllOrders(1);

    return(0);

    }

    if (AccountEquity()-Equity <= -100)

    {

    Equity=AccountEquity();

    closeAllOrders(0);

    closeAllOrders(1);

    return(0);

    }

    return (0);

    }

    EA自定义函数-全部平仓

    bool ClosePosition()//Close all pending and holding positions

    {

    bool Flag=true;

    int tick[200],tp[200];

    int j=0;

    for(int i=0;i<OrdersTotal();i++) {

    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

    if(OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicHunDun))

    {

    j=j+1;

    tick[j]=OrderTicket();

    tp[j]=OrderType();

    }

    }

    if (j!=0)

    {

    for(i=1;i<=j;i++)

    {

    OrderSelect(tick[i], SELECT_BY_TICKET); switch(tp[i])

    {

    case OP_BUY:

    if(OrderClose(tick[i],OrderLots(),Bid,3,CLR_NONE)==false) Flag=false;

    break;

    case OP_SELL:

    if(OrderClose(tick[i],OrderLots(),Ask,3,CLR_NONE)==false) Flag=false;

    break;

    }

    }

}

return(Flag);

}

Report this document

For any questions or suggestions please email
cust-service@docsford.com