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

一套顺势加码EA的源码



该EA通过特定的条件进行顺势加码。

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

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

extern bool auto_close_order = FALSE;
int gi_unused_80 = 7;
double gd_unused_96 = 0.0;
bool gi_unused_104 = TRUE;
bool gi_unused_108 = TRUE;
bool gi_unused_112 = TRUE;
bool gi_unused_116 = TRUE;
double gd_unused_120 = 0.0001;
extern double Lots = 0.1;
extern int MA1_Period = 50;
extern int MA2_Period = 150;
extern int MA3_Period = 10;
extern int MA4_Period = 20;
int g_applied_price_152 = PRICE_OPEN;
int g_ma_method_156 = MODE_SMA;
extern double ProfitMade = 10.0;
extern double LossLimit = 115.0;
extern int PLBreakEven = 9999;
int g_slippage_180 = 2;
int g_magic_184 = EMPTY_VALUE;
string g_comment_188 = "Divergence_07_";
int g_time_196 = 0;
int g_count_200 = 0;
int g_count_204 = 0;
int gi_unused_208 = 0;
bool gi_212 = TRUE;


int init() {
   string dbl2str_4;
   for (int count_0 = 0; count_0 < Bars; count_0++) {
      dbl2str_4 = DoubleToStr(count_0, 0);
      ObjectDelete("myx" + dbl2str_4);
      ObjectDelete("myz" + dbl2str_4);
   }
   g_count_204 = 0;
   ObjectDelete("Cmmt");
   ObjectCreate("Cmmt", OBJ_TEXT, 0, Time[20], High[20] + 5.0 * Point);
   ObjectSetText("Cmmt", "Divergence=X.XXXX", 10, "Arial", White);
   Print("Init happened ", TimeCurrent());
   Comment(" ");
   return (0);
}

int deinit() {
   string dbl2str_4;
   for (int count_0 = 0; count_0 < Bars; count_0++) {
      dbl2str_4 = DoubleToStr(count_0, 0);
      ObjectDelete("myx" + dbl2str_4);
      ObjectDelete("myz" + dbl2str_4);
   }
   g_count_204 = 0;
   Print("DE-Init happened ", TimeCurrent());
   Comment(" ");
   return (0);
}

int start() {
   int li_unused_0 = 1;
   double point_4 = Point;
   double ld_12 = Ask - Bid;
   int order_total_20 = 0;
   int error_24 = 0;
   int count_28 = 0;
   double price_32 = 0;
   double price_40 = 0;
   double ld_48 = 0;
   double ld_unused_56 = 0;
   bool li_64 = FALSE;
   bool li_68 = FALSE;
   if (g_time_196 != Time[0]) {
      g_time_196 = Time[0];
      g_count_200++;
      g_count_204++;
      gi_212 = TRUE;
   }
   count_28 = 0;
   for (order_total_20 = OrdersTotal(); order_total_20 >= 0; order_total_20--) {
      bool cg = OrderSelect(order_total_20, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_184) count_28++;
   }
   double high_104 = High[1];
   double low_112 = Low[1];
   double open_120 = Open[0];
   double ima_72 = iMA(Symbol(), 0, MA1_Period, 0, g_ma_method_156, g_applied_price_152, 1);
   double ima_80 = iMA(Symbol(), 0, MA2_Period, 0, g_ma_method_156, g_applied_price_152, 1);
   double ima_88 = iMA(Symbol(), 0, MA3_Period, 0, g_ma_method_156, g_applied_price_152, 1);
   double ima_96 = iMA(Symbol(), 0, MA4_Period, 0, g_ma_method_156, g_applied_price_152, 1);
   double ima_128 = iMA(Symbol(), 0, MA3_Period, 0, g_ma_method_156, g_applied_price_152, 0);
   double ima_136 = iMA(Symbol(), 0, MA3_Period, 0, g_ma_method_156, g_applied_price_152, 2);
   double istochastic_144 = iStochastic(Symbol(), 0, 10, 5, 5, MODE_SMA, 1, MODE_MAIN, 1);
   double istochastic_152 = iStochastic(Symbol(), 0, 10, 5, 5, MODE_SMA, 1, MODE_SIGNAL, 1);
   if (auto_close_order) {
      if (ima_88 > ima_96) f0_0(OP_SELL, 0);
      if (ima_88 < ima_96) f0_0(OP_BUY, 0);
   }
   if (high_104 > ima_72 && low_112 > ima_72 && open_120 > ima_72 && high_104 > ima_88 && 
open_120 > ima_88 && open_120 > ima_80 && ima_72 > ima_80 && ima_88 > ima_96 &&
      ima_128 > ima_88 && ima_88 > ima_136) li_64 = TRUE;
   if (high_104 < ima_72 && low_112 < ima_72 && open_120 < ima_72 && low_112 < ima_88 && 
open_120 < ima_88 && open_120 < ima_80 && ima_72 < ima_80 && ima_88 < ima_96 &&
      ima_128 < ima_88 && ima_88 < ima_136) li_68 = TRUE;
   if (gi_212 && li_64) {
      f0_0(OP_SELL, 0);
      if (LossLimit == 0.0) price_32 = 0;
      else price_32 = Ask - (LossLimit + 7.0) * Point;
      if (ProfitMade == 0.0) price_40 = 0;
      else price_40 = Ask + (ProfitMade + 7.0) * Point;
      cg = OrderSend(Symbol(), OP_BUY, Lots, Ask, g_slippage_180, price_32, price_40, g_comment_188, 
g_magic_184, 16777215);
      error_24 = GetLastError();
      if (error_24 == 0/* NO_ERROR */) {
         Print("BUY  Ask=", Ask, " bartick=", g_count_200);
         ObjectCreate("myx" + DoubleToStr(g_count_204, 0), OBJ_TEXT, 0, Time[0], High[0] + 5.0 * point_4);
         ObjectSetText("myx" + DoubleToStr(g_count_204, 0), "B", 15, "Arial", Red);
         g_count_200 = 0;
         gi_212 = FALSE;
      } else Print("-----ERROR----- BUY  Ask=", Ask, " error=", error_24, " bartick=", g_count_200);
   }
   if (gi_212 && li_68) {
      f0_0(OP_BUY, 0);
      if (LossLimit == 0.0) price_32 = 0;
      else price_32 = Bid + (LossLimit + 7.0) * Point;
      if (ProfitMade == 0.0) price_40 = 0;
      else price_40 = Bid - (ProfitMade + 7.0) * Point;
      cg = OrderSend(Symbol(), OP_SELL, Lots, Bid, g_slippage_180, price_32, price_40, g_comment_188, 
g_magic_184, 255);
      error_24 = GetLastError();
      if (error_24 == 0/* NO_ERROR */) {
         Print("SELL Bid=", Bid, " bartick=", g_count_200);
         ObjectCreate("myx" + DoubleToStr(g_count_204, 0), OBJ_TEXT, 0, Time[0], High[0] + 5.0 * point_4);
         ObjectSetText("myx" + DoubleToStr(g_count_204, 0), "S", 15, "Arial", Red);
         g_count_200 = 0;
         gi_212 = FALSE;
      } else Print("-----ERROR----- SELL Bid=", Bid, " error=", error_24, " bartick=", g_count_200);
   }
   for (order_total_20 = OrdersTotal(); order_total_20 >= 0; order_total_20--) {
      cg = OrderSelect(order_total_20, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_184) {
         if (OrderType() == OP_BUY) {
            ld_48 = Bid - OrderOpenPrice();
            if (ld_48 >= PLBreakEven * point_4 && OrderOpenPrice() > OrderStopLoss()) {
               price_32 = OrderOpenPrice() + 2.0 * ld_12;
               price_40 = OrderTakeProfit();
               cg = OrderModify(OrderTicket(), OrderOpenPrice(), price_32, price_40, 16777215);
               error_24 = GetLastError();
               if (error_24 == 0/* NO_ERROR */) {
                  Print("MODIFY BREAKEVEN BUY  Bid=", Bid, " bartick=", g_count_200);
                  ObjectCreate("myz" + DoubleToStr(g_count_204, 0), OBJ_TEXT, 0, Time[0], Low[0] - 7.0 * point_4);
                  ObjectSetText("myz" + DoubleToStr(g_count_204, 0), "BE", 15, "Arial", White);
               } else Print("-----ERROR----- MODIFY BREAKEVEN BUY  Bid=", Bid, " error=", error_24,
 " bartick=", g_count_200);
            }
            if ((ProfitMade > 0.0 && ld_48 >= ProfitMade * point_4) || (LossLimit > 0.0 && 
ld_48 <= (-1.0 * LossLimit) * point_4)) {
               cg = OrderClose(OrderTicket(), Lots, Bid, g_slippage_180, White);
               error_24 = GetLastError();
               if (error_24 == 0/* NO_ERROR */) {
                  Print("CLOSE BUY  Bid=", Bid, " bartick=", g_count_200);
                  ObjectCreate("myz" + DoubleToStr(g_count_204, 0), OBJ_TEXT, 0, Time[0], Low[0] - 7.0 * point_4);
                  ObjectSetText("myz" + DoubleToStr(g_count_204, 0), "C", 15, "Arial", White);
               } else Print("-----ERROR----- CLOSE BUY  Bid=", Bid, " error=", error_24, " bartick=", 
g_count_200);
            }
         }
         if (OrderType() == OP_SELL) {
            ld_48 = OrderOpenPrice() - Ask;
            if (ld_48 >= PLBreakEven * point_4 && OrderOpenPrice() < OrderStopLoss()) {
               price_32 = OrderOpenPrice() - 2.0 * ld_12;
               price_40 = OrderTakeProfit();
               cg = OrderModify(OrderTicket(), OrderOpenPrice(), price_32, price_40, 255);
               error_24 = GetLastError();
               if (error_24 == 0/* NO_ERROR */) {
                  Print("MODIFY BREAKEVEN SELL Ask=", Ask, " bartick=", g_count_200);
                  ObjectCreate("myz" + DoubleToStr(g_count_204, 0), OBJ_TEXT, 0, Time[0], Low[0] - 7.0 * point_4);
                  ObjectSetText("myz" + DoubleToStr(g_count_204, 0), "BE", 15, "Arial", Red);
               } else Print("-----ERROR----- MODIFY BREAKEVEN SELL Ask=", Ask, " error=", error_24, " bartick=", 
g_count_200);
            }
            if ((ProfitMade > 0.0 && ld_48 >= ProfitMade * point_4) || (LossLimit > 0.0 && ld_48 <= 
(-1.0 * LossLimit) * point_4)) {
               cg = OrderClose(OrderTicket(), Lots, Ask, g_slippage_180, Red);
               error_24 = GetLastError();
               if (error_24 == 0/* NO_ERROR */) {
                  Print("CLOSE SELL Ask=", Ask, " bartick=", g_count_200);
                  ObjectCreate("myz" + DoubleToStr(g_count_204, 0), OBJ_TEXT, 0, Time[0], Low[0] - 7.0 * point_4);
                  ObjectSetText("myz" + DoubleToStr(g_count_204, 0), "C", 15, "Arial", Red);
                  continue;
               }
               Print("-----ERROR----- CLOSE SELL Ask=", Ask, " error=", error_24, " bartick=", g_count_200);
            }
         }
      }
   }
   return (0);
}


int f0_0(int a_cmd_0, int ai_4) {
   double price_8;
   if (a_cmd_0 == OP_BUY) price_8 = Bid;
   else price_8 = Ask;
   for (int order_total_16 = OrdersTotal(); order_total_16 >= 0; order_total_16--) {
      bool cg = OrderSelect(order_total_16, SELECT_BY_POS);
      if (OrderSymbol() == Symbol()) {
         if (OrderType() == a_cmd_0) {
            if (ai_4 == 0) cg = OrderClose(OrderTicket(), OrderLots(), price_8, g_slippage_180, Red);
            if (ai_4 == 1)
               if (OrderTakeProfit() > 0.0) cg = OrderClose(OrderTicket(), OrderLots(), price_8, 
g_slippage_180, Red);
         }
      }
   }
   return (0);
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 一套顺势加码EA的源码
上一篇:
下一篇:
分享到:更多 ()