账号净值低于设定值关闭所有订单并退出EA

  1. extern string 关闭EA并发邮件   = "账户低于净值,关闭所有订单并退出EA";
  2. extern double 低于净值停止     = 0.0;
  3. ////
  4. bool 开关返回值 = FALSE;
  5. ////
  6. int start()
  7. {
  8. A_Stop();////
  9. return(0);
  10. }
  11. //////
  12. void A_Stop() {
  13. int res;
  14. bool 判断开关;
  15. double 账户净值;
  16. if (低于净值停止 <= 0.0) return;
  17. if (!开关返回值) {
  18. if (AccountNumber() == 0 || AccountEquity() == 0.0 || AccountBalance() == 0.0) return;
  19. 判断开关 = FALSE;
  20. 账户净值 = AccountEquity();
  21. if (账户净值 < 低于净值停止 && 低于净值停止 > 0.0) {
  22. 判断开关 = TRUE;
  23. }
  24. if (判断开关) 开关返回值 = TRUE;
  25. }
  26. if (开关返回值) {
  27. for (int l = OrdersTotal() - 1; l >= 0; l--) {
  28. if (OrderSelect(l, SELECT_BY_POS)) {
  29. {
  30. switch (OrderType()) {
  31. case OP_BUY:
  32. case OP_SELL:
  33. res=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 9999);
  34. ExpertRemove();
  35. SendMail("帐户低于净值警告","目前净值低于设置最低净值警告,EA已自动关闭!");break;
  36. default:
  37. res=OrderDelete(OrderTicket());
  38. ExpertRemove();
  39. SendMail("帐户低于净值警告","目前净值低于设置最低净值警告,EA已自动关闭!");break;
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
(0)

相关推荐