账号净值低于设定值关闭所有订单并退出EA
- extern string 关闭EA并发邮件 = "账户低于净值,关闭所有订单并退出EA";
- extern double 低于净值停止 = 0.0;
- ////
- bool 开关返回值 = FALSE;
- ////
- int start()
- {
- A_Stop();////
- return(0);
- }
- //////
- void A_Stop() {
- int res;
- bool 判断开关;
- double 账户净值;
- if (低于净值停止 <= 0.0) return;
- if (!开关返回值) {
- if (AccountNumber() == 0 || AccountEquity() == 0.0 || AccountBalance() == 0.0) return;
- 判断开关 = FALSE;
- 账户净值 = AccountEquity();
- if (账户净值 < 低于净值停止 && 低于净值停止 > 0.0) {
- 判断开关 = TRUE;
- }
- if (判断开关) 开关返回值 = TRUE;
- }
- if (开关返回值) {
- for (int l = OrdersTotal() - 1; l >= 0; l--) {
- if (OrderSelect(l, SELECT_BY_POS)) {
- {
- switch (OrderType()) {
- case OP_BUY:
- case OP_SELL:
- res=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 9999);
- ExpertRemove();
- SendMail("帐户低于净值警告","目前净值低于设置最低净值警告,EA已自动关闭!");break;
- default:
- res=OrderDelete(OrderTicket());
- ExpertRemove();
- SendMail("帐户低于净值警告","目前净值低于设置最低净值警告,EA已自动关闭!");break;
- }
- }
- }
- }
- }
- }
赞 (0)