1、限制EA使用时间、交易对象和账号git
if(Symbol() != "EURUSD") return(0); //指定EA交易货币对 if((TimeDay(TimeCurrent()) > 25 && TimeMonth(TimeCurrent()) >= 3 && TimeYear(TimeCurrent()) >= 2010) || (TimeMonth(TimeCurrent()) > 3 && TimeYear(TimeCurrent()) >= 2010) ||TimeYear(TimeCurrent()) > 2010) { Comment("===已经超过受权使用时间,请联系xxxx==="); Print("===xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==="); return(0); } //指定使用时间 if(AccountNumber() != 13222222) { Comment("===本EA只受权在帐号13222222下使用==="); Print("===xxxxxxxxxxxxx==="); return(0); } //限制使用帐号
2、获取必定周期内最高/最底价格code
double val1,val2; val1=High[iHighest(NULL,0,MODE_HIGH,20,1)]; //在当前图表上从第1个起,在20个连续柱子范围内计算最大值 val2=Low[iLowest(NULL,0,MODE_LOW,20,1)]; //在当前图表上从第1个起,在20个连续柱子范围内计算最大值
3、根据帐户余额动态计算开仓手数对象
int LotSize() // The function opens a short position with lot size=volume { if (AccountBalance()>=50) lot=0.02; if (AccountBalance()>=100) lot=0.04; if (AccountBalance()>=200) lot=0.08; if (AccountBalance()>=300) lot=0.12; if (AccountBalance()>=400) lot=0.16; if (AccountBalance()>=500) lot=0.2; if (AccountBalance()>=600) lot=0.24; if (AccountBalance()>=700) lot=0.28; if (AccountBalance()>=800) lot=0.32; if (AccountBalance()>=900) lot=0.36; if (AccountBalance()>=1000) lot=0.4; if (AccountBalance()>=1500) lot=0.6; if (AccountBalance()>=2000) lot=0.8; if (AccountBalance()>=2500) lot=1.0; if (AccountBalance()>=3000) lot=1.2; if (AccountBalance()>=3500) lot=1.4; if (AccountBalance()>=4000) lot=1.6; if (AccountBalance()>=4500) lot=1.8; if (AccountBalance()>=5000) lot=2.0; if (AccountBalance()>=5500) lot=2.2; if (AccountBalance()>=6000) lot=2.4; if (AccountBalance()>=7000) lot=2.8; if (AccountBalance()>=8000) lot=3.2; if (AccountBalance()>=9000) lot=3.6; if (AccountBalance()>=10000) lot=4.0; if (AccountBalance()>=15000) lot=6.0; if (AccountBalance()>=20000) lot=8.0; if (AccountBalance()>=30000) lot=12; if (AccountBalance()>=40000) lot=16; if (AccountBalance()>=50000) lot=20; if (AccountBalance()>=60000) lot=24; if (AccountBalance()>=70000) lot=28; if (AccountBalance()>=80000) lot=32; if (AccountBalance()>=90000) lot=36; if (AccountBalance()>=100000) lot=40; if (AccountBalance()>=200000) lot=80; }
4、设置邮件通知it
extern bool SignalMail = True;//是否开启邮件通知 OrderClose(平仓);//平仓语句, if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + "订单平仓或部分平仓通知" + "[" + AccountName() + "]" + "[" + AccountNumber()+"]");//平仓成功发送邮件提醒 OrderSend(开仓);//开仓语句 if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + "开仓提醒" + "[" + AccountName() + "]" + "[" + AccountNumber()+"]");//开仓成功发送邮件提醒
5、指定平仓时间io
total=OrdersTotal(); for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) // check for opened position and symbol { if(OrderType()==OP_BUY) // long position is opened { if(total>0 && Hour()==22 && Minute()>45) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position return(0); // exit } } else // go to short position { if(total>0 && Hour()==22 && Minute()>45) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position return(0); // exit } } } }