11评论

2收藏

净值监控指标,时刻关注你的账户

avatar 情人 | 5876 人阅读 | 11 人评论 | 2016-07-22

给出源码,你们可以看看

  1. //+------------------------------------------------------------------+
  2. //|                                                   净值监控V1.mq4 |
  3. //|                                      Copyright 2012, Goddz Corp. |
  4. //+------------------------------------------------------------------+
  5. #property copyright "Copyright 2012, Goddz Corp."

  6. extern int  参考净值 =  0;    //当净值小于此值时全平全撤 或 警报提醒
  7. extern bool 全平全撤 = true;  //true 表示净值达到后全平,false表示净值达到后只报警提示

  8. int preEquity = 0;
  9. int iniEquity = 0;
  10. bool isAlertOn = true;
  11. datetime closetime = 0;
  12. bool isCloseOk = false;
  13. int id = 0;
  14. //+------------------------------------------------------------------+
  15. //| expert initialization function                                   |
  16. //+------------------------------------------------------------------+
  17. int init()
  18.   {
  19. //----
  20.    Alert("***------------------------。");
  21.    Alert("***------------------------。");
  22.    
  23.    if (参考净值 > AccountEquity())
  24.    {
  25.       Alert("***参考净值不能大于当前净值。");
  26.       参考净值 = 0;
  27.       return(0);
  28.    }
  29.    if (preEquity != 参考净值)
  30.    {
  31.       Alert("***修改参考净值为:", 参考净值);
  32.       closetime = 0;
  33.       preEquity = 参考净值;
  34.    }
  35.    iniEquity = AccountEquity();
  36. //----
  37.    return(0);
  38.   }
  39. //+------------------------------------------------------------------+
  40. //| expert deinitialization function                                 |
  41. //+------------------------------------------------------------------+
  42. int deinit()
  43.   {
  44. //----
  45.    
  46. //----
  47.    return(0);
  48.   }
  49. //+------------------------------------------------------------------+
  50. //| expert start function                                            |
  51. //+------------------------------------------------------------------+
  52. int start()
  53.   {
  54. //----
  55.    if (参考净值 > 0 && AccountEquity() < 参考净值 && closetime == 0) //iniEquity >= 参考净值 &&
  56.    {
  57.       closetime = TimeCurrent(); //记录信息出现时间
  58.       isCloseOk = false;
  59.       Print("***净值达到设定值***", AccountEquity());
  60.       id = 0;
  61.    }
  62.    
  63.    if (closetime > 0)
  64.    {
  65.       if (全平全撤)
  66.       {
  67.          if (!isCloseOk)
  68.          {
  69.             CloseAndDeleteAll();
  70.             if (OrdersTotal() == 0)
  71.             {
  72.                isCloseOk = true;
  73.             }
  74.          }
  75.          if (isCloseOk)
  76.          {
  77.             id++;
  78.             Alert("***净值达到设定值,请重新初始化参考净值*** ", id);           
  79.          }
  80.       }
  81.       else
  82.       {
  83.          id++;
  84.          Alert("***净值达到设定值***", id);
  85.       }
  86.    }
  87. //----
  88.    return(0);
  89.   }
  90. //+------------------------------------------------------------------+

  91. void CloseAndDeleteAll()
  92. {
  93.    for (int i = OrdersTotal() - 1; i >= 0; i--)
  94.    {
  95.       if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
  96.       {
  97.          int ticket = OrderTicket();
  98.          bool ret = true;
  99.          if (OrderType() == OP_BUY)
  100.          {
  101.             ret = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 1000, CLR_NONE);
  102.          }
  103.          else if (OrderType() == OP_SELL)
  104.          {
  105.             ret = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 1000, CLR_NONE);
  106.          }
  107.          else if (OrderType() > OP_SELL)
  108.          {
  109.             ret = OrderDelete( OrderTicket() );
  110.          }//挂单

  111.          if (ret)
  112.          {
  113.             break;
  114.          }
  115.          //失败
  116.          IsContinueByErrcode( GetLastError(), ticket);
  117.       }
  118.    }//for
  119.    RefreshRates();
  120. }

  121. bool IsContinueByErrcode( int errCode, int ticket)
  122. {
  123.    if (isAlertOn)
  124.    {
  125.       switch ( errCode )
  126.       {
  127.          case 129: if (isAlertOn) Alert(Symbol() + "-错误:无效的价格,交易失败.", " 定单号:" + ticket);break;
  128.          case 131: if (isAlertOn) Alert(Symbol() + "-错误:无效的交易量,交易失败.", " 定单号:" + ticket);break;
  129.          case 134: if (isAlertOn) Alert(Symbol() + "-错误:资金不足,交易失败.", " 定单号:" + ticket);break;
  130.          case 130: if (isAlertOn) Alert(Symbol() + "-错误:无效的止损,止赢或挂单价离市价近.", " 定单号:" + ticket);break;
  131.          case 138: if (isAlertOn) Alert(Symbol() + "-错误:价格过期,交易失败.", " 定单号:" + ticket);break;
  132.          case 148: if (isAlertOn) Alert(Symbol() + "-错误:帐户定单过多,交易失败.", " 定单号:" + ticket);break;
  133.          default :
  134.             {
  135.                if (isAlertOn) Alert(Symbol() + "-错误:其它错误#", errCode, " 定单号:" + ticket);break;
  136.             }
  137.             break;
  138.       }
  139.    }
  140.    
  141.    return (false);
  142. }
复制代码


""
还没有人打赏,支持一下

评论|共 11 个

omelan

发表于 2018-9-22 10:15:31 | 显示全部楼层

好东东必须大家一起分享

渔人

发表于 2020-6-15 10:11:18 | 显示全部楼层

谢谢楼主,共同发展

老张

发表于 2020-7-21 16:04:50 | 显示全部楼层

学习了,不错

高帆豪

发表于 2020-7-21 22:32:21 | 显示全部楼层

帮你顶下哈!!

kclokclo5

发表于 2020-9-10 10:00:37 | 显示全部楼层

谢谢楼主分享

ijhcybuv

发表于 2020-11-18 20:22:12 | 显示全部楼层

翱翔长空

发表于 2021-7-17 21:00:39 | 显示全部楼层

皮肤估风格

发表于 2021-7-17 23:49:19 | 显示全部楼层

量化投资

发表于 2021-7-22 14:42:15 | 显示全部楼层

支持下

12下一页
您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则