打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
一个简单地均线EA
userphoto

2017.06.21

关注

   这个EA系统是以均线为分析指标建立的,它的买卖规则也很简单。

   需要的指标参数  5日 Eponential 均线

                  13日 Eponential 均线

                   21日Eponential 均线

                  80日 Eponential 均线

                  rsi  参数 21日

    做多条件:价格在80日均线之上,13、21日都在80日均线之上,rsi在50之上,当5日均线上穿13、21日均线时做多。

   做空条件正好相反。


  EA源码

//+------------------------------------------------------------------+
//| This MQL is generated by Expert AdvisorBuilder                 |
//|               
http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/|
//|                                                                 |
//|  In no event will author be liable for anydamages whatsoever.   |
//|                     Use at your ownrisk.                      |
//|                                                                 |
//+------------------- DO NOT REMOVE THIS HEADER--------------------+

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property copyright "Expert AdvisorBuilder"
#propertylink     "
http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 0.1;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 300;
extern bool UseTakeProfit = True;
extern int TakeProfit = 600;
extern bool UseTrailingStop = True;
extern int TrailingStop = 300;

int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initializationfunction                                  |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars;

   if(EachTickMode) Current = 0; else Current = 1;

  return(0);
}
//+------------------------------------------------------------------+
//| expert deinitializationfunction                                |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
}
//+------------------------------------------------------------------+
//| expert startfunction                                           |
//+------------------------------------------------------------------+
int start() {
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel,TakeProfitLevel;

 

   if(EachTickMode && Bars != BarCount)TickCheck = False;
   Total = OrdersTotal();
   Order =SIGNAL_NONE;

  //+------------------------------------------------------------------+
   //| VariableBegin                                                  |
  //+------------------------------------------------------------------+


double Buy1_1 = iMA(NULL, 0, 5, 0,MODE_EMA, PRICE_CLOSE, Current + 0);
double Buy1_2 = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Buy2_1 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current +0);
double Buy2_2 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Buy3_1 = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Buy3_2 = iMA(NULL, 0, 80, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Buy4_1 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Buy4_2 = iMA(NULL, 0, 80, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Buy5_1 = iRSI(NULL, 0, 21, PRICE_CLOSE, Current + 0);
double Buy5_2 = 50;

double Sell1_1 = iMA(NULL, 0, 5,0, MODE_EMA, PRICE_CLOSE, Current + 0);
double Sell1_2 = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Sell2_1 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Sell2_2 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Sell3_1 = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Sell3_2 = iMA(NULL, 0, 80, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Sell4_1 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Sell4_2 = iMA(NULL, 0, 80, 0, MODE_EMA, PRICE_CLOSE, Current+ 0);
double Sell5_1 = iRSI(NULL, 0, 21, PRICE_CLOSE, Current + 0);
double Sell5_2 = 50;

double CloseBuy1_1 = iMA(NULL, 0,5, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double CloseBuy1_2 = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE,Current + 0);
double CloseBuy2_1 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE,Current + 0);
double CloseBuy2_2 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE,Current + 0);
double CloseBuy3_1 = iRSI(NULL, 0, 21, PRICE_CLOSE, Current +0);
double CloseBuy3_2 = 50;

double CloseSell1_1 = iMA(NULL, 0,5, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double CloseSell1_2 = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE,Current + 0);
double CloseSell2_1 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE,Current + 0);
double CloseSell2_2 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE,Current + 0);
double CloseSell3_1 = iRSI(NULL, 0, 21, PRICE_CLOSE, Current +0);
double CloseSell3_2 = 50;

  
  //+------------------------------------------------------------------+
   //| VariableEnd                                                    |
  //+------------------------------------------------------------------+

   //Checkposition
   bool IsTrade =False;

   for (int i =0; i < Total; i ++) {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if(OrderType() <= OP_SELL&&  OrderSymbol()== Symbol()) {
        IsTrade = True;
        if(OrderType() == OP_BUY) {
           //Close

           //+------------------------------------------------------------------+
           //| Signal Begin(ExitBuy)                                          |
           //+------------------------------------------------------------------+

                    if (CloseBuy1_1 < CloseBuy1_2&& CloseBuy2_1 <CloseBuy2_2 && CloseBuy3_1< CloseBuy3_2) Order = SIGNAL_CLOSEBUY;


           //+------------------------------------------------------------------+
           //| Signal End(ExitBuy)                                            |
           //+------------------------------------------------------------------+

           if (Order == SIGNAL_CLOSEBUY &&((EachTickMode && !TickCheck) ||(!EachTickMode && (Bars !=BarCount)))) {
              OrderClose(OrderTicket(), OrderLots(), Bid, Slippage,MediumSeaGreen);
              if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " +DoubleToStr(Bid, Digits) + " Close Buy");
              if (!EachTickMode) BarCount = Bars;
              IsTrade = False;
              continue;
           }
           //Trailing stop
           if(UseTrailingStop && TrailingStop> 0){                
              if(Bid - OrderOpenPrice() > Point * TrailingStop){
                 if(OrderStopLoss() < Bid - Point * TrailingStop){
                    OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point *TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                    if (!EachTickMode) BarCount = Bars;
                    continue;
                 }
              }
           }
        } else {
           //Close

           //+------------------------------------------------------------------+
           //| Signal Begin(ExitSell)                                         |
           //+------------------------------------------------------------------+

                    if (CloseSell1_1 > CloseSell1_2&& CloseSell2_1 >CloseSell2_2 && CloseSell3_1> CloseSell3_2) Order = SIGNAL_CLOSESELL;


           //+------------------------------------------------------------------+
           //| Signal End(ExitSell)                                           |
           //+------------------------------------------------------------------+

           if (Order == SIGNAL_CLOSESELL &&((EachTickMode && !TickCheck) ||(!EachTickMode && (Bars !=BarCount)))) {
              OrderClose(OrderTicket(), OrderLots(), Ask, Slippage,DarkOrange);
              if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " +DoubleToStr(Ask, Digits) + " Close Sell");
              if (!EachTickMode) BarCount = Bars;
              IsTrade = False;
              continue;
           }
           //Trailing stop
           if(UseTrailingStop && TrailingStop> 0){                
              if((OrderOpenPrice() - Ask) > (Point *TrailingStop)) {
                 if((OrderStopLoss() > (Ask + Point * TrailingStop))|| (OrderStopLoss() == 0)) {
                    OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point *TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                    if (!EachTickMode) BarCount = Bars;
                    continue;
                 }
              }
           }
        }
     }
   }

  //+------------------------------------------------------------------+
   //| SignalBegin(Entry)                                             |
  //+------------------------------------------------------------------+

   if (Buy1_1> Buy1_2 && Buy2_1> Buy2_2 && Buy3_1> Buy3_2 && Buy4_1> Buy4_2 && Buy5_1> Buy5_2) Order = SIGNAL_BUY;

   if (Sell1_1< Sell1_2 && Sell2_1< Sell2_2 && Sell3_1< Sell3_2 && Sell4_1< Sell4_2 && Sell5_1< Sell5_2) Order = SIGNAL_SELL;


  //+------------------------------------------------------------------+
   //| SignalEnd                                                      |
  //+------------------------------------------------------------------+

   //Buy
   if (Order == SIGNAL_BUY&& ((EachTickMode&& !TickCheck) || (!EachTickMode&& (Bars != BarCount)))) {
     if(!IsTrade) {
        //Check free margin
        if (AccountFreeMargin() < (1000 * Lots)) {
           Print("We have no money. Free Margin = ",AccountFreeMargin());
           return(0);
        }

        if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; elseStopLossLevel = 0.0;
        if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; elseTakeProfitLevel = 0.0;

        Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage,StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")",MagicNumber, 0, DodgerBlue);
        if(Ticket > 0) {
           if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("BUYorder opened : ", OrderOpenPrice());
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " +DoubleToStr(Ask, Digits) + " Open Buy");
   } else{
    Print("Erroropening BUY order : ", GetLastError());
   }
        }
        if (EachTickMode) TickCheck = True;
        if (!EachTickMode) BarCount = Bars;
        return(0);
     }
   }

   //Sell
   if (Order == SIGNAL_SELL&& ((EachTickMode&& !TickCheck) || (!EachTickMode&& (Bars != BarCount)))) {
     if(!IsTrade) {
        //Check free margin
        if (AccountFreeMargin() < (1000 * Lots)) {
           Print("We have no money. Free Margin = ",AccountFreeMargin());
           return(0);
        }

        if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; elseStopLossLevel = 0.0;
        if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; elseTakeProfitLevel = 0.0;

        Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage,StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")",MagicNumber, 0, DeepPink);
        if(Ticket > 0) {
           if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("SELLorder opened : ", OrderOpenPrice());
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " +DoubleToStr(Bid, Digits) + " Open Sell");
   } else{
    Print("Erroropening SELL order : ", GetLastError());
   }
        }
        if (EachTickMode) TickCheck = True;
        if (!EachTickMode) BarCount = Bars;
        return(0);
     }
   }

   if(!EachTickMode) BarCount = Bars;

  return(0);
}
//+------------------------------------------------------------------+



本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
关于MT4里BIAS的问题
MT4外汇交易时间限制功能 (转帖)——水行三界 水,因势而汹涌,因容而浩瀚。——东方财富...
新手快速学会怎样编写外汇EA
MT4源码
[i★] 23 副图macd在主图显信号
MT4 单手测试模板
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服