下载MetaTrader 5

请问有高手免费写EA吗? - 页 2

要添加评论,请登录注册
yijun lan
194
yijun lan 2010.03.05 04:03  

#property copyright "Copyright 2010, trad@mql4.com"
#property link "supercase@163.com"

double gd_216;
extern bool time1 = true;
bool OpenBuya = false;
bool OpenBuyb = false;
bool OpenSella = false;
bool OpenSellb = false;
double p,buya,buyb,sella,sellb;

int start()
{
if(CalculateCurrentOrders(Symbol())==0)
{
if(time1 && TimeHour(TimeCurrent())==0) CheckForOpen();
if(!time1) CheckForOpenOrder();
}
if(TimeHour(TimeCurrent())==23 && TimeMinute(TimeCurrent())==55 && OrdersTotal()>0) CheckForClose();
return(0);
}

int CalculateCurrentOrders(string symbol)
{
int orders = 0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==0)
orders++;
time1=true;
}
return(orders);
}

void CheckForOpen()
{
int digits = MarketInfo(Symbol(), MODE_DIGITS);
if (digits < 4) gd_216 = 0.01;
else gd_216 = 0.0001;

p = (High[1]+Low[1]+Close[1])/3;
buya=p+21*gd_216;
buyb=p+41*gd_216;
sella=p-21*gd_216;
sellb=p-41*gd_216;

if(Close[1]>buyb) OpenBuyb = true;
else if(Close[1]>buya && Close[1]<buyb) OpenBuya = true;
else if(Close[1]>sella && Close[1]<buya)
{
if(Close[0]>p) OpenBuya = true;
else if(Close[0]<p) OpenSella = true;
}
else if(Close[1]>sellb && Close[1]<sella) OpenSella = true;
else if(Close[1]<sellb) OpenSellb = true;
time1 = false;
}

void CheckForOpenOrder()
{
if(OpenBuya && Close[0] > buya && Close[0] - buya < 5*gd_216)
OrderSend(Symbol(),OP_BUY,1,Ask,3, Ask-30*Point, Ask+25*Point,0,0,0,Red);
if(OpenBuyb && Close[0] > buyb && Close[0] - buyb < 5*gd_216)
OrderSend(Symbol(),OP_BUY,1,Ask,3, Ask-30*Point, Ask+25*Point,0,0,0,Red);
if(OpenSella && Close[0] < sella && sella - Close[0] < 5*gd_216)
OrderSend(Symbol(),OP_SELL,1,Bid,3, Bid+30*Point, Bid-25*Point,0,0,0,Lime);
if(OpenSellb && Close[0] < sellb && sellb - Close[0] < 5*gd_216)
OrderSend(Symbol(),OP_SELL,1,Bid,3, Bid+30*Point, Bid-25*Point,0,0,0,Lime);
}

void CheckForClose()
{
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==0)
{
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime);
if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime);
}
}
}

附加的文件:
tanggangsi
25
tanggangsi 2010.03.07 07:24  
trad 写道 >>
ERR_INVALID_STOPS 130 Stops 太近或是价格计算错误。 需要刷新数据 /RefreshRates.html">RefreshRates 函数重试 如果错误没有消失,尝试停止所有运行交易,改变程序逻辑。

说明止损点计算有误。

//+------------------------------------------------------------------+
//| OnceDay System.mq4 |
//| Copyright 2010, trad@mql4.com |
//| supercase@163.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, trad@mql4.com"
#property link "supercase@163.com"

#define MAGICMA 20100227
extern double TakeProfit =20;
extern double Lots = 0.1;
extern double Stoploss = 30;
extern int slippage=5;

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//---- check for history and trading
if(IsTradeAllowed()==false)
return;

CheckForCancel();
if(CalculateCurrentOrders(Symbol())==0)
CheckForOpen();

return(0);
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int orders = 0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
orders++;
}
return(orders);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
double p =NormalizeDouble((High[1]+Low[1]+Close[1])/3,Digits);
double buya=p+21*Point;
double buyb=p+41*Point;
double sella=p-21*Point;
double sellb=p-41*Point;

if(TimeHour(TimeCurrent())!=12) return;

if(Close[1]>buyb)
OrderSend(Symbol(),OP_BUYSTOP,Lots,buyb,slippage, buyb-30*Point, buyb+20*Point,"",MAGICMA,0,Red);
else if(Close[1]>buya && Close[1]<buyb)
OrderSend(Symbol(),OP_BUYSTOP,Lots,buya,slippage,buya -30*Point,buya +20*Point,"",MAGICMA,0,Red);
else if(Close[1]>sella && Close[1]<buya)
{
if(Close[0]>p)
OrderSend(Symbol(),OP_BUYSTOP,Lots,buya,slippage,buya -30*Point,buya +20*Point,"",MAGICMA,0,Red);
else if(Close[0]<p)
OrderSend(Symbol(),OP_SELLSTOP,Lots,sella,slippage, sella+30*Point,sella -20*Point,"",MAGICMA,0,Aqua);
}
else if(Close[1]>sellb && Close[1]<sella)
OrderSend(Symbol(),OP_SELLSTOP,Lots,sella,slippage, sella+30*Point,sella- 20*Point,"",MAGICMA,0,Aqua);
else if(Close[1]<sellb)
OrderSend(Symbol(),OP_SELLSTOP,Lots,sellb,slippage, sellb+30*Point,sellb -20*Point,"",MAGICMA,0,Aqua);
}
//+------------------------------------------------------------------+
//| Check for cancel order conditions |
//+------------------------------------------------------------------+
void CheckForCancel()
{
if(TimeHour(TimeCurrent())!=0) return;

for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP
|| OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)
{
OrderDelete(OrderTicket(),White);
}
}
}

}


/*每当新的一天就计算出前一天的支点P
P=昨日的(high+low+close)/3
由P算出4个价格分别为:
buya=P+21个点
buyb=P+41个点
sella=P-21个点
sellb=P-41个点
每天中午12:00就挂单
挂单分5种判断:
1.昨日的close价格在buyb之上,在buyb挂多单;
2.昨日的close价格在buya buyb之间,在buya挂多单;
3.昨日的close价格在buya sella之间,看:
当前价格在P之上,在buya挂多单;
当前价格在P之下,在sella挂空单;
4.昨日的close价格在sella sellb之间,在sella挂空单;
5.昨日的close价格在sellb之下,在sellb挂空单。
挂单止赢20个点止损30个点
一旦挂单成交就让其自动止赢或者止损
晚上12:00即0点
没有成交的挂单撤销
准备新的挂单。*/

12
要添加评论,请登录注册