經常使用模塊

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
				}
			}
		}
	}
相關文章
相關標籤/搜索