评论

收藏

账户净值风险控制

avatar oneleaf | 1116 人阅读 | 0 人评论 | 2019-12-09

  1. #property copyright "shiyingpan"
  2. #property link      "https://aijy.github.io"
  3. #property version   "1.00"
  4. #property strict

  5. int 授权账号=123;
  6. double 初始资金=0;

  7. int OnInit()
  8.   {
  9.    while(AccountNumber()==0) //-- 加载前可先使用账户号判断时候可交易,网络未连接时,账号为0
  10.       Sleep(500);            //-- 程序在此停留0.5秒,啥也不干,再判断账号值
  11.    if(AccountNumber()!=授权账号)
  12.    {
  13.       Alert("非授权账号");
  14.       return INIT_FAILED;   //-- 非授权账号,不能加载成功
  15.    }
  16.    Print("账号名:",AccountName());    //-- 获取账户名   
  17.    初始资金=AccountEquity();           //-- 加载EA时获取当前账户净值
  18.    
  19.    if(!IsDemo())                  //-- 如果是实盘
  20.    {
  21.       Alert("当前账户为实盘账户!");
  22.    }
  23.    return(INIT_SUCCEEDED);
  24.   }

  25. void OnDeinit(const int reason)
  26.   {

  27.    
  28.   }

  29. void OnTick()
  30.   {
  31. //--------------- 账户净值风险控制 ----------------//
  32.    if(AccountEquity()<初始资金*0.8)
  33.    {
  34.       Alert("当前账户净值亏损20%,已停止交易");
  35.       //-- 添加平仓操作(平仓退出)
  36.       ExpertRemove(); //-- 退出EA
  37.       return;
  38.    }
  39.   }
复制代码


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

EA之家评论守则