评论

收藏

清除亏损

avatar 老周 | 1207 人阅读 | 0 人评论 | 2016-10-31

extern int ProfitTarget = 1; // Profit target in dollars

int start()
{
  int total = OrdersTotal();
  for(int i=total-1;i>=0;i--)
  {
    OrderSelect(i, SELECT_BY_POS);
    int type  = OrderType();

    bool result = false;

    switch(type)
    {
      //Close opened long positions
      case OP_BUY      : if ( OrderProfit() <= ProfitTarget) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
                          break;

      //Close opened short positions
      case OP_SELL      : if ( OrderProfit() <= ProfitTarget) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

    }

    if(result == false)
    {
      Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
      Sleep(3000);
    }
  }

  return(0);
}

""
还没有人打赏,支持一下
您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则