有您的持续关注
我们会做得更好

一款来自网络的趋势EA



趋势EA根据MA、ADX、KD指标综合信号在进行交易。虽有合理的盈亏比,但遇到长时间小幅乱震荡的行情,可能会频繁止损。

本网收集整理智能交易EA仅为MQL4编程爱好者提供语法及相关编程技巧的学习研究之用,智能交易存在极高的风险测试请用模拟盘,请勿用于实盘。趋势EA源码:

//+------------------------------------------------------------------+
//|                                                       趋势EA.mq4 |
//|                                     Copyright 2014, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com/"

extern double lots=0.1;
extern int Magic_Number=36891;
extern int hd=30;
int Tick;
extern int StopLoss=300;
extern int TakeProfit=600;
bool ok=true;
bool yes=true;

int init()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   Comment("www.125808047.com");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

int Ticket;
int OrderTypeNow=GetOrderTypeHolding();

if (OrderTypeNow==-1)
{
if (TradeOrNo(1))
{
RefreshRates();
Ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,hd,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",Magic_Number,0,Green);
if(Ticket<0)
{
Print("多单入场失败"+GetLastError()); 
return(0); 
}
}else
if (TradeOrNo(2))
{
RefreshRates();
Ticket=OrderSend(Symbol(),OP_SELL,lots,Bid,hd,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",Magic_Number,0,Red);
if(Ticket<0)
{
Print("空单入场失败"+GetLastError()); 
return(0); 
}
}
return(0);
}

return(-1);
}
//+------------------------------------------------------------------+
int GetOrderTypeHolding()//从最近持仓单提取订单类型,如果没有持仓单,则认为是止赢出场或程序刚开始运行返回-1
{int Type=-1;
for(int i=OrdersTotal()-1;i>=0;i--)
{
bool cg = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number )
{ 
Type=OrderType(); 
Tick=OrderTicket();  
}
}
return(Type);
}
bool TradeOrNo(int Type)//判断当前指定方向的入场条件是否成立
{
double ma_5_1,ma_5_2,ma_10_1,ma_10_2,ma_20_1,ma_20_2;
double adx;
double k1,k2,d1,d2;
int n=1;
ma_5_1=iMA(Symbol(),0,5,0,MODE_SMA,PRICE_CLOSE,n);
ma_5_2=iMA(Symbol(),0,5,0,MODE_SMA,PRICE_CLOSE,n+1);
ma_10_1=iMA(Symbol(),0,10,0,MODE_SMA,PRICE_CLOSE,n);
ma_10_2=iMA(Symbol(),0,10,0,MODE_SMA,PRICE_CLOSE,n+1);
ma_20_1=iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,n);
ma_20_2=iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,n+1);
adx=iADX(Symbol(),0,14,PRICE_CLOSE,MODE_MAIN,n);
k1=iCustom(Symbol(),0,"Stochastic",5,3,3,0,n+1);
d1=iCustom(Symbol(),0,"Stochastic",5,3,3,1,n+1);
k2=iCustom(Symbol(),0,"Stochastic",5,3,3,0,n+2);
d2=iCustom(Symbol(),0,"Stochastic",5,3,3,1,n+2);
while ((ma_5_1>ma_5_2)&&(ma_10_1>ma_10_2)&&(ma_20_1>ma_20_2)&&(ma_5_1>ma_10_1)
   &&(ma_10_1>ma_20_1)&&(ma_5_2>ma_10_2)&&(ma_10_2>ma_20_2)&&(adx>30)
   &&(k1>d1)&&(k2<=d2)){

{
n++;
if(Close[1]<Open[1])
{
ok=true;
return (ok);
}
break;
}
}
while ((ma_5_1<ma_5_2)&&(ma_10_1<ma_10_2)&&(ma_20_1<ma_20_2)&&(ma_5_1<ma_10_1)
   &&(ma_10_1<ma_20_1)&&(ma_5_2<ma_10_2)&&(ma_10_2<ma_20_2)&&(adx>30)
   &&(k1<d1)&&(k2>=d2)){

{
n++;
if(Close[1]>Open[1])
{
yes=true;
return (yes);
}
break;
}
}

 
switch(Type)
{
case 1://判断多单入场条件是否成立
if(ok==true)//做多条件成立
{ 
return(true);
}
break;
case 2:
if((yes==true))//做空条件成立
{
return(true);
}
break;


}
return(false);
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 一款来自网络的趋势EA
上一篇:
下一篇:
分享到:更多 ()