该函数在账户盈利到达预期设定的值的时候执行全部平仓。
- int Save_Profit(){
- if (AccountProfit()>= Profit_to_Close)
- {
- for(int i=OrdersTotal()-1;i>=0;i--)
- {
- OrderSelect(i, SELECT_BY_POS);
- int type = OrderType();
- bool result = false;
- switch(type)
- {
- //Close opened long positions
- case
- OP_BUY
- :
- result
- =
- OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Pink);
- break;
- //Close opened short positions
- case
- OP_SELL
- :
- result
- =
- OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Pink);
- }
- if(result == false)
- {
- Sleep(3000);
- }
- else if (Cancel_Trading_On_Profit) cantrade=false;
- }
- Print ("Account Profit Reached. All Open Trades Have Been Closed");
- return(0);
- }
|