常用模块

一、限制EA使用时间、交易对象和帐号

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);
	}	//限制使用账号

二、获取一定周期内最高/最底价格

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个连续柱子范围内计算最大值

三、根据账户余额动态计算开仓手数

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;
 }

四、设置邮件通知

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()+"]");//开仓成功发送邮件提醒

五、指定平仓时间

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
				}
			}
		}
	}

转载于:https://my.oschina.net/u/3093769/blog/1635902

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值