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

智能交易系统 海豚小弟 EA



海豚小弟 EA以中价与均线对比 KD穿越为策略,加入以日线或四时线或参数为止损,跟踪止损以SAR。

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

//+------------------------------------------------------------------+
//|                                                   海豚小弟EA.mq4 |
//|                                    Copyright @2016, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com/"
//+------------------------------------------------------------------+
extern double 手数 = 0.1;
extern int 四小时止损 = 30;
extern int 日线止损 = 60;
extern int 滑点 = 3;

extern int 均线周期 = 208;
extern int KD高分界线 = 55;
extern int KD低分界线 = 45;

extern int 魔术号码 = 1314;

int 最后价1 = 0;
int 最后价2 = 0;

bool cg = false;
//+----------------------------初始化---------------------------------+

int init()
  {
   ObjectCreate("", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("", "海豚小弟", 10, "宋体", SteelBlue);
   ObjectSet("", OBJPROP_XDISTANCE, 10);
   ObjectSet("", OBJPROP_YDISTANCE, 20);
   
   ObjectCreate("", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("", "12345", 10, "宋体", SteelBlue);
   ObjectSet("", OBJPROP_XDISTANCE, 10);
   ObjectSet("", OBJPROP_YDISTANCE, 40);       
   return(0);
  }

//+----------------------反初始化------------------------------------+

int deinit()
  {
   GetLastError(); 
    Comment("www.125808047.com");  
   return(0);
  }

//+-----------------------主函数-------------------------------------+

int start()
   {
   double 均线, 
          KDJ主0, 
          KDJ信0, 
          KDJ主1, 
          KDJ信1;
   
   均线 = iMA(Symbol(), 0, 均线周期, 0, MODE_EMA, PRICE_MEDIAN, 1);
   KDJ主0 = iStochastic(Symbol(), 0, 80, 5, 3, MODE_SMA, 0, MODE_MAIN, 1);
   KDJ信0 = iStochastic(Symbol(), 0, 80, 5, 3, MODE_SMA, 0, MODE_SIGNAL, 1);
   KDJ主1 = iStochastic(Symbol(), 0, 80, 5, 3, MODE_SMA, 0, MODE_MAIN, 2);
   KDJ信1 = iStochastic(Symbol(), 0, 80, 5, 3, MODE_SMA, 0, MODE_SIGNAL, 2);
   
   if ((High[1]+Low[1])/2>均线 && KDJ主0>KDJ信0 && KDJ信0<=KD低分界线 && Time[0]>最后价1)     // 中价大于均线 且KD中主线在上方 且信号线小于55 且当前开盘时间大于最后时间
      {
      if (KDJ主1< KDJ信1)                                                                    // 当KD的主线小于信号线时,即发生交叉
         {
         cg = OrderSend(Symbol(), 
                   OP_BUY,                                                                   // 发送买单
                   手数, 
                   Ask, 
                   滑点, 
                   获得止损子(OP_BUY), 
                   0, 
                   "", 
                   魔术号码, 
                   0, 
                   Blue); 
         最后价1 = Time[0];                                                                   // 将最后时间赋为当前开盘价时间
         return (0); 
         }
      }
  
   else if ((High[1]+Low[1])/2<均线 && KDJ主0<KDJ信0 && KDJ信0>=KD高分界线 && Time[0]>最后价1)
      {
      if (KDJ主1>KDJ信1)
         {
         cg = OrderSend(Symbol(), 
                   OP_SELL,                                                                  // 开卖
                   手数, 
                   Bid, 
                   滑点, 
                   获得止损子(OP_SELL), 
                   0, 
                   "", 
                   魔术号码, 
                   0, 
                   Red);
         最后价1 = Time[0];
         return (0);   
         } 
      }
   
   if (单总数子(魔术号码)>0)                                                                 // 当有单子时
      {
      if (Time[0]>最后价2)                                                                   // 则在当前开盘时间时
         {
          跟踪止损子(魔术号码);                                                              // 修改订单止损
          最后价2 = Time[0]; 
         }
      for (int i=0; i<OrdersTotal(); i++)
         {
         cg = OrderSelect(i, SELECT_BY_POS);
         if (OrderMagicNumber()==魔术号码) break;                                            // (未理解)
         }
      if (OrderType()==OP_BUY)                                                               // 如果为买单时
         {
         if (KDJ主0<KDJ信0 && KDJ信0>=80 && KDJ主1>KDJ信1)                                   // 当现在的KD主线在当前信号线下方,且当前信号线在80以下,且前一主线》前一信号线
            cg = OrderClose(OrderTicket(),                                                        // 平仓(编:原来编号
                       OrderLots(),                                                          // 手: 原来订单手数
                       Bid,                                                                  // 价:  叫买价???
                       滑点,                                                                 // 滑:
                       Pink);                                                                // 色:
         }
      if (OrderType()==OP_SELL)
         {
         if (KDJ主0>KDJ信0 && KDJ信0<=20 && KDJ主1<KDJ信1)
            cg = OrderClose(OrderTicket(), 
                       OrderLots(), 
                       Ask, 
                       滑点,
                       Pink);
         }
      }
//----
   return(0);
  }
  
//+---------------------统计单总数 子函数()--------------------------+

int 单总数子(int 魔术号)
{
   int 总数=0;
   for (int i=0; i<OrdersTotal(); i++){
      cg = OrderSelect(i,SELECT_BY_POS);
      if (OrderMagicNumber()==魔术号){
         总数++;
         }
      }   
   return(总数);
} 

//+---------------------获得止损 子函数()----------------------------+

double 获得止损子(int 买卖类型)
  {
   int 默认止损;
   
   if (Period()==PERIOD_H4) 默认止损=四小时止损;
    else 默认止损=日线止损;
   
   if (买卖类型==OP_BUY)                                                                     // 当买时
      {
      if (Low[2]<Low[1] && (Ask-Low[2])>默认止损*Point)                                      // 如果前二低<前一低 且现在价格-前二低>默认止损
         return (Low[2]);                                                                    // 则返回前二低
      else 
      if (Ask>(Low[1]+默认止损*Point))                                                       // 否则如果 现在价格>前一低+默认止损
         return (Low[1]);                                                                    // 则返回前一低
      else 
         return (NormalizeDouble(Ask-默认止损*Point, Digits));                               // 否则返回现在价格-默认止损
      }
      
   else if (买卖类型==OP_SELL)                                                               // 当为卖时
      {
      if (High[2]>High[1] && (High[2]-Bid)>默认止损*Point)
         return (High[2]);
      else 
      if ((High[1]-Bid)>默认止损*Point)
         return (High[1]);
      else 
         return (NormalizeDouble(Bid+默认止损*Point, Digits));
      }
   return(0);
  }

//+------------------------------------------------------------------+

void 跟踪止损子(int 魔术号){  
  for (int k=0; k<OrdersTotal(); k++){
    cg = OrderSelect(k,SELECT_BY_POS);
    if (OrderMagicNumber()==魔术号){        
      if (   OrderType()==OP_BUY                                                             // 如是为买单 
         && OrderStopLoss()<iSAR(Symbol(), 0, 0.02, 0.2, 1)                                  // 且订单止损价<前一抛物线
         && Ask>iSAR(Symbol(), 0, 0.02, 0.2, 1)) {                                           // 且现在价格>前一抛物线
         if (!OrderModify(OrderTicket(),                                                     // 跟踪修改 (编:
                          OrderOpenPrice(),                                                  // 价:
                          iSAR(Symbol(), 0, 0.02, 0.2, 1),                                   // 损:前一抛物线值
                          0,                                                                 // 赢:
                          0,                                                                 // 效:
                          Blue)){                                                            // 色:
            Print("Buy跟踪止损修改出错 :"+GetLastError());
            }    
         }
      if (  OrderType()==OP_SELL 
         && OrderStopLoss()>iSAR(Symbol(), 0, 0.02, 0.2, 1) 
         && Bid<iSAR(Symbol(), 0, 0.02, 0.2, 1)) {
         if (!OrderModify(OrderTicket(),
                          OrderOpenPrice(),
                          iSAR(Symbol(), 0, 0.02, 0.2, 1),
                          0,
                          0,
                          Red)){
            Print("Sell单跟踪止损修改出错 :"+GetLastError());  
            }
         }
       }
  }
}

//+------------------------------------------------------------------+
如您喜欢此文章请点下面分享按钮↴峰汇在线 » 智能交易系统 海豚小弟 EA
上一篇:
下一篇:
分享到:更多 ()