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

非常简洁且功能齐全的均线 EA



非常简洁且功能齐全的均线 EA 部分自定义函数采用中文,在编程技巧上面简洁精悍。十分有益于新手学习编程技巧。遗憾之处找不到作者相关信息。

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

//+------------------------------------------------------------------+
//|                                   非常简洁且功能齐全的均线EA.mq4 |
//|                                     Copyright 2016, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com/"
//+------------------------------------------------------------------+

  extern double 赢利目标 = 200;
  extern double 止损 = 300;
  extern double 手数 = 2;
  extern double 跟踪止赢 = 50;
  extern int 短均周期 = 5;
  extern int 长均周期 = 60;
  bool cg = false;
  //+---------------------------主函数---------------------------------+
 
void deinit() {
   Comment("www.125808047.com");
}
 
  
  int start() 
      {
       int cnt, 
           编号, 
           单总数;
       double 短均, 
             长均;

       if (Bars < 100) 
          {
           Print("bars less than 100");
           return (0);
          }

       if (赢利目标 < 10) 
            {
            Print("赢利目标低于 10");
            return (0); 
            }

       短均 = iMA(NULL, 0, 短均周期, 0, MODE_EMA, PRICE_CLOSE, 0);
       长均 = iMA(NULL, 0, 长均周期, 0, MODE_EMA, PRICE_CLOSE, 0);

       static int 穿越 = 0;
       穿越 = 穿越子函数(长均, 短均);

       单总数 = OrdersTotal();
       if (单总数 < 1) 
          {
           if (穿越 == 1)  // 满足空仓条件,开空仓
              {
               编号 = OrderSend(Symbol(),
                                OP_SELL, 
                                手数, 
                                Bid, 
                                3, 
                                Bid + 止损 * Point,
                                Bid - 赢利目标 * Point,
                                "EMA_CROSS", 
                                12345, 
                                0, 
                                Green);
              if (编号 > 0) 
                 {
                  if (OrderSelect(编号, SELECT_BY_TICKET, MODE_TRADES))
                      Print("SELL单开在: ", OrderOpenPrice());
                 } 
               else
                  Print("开卖单出错: ", GetLastError());
              return (0);
              }
           if (穿越 == 2) // 满足多仓条件,开多仓
              {
               编号 = OrderSend(Symbol(), 
                                OP_BUY, 
                                手数, 
                                Ask, 
                                3, 
                                Ask - 止损 * Point,
                                Ask + 赢利目标 * Point, 
                                "EMA_CROSS", 
                                12345, 
                                0, 
                                Red);
               if (编号 > 0) 
                  {
                   if (OrderSelect(编号, SELECT_BY_TICKET, MODE_TRADES))
                      Print("BUY单开在: ", OrderOpenPrice());
                  } 
                else
                   Print("开买单出错 : ", GetLastError());
               return (0);
               }
           return (0);
           }
           
//---- 跟踪止盈止损
       for (cnt = 0; cnt < 单总数; cnt++) 
           {
           cg = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
              if (OrderType() <= OP_SELL && OrderSymbol() == Symbol()) 
                 {
                  if (OrderType() == OP_SELL) // long position is opened
                     {
//----跟踪止损
                      if (跟踪止赢 > 0) 
                         {
                          if (Bid - OrderOpenPrice() > Point * 跟踪止赢) 
                             {
                              if (OrderStopLoss() < Bid - Point * 跟踪止赢) 
                                 {
                                  cg = OrderModify(OrderTicket(), 
                                              OrderOpenPrice(),
                                              Bid - Point * 跟踪止赢,
                                              OrderTakeProfit(), 
                                              0, 
                                              Green);
                                  return (0);
                                 }
                             }
                         }
                     } 
                   else // go to short position
                     {
// check for trailing stop
                      if (跟踪止赢 > 0) 
                         {
                          if ((OrderOpenPrice() - Ask) > (Point * 跟踪止赢)) 
                             {
                              if ((OrderStopLoss() > (Ask + Point * 跟踪止赢))) 
                                 {
                                  cg = OrderModify(OrderTicket(), 
                                              OrderOpenPrice(),
                                              Ask + Point * 跟踪止赢,
                                              OrderTakeProfit(), 
                                              0, 
                                              Red);
                                  return (0);
                                  }
                             }
                         }
                     }
                 }
           }
  //----
       return (0);
       }
       
  //+-----------------------穿越 子函数()------------------------------+
  
  // 移动平均线多空条件判断,
  int 穿越子函数(double 线1, double 线2) 
     {
      static int 最后方向 = 0;
      static int 当前方向 = 0;
 //首个load不工作, 等待第一次穿越!
      static bool 第一时间 = true;
      if (第一时间 == true) 
         {
         第一时间 = false;
         return (0);
         }
  //----因主循环中有单数限制,所以当大于时下单后不会再不停下单
      if (线1 > 线2)
         当前方向 = 2; //多头市场 上穿做多
      if (线1 < 线2)
         当前方向 = 1; //空头市场 下穿做空
  //----
      if (当前方向 != 最后方向)  //changed 
         {
         最后方向 = 当前方向;
         return(最后方向);
         }
      else
         {
         return (0);  //方向未改变
         }
     }
  //+--------------------------------------------------------------------+

 

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 非常简洁且功能齐全的均线 EA
上一篇:
下一篇:
分享到:更多 ()