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

智能交易系统 ANLY EA



ANLY EA依照MACD信号在进行开仓平仓交易。

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

//+------------------------------------------------------------------+
//|                                                      ANLY EA.mq4 |
//|                          TradeMater , www.forex-trade-master.com |
//+------------------------------------------------------------------+
#property copyright "TradeMater , www.forex-trade-master.com"
#property link      "http://www.forex-trade-master.com/"

extern int FastEMA = 12;
extern int SlowEMA = 26;
extern int MACD_SMA = 9;
extern double Lots = 0.1;
extern int mm = 0;
extern double Risk = 10.0;
extern int StopLoss = 0;
extern int TakeProfit = 0;
bool gi_116 = FALSE;
extern bool Reverse = FALSE;
extern int TrailingStop = 0;
extern int TrailingStep = 1;
extern int BreakEven = 0;
extern int MagicNumber = 0;
extern int Repeat = 3;
extern int Periods = 5;
extern bool UseAlert = FALSE;
extern bool SendEmail = FALSE;
extern string TradeLog = "MACD EA";
extern int Slippage = 3;
int gi_168 = 0;
int g_datetime_172 = 0;
double gd_176 = 0.0;
double gd_184 = 0.0;
int gi_192 = 0;
double gd_196 = 300.0;
extern string Indicator_Setting = "---------- Indicator Setting";
int gi_212 = 1;
int gi_216 = 1;
double gd_220 = 0.0;
int gi_228 = 7;
int gi_232 = 0;
string gs_unused_236 = "alert.wav";
double gd_unused_244 = 0.0;
double gd_unused_252 = 0.0;
int gi_unused_260 = 0;
string g_name_264 = "";
int gi_272 = 0;
bool cg = false;

int init() {
   gi_168 = Repeat;
   return (0);
}

void deinit() {
   Comment("www.125808047.com");
}

int start() {
   double l_imacd_28;
   double l_imacd_36;
   double l_imacd_44;
   if (gi_116) gi_192 = 1;
   else gi_192 = 0;
   g_name_264 = Symbol() + TradeLog + "-" + Month() + "-" + Day() + ".log";
   gi_unused_260 = MarketInfo(Symbol(), MODE_SPREAD);
   int l_pos_0 = 0;
   double ld_4 = 0;
   double ld_12 = 0;
   ld_4 = 0;
   ld_12 = 0;
   if (CntOrd(OP_BUY, MagicNumber) > 0) gi_232 = 1;
   if (CntOrd(OP_SELL, MagicNumber) > 0) gi_232 = -1;
   int li_unused_20 = 0;
   int li_24 = 100;
   for (int l_shift_52 = 1; l_shift_52 <= li_24; l_shift_52++) {
      l_imacd_28 = iMACD(NULL, 0, FastEMA, SlowEMA, MACD_SMA, PRICE_CLOSE, MODE_MAIN, l_shift_52);
      l_imacd_36 = iMACD(NULL, 0, FastEMA, SlowEMA, MACD_SMA, PRICE_CLOSE, MODE_MAIN, l_shift_52 + 1);
      l_imacd_44 = iMACD(NULL, 0, FastEMA, SlowEMA, MACD_SMA, PRICE_CLOSE, MODE_MAIN, l_shift_52 + 2);
      if (l_imacd_28 > 0.0 && l_imacd_36 < 0.0 && l_imacd_44 < 0.0) {
         if (Reverse) {
            ld_12 = 1;
            break;
         }
         ld_4 = 1;
         break;
      }
      if (l_imacd_28 < 0.0 && l_imacd_36 > 0.0 && l_imacd_44 > 0.0) {
         if (Reverse) {
            ld_4 = 1;
            break;
         }
         ld_12 = 1;
         break;
      }
   }
   int l_pos_56 = 0;
   int l_count_60 = 0;
   bool li_64 = FALSE;
   bool li_68 = FALSE;
   bool li_72 = FALSE;
   bool li_76 = FALSE;
   double ld_unused_80 = 0;
   double ld_unused_88 = 0;
   double ld_unused_96 = 0;
   bool li_104 = FALSE;
   bool li_108 = TRUE;
   if (li_108 == TRUE) {
      li_108 = FALSE;
      gi_272 = Time[0];
   }
   if (gi_272 == Time[0] && TimeCurrent() - gi_272 > gd_196) li_104 = FALSE;
   else {
      gi_272 = Time[0];
      li_104 = TRUE;
   }
   bool li_112 = FALSE;
   bool li_116 = FALSE;
   if (TimeCurrent() >= Time[0] + 60 * Period() - gd_176) li_112 = TRUE;
   else li_112 = FALSE;
   if (TimeCurrent() >= Time[0] + 60 * Period() - gd_184) li_116 = TRUE;
   else li_116 = FALSE;
   if (gd_176 == 0.0) li_112 = TRUE;
   if (gd_184 == 0.0) li_116 = TRUE;
   gd_220 = Lots;
   if (mm < 0) {
      gd_220 = MathCeil(AccountEquity() * Risk / 10000.0) / 10.0 - 0.1;
      if (gd_220 < 0.1) gd_220 = 0.1;
   }
   if (mm > 0) {
      gd_220 = MathCeil(AccountEquity() * Risk / 10000.0) / 10.0 - 1.0;
      if (gd_220 > 1.0) gd_220 = MathCeil(gd_220);
      if (gd_220 < 1.0) gd_220 = 1;
   }
   if (gd_220 > 100.0) gd_220 = 100;
   l_count_60 = 0;
   for (l_pos_56 = 0; l_pos_56 < OrdersTotal(); l_pos_56++) {
      cg = OrderSelect(l_pos_56, SELECT_BY_POS, MODE_TRADES);
      if ((OrderType() == OP_SELL || OrderType() == OP_BUY) && OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumber || MagicNumber == 0)) l_count_60++;
   }
   if (l_count_60 >= 1) {
      li_64 = FALSE;
      li_68 = FALSE;
   }
   li_68 = FALSE;
   li_64 = FALSE;
   if (ld_12 > 0.0) {
      li_64 = TRUE;
      li_68 = FALSE;
   }
   if (ld_4 > 0.0) {
      li_68 = TRUE;
      li_64 = FALSE;
   }
   if (ld_12 > 0.0) li_76 = TRUE;
   if (ld_4 > 0.0) li_72 = TRUE;
   subPrintDetails();
   for (l_pos_56 = 0; l_pos_56 < OrdersTotal(); l_pos_56++) {
     cg =  OrderSelect(l_pos_56, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumber || MagicNumber == 0)) {
         if (li_76 == TRUE && li_116 == TRUE) {
            if (li_104 == TRUE && gi_192 > 0) {
               SetText(Time[0], High[0] + 1 * gi_228 * Point, "CloseBuy" + DoubleToStr(Time[0], 0), CharToStr(251), 16711935);
               PlaySound("alert.wav");
               OrdClose(OrderTicket(), OrderLots(), Bid, Slippage, Red);
               Alerts(0, 0, li_76, li_72, Bid, 0, 0, OrderTicket());
               return (0);
            }
            if (gi_192 == 0) {
               SetText(Time[0], High[0] + 1 * gi_228 * Point, "CloseBuy" + DoubleToStr(Time[0], 0), CharToStr(251), 16711935);
               PlaySound("alert.wav");
               OrdClose(OrderTicket(), OrderLots(), Bid, Slippage, Red);
               Alerts(0, 0, li_76, li_72, Bid, 0, 0, OrderTicket());
               return (0);
            }
         }
      }
      if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumber || MagicNumber == 0)) {
         if (li_72 == TRUE && li_116 == TRUE) {
            if (li_104 == TRUE && gi_192 > 0) {
               SetText(Time[0], High[0] - 0.3 * gi_228 * Point, "CloseSell" + DoubleToStr(Time[0], 0), CharToStr(251), 16711935);
               PlaySound("alert.wav");
               OrdClose(OrderTicket(), OrderLots(), Ask, Slippage, Red);
               Alerts(0, 0, li_76, li_72, Ask, 0, 0, OrderTicket());
               return (0);
            }
            if (gi_192 == 0) {
               SetText(Time[0], High[0] - 0.3 * gi_228 * Point, "CloseSell" + DoubleToStr(Time[0], 0), CharToStr(251), 16711935);
               PlaySound("alert.wav");
               OrdClose(OrderTicket(), OrderLots(), Ask, Slippage, Red);
               Alerts(0, 0, li_76, li_72, Ask, 0, 0, OrderTicket());
               return (0);
            }
         }
      }
   }
   double ld_120 = 0;
   double ld_128 = 0;
   int li_136 = 0;
   if (l_count_60 == 0) {
      if (li_64 == TRUE && li_112 == TRUE) {
         if (li_104 == TRUE && gi_192 > 0) {
            SetText(Time[0], High[0] + 1 * gi_228 * Point, "Sell" + DoubleToStr(Time[0], 0), CharToStr(234), 255);
            if (TakeProfit == 0) ld_128 = 0;
            else ld_128 = Bid - TakeProfit * Point;
            if (StopLoss == 0) ld_120 = 0;
            else ld_120 = Bid + StopLoss * Point;
            PlaySound("alert.wav");
            li_136 = OrdSend(Symbol(), 1, gd_220, Bid, Slippage, ld_120, ld_128, "MACD EA", MagicNumber, 0, Red);
            Alerts(li_68, li_64, 0, 0, Bid, ld_120, ld_128, li_136);
            li_64 = FALSE;
            return (0);
         }
         if (gi_192 == 0) {
            SetText(Time[0], High[0] + 1 * gi_228 * Point, "Sell" + DoubleToStr(Time[0], 0), CharToStr(234), 255);
            if (TakeProfit == 0) ld_128 = 0;
            else ld_128 = Bid - TakeProfit * Point;
            if (StopLoss == 0) ld_120 = 0;
            else ld_120 = Bid + StopLoss * Point;
            PlaySound("alert.wav");
            li_136 = OrdSend(Symbol(), 1, gd_220, Bid, Slippage, ld_120, ld_128, "MACD EA", MagicNumber, 0, Red);
            Alerts(li_68, li_64, 0, 0, Bid, ld_120, ld_128, li_136);
            li_64 = FALSE;
            return (0);
         }
      }
      if (li_68 == TRUE && li_112 == TRUE) {
         if (li_104 == TRUE && gi_192 > 0) {
            SetText(Time[0], Low[0] - 0.3 * gi_228 * Point, "Buy" + DoubleToStr(Time[0], 0), CharToStr(233), 65280);
            if (TakeProfit == 0) ld_128 = 0;
            else ld_128 = Ask + TakeProfit * Point;
            if (StopLoss == 0) ld_120 = 0;
            else ld_120 = Ask - StopLoss * Point;
            PlaySound("alert.wav");
            li_136 = OrdSend(Symbol(), 0, gd_220, Ask, Slippage, ld_120, ld_128, "MACD EA", MagicNumber, 0, Lime);
            Alerts(li_68, li_64, 0, 0, Ask, ld_120, ld_128, li_136);
            li_68 = FALSE;
            return (0);
         }
         if (gi_192 == 0) {
            SetText(Time[0], Low[0] - 0.3 * gi_228 * Point, "Buy" + DoubleToStr(Time[0], 0), CharToStr(233), 65280);
            if (TakeProfit == 0) ld_128 = 0;
            else ld_128 = Ask + TakeProfit * Point;
            if (StopLoss == 0) ld_120 = 0;
            else ld_120 = Ask - StopLoss * Point;
            PlaySound("alert.wav");
            li_136 = OrdSend(Symbol(), 0, gd_220, Ask, Slippage, ld_120, ld_128, "MACD EA", MagicNumber, 0, Lime);
            Alerts(li_68, li_64, 0, 0, Ask, ld_120, ld_128, li_136);
            li_68 = FALSE;
            return (0);
         }
      }
   }
   for (l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
      if (OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES))
         if (OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumber || MagicNumber == 0)) TrailingPositions();
   }
   Alerts(0, 0, 0, 0, 0, 0, 0, 0);
   return (0);
}

void SetText(int ai_unused_0, double ad_unused_4, string as_unused_12, string as_unused_20, int ai_unused_28) {
}

void Alerts(int ai_0, int ai_4, int ai_8, int ai_12, double ad_16, double ad_24, double ad_32, int ai_40) {
   string ls_44 = "";
   ls_44 = "";
   string l_time2str_52 = "";
   l_time2str_52 = TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES);
   if (UseAlert) {
      if (ai_0 == 1) {
         if (gi_168 == Repeat) g_datetime_172 = 0;
         if (gi_168 > 0 && TimeCurrent() - g_datetime_172 > Periods) {
            if (ai_0 == 1) {
               ls_44 = ls_44 + "Buy @ " + DoubleToStr(ad_16, Digits) + "; SL: " + DoubleToStr(ad_24, Digits) + "; TP: " + DoubleToStr(ad_32, Digits) + " at " + l_time2str_52 + " Order:" + DoubleToStr(ai_40, 0) + ".";
               Alert(Symbol(), " ", Period(), ": ", ls_44);
               if (SendEmail) SendMail(Symbol() + " " + Period() + ": ", Symbol() + " " + Period() + ": " + ls_44);
               gi_168--;
               g_datetime_172 = TimeCurrent();
            }
         }
      }
      if (ai_4 == 1) {
         if (gi_168 == Repeat) g_datetime_172 = 0;
         if (gi_168 > 0 && TimeCurrent() - g_datetime_172 > Periods) {
            if (ai_4 == 1) {
               ls_44 = ls_44 + "Sell @ " + DoubleToStr(ad_16, Digits) + "; SL: " + DoubleToStr(ad_24, Digits) + "; TP: " + DoubleToStr(ad_32, Digits) + " at " + l_time2str_52 + " Order:" + DoubleToStr(ai_40, 0) + ".";
               Alert(Symbol(), " ", Period(), ": ", ls_44);
               if (SendEmail) SendMail(Symbol() + " " + Period() + ": ", Symbol() + " " + Period() + ": " + ls_44);
               gi_168--;
               g_datetime_172 = TimeCurrent();
            }
         }
      }
      if (ai_12 == 1) {
         if (gi_168 == Repeat) g_datetime_172 = 0;
         if (gi_168 > 0 && TimeCurrent() - g_datetime_172 > Periods) {
            if (ai_12 == 1) {
               ls_44 = ls_44 + " Close Sell @ " + DoubleToStr(ad_16, Digits) + " at " + l_time2str_52 + " Order:" + DoubleToStr(ai_40, 0) + ".";
               Alert(Symbol(), " ", Period(), ": ", ls_44);
               if (SendEmail) SendMail(Symbol() + " " + Period() + ": ", Symbol() + " " + Period() + ": " + ls_44);
               gi_168--;
               g_datetime_172 = TimeCurrent();
            }
         }
      }
      if (ai_8 == 1) {
         if (gi_168 == Repeat) g_datetime_172 = 0;
         if (gi_168 > 0 && TimeCurrent() - g_datetime_172 > Periods) {
            if (ai_8 == 1) {
               ls_44 = ls_44 + " Close Buy @ " + DoubleToStr(ad_16, Digits) + " at " + l_time2str_52 + " Order:" + DoubleToStr(ai_40, 0) + ".";
               Alert(Symbol(), " ", Period(), ": ", ls_44);
               if (SendEmail) SendMail(Symbol() + " " + Period() + ": ", Symbol() + " " + Period() + ": " + ls_44);
               gi_168--;
               g_datetime_172 = TimeCurrent();
            }
         }
      }
      if (ai_8 == 0 && ai_12 == 0 && ai_0 == 0 && ai_4 == 0) {
         gi_168 = Repeat;
         g_datetime_172 = 0;
      }
   }
}

void subPrintDetails() {
   string ls_0 = "";
   string ls_8 = "----------------------------------------\n";
   string ls_16 = "\n";
   string ls_unused_24 = "";
   ls_0 = "MACD EA" + ls_16;
   ls_0 = ls_0 + "StopLoss=" + DoubleToStr(StopLoss, 0) + " | ";
   ls_0 = ls_0 + "TakeProfit=" + DoubleToStr(TakeProfit, 0) + " | ";
   ls_0 = ls_0 + "TrailingStop=" + DoubleToStr(TrailingStop, 0) + ls_16;
   ls_0 = ls_0 + ls_8;
   ls_0 = ls_0 + "Lots=" + DoubleToStr(gd_220, 2) + " | ";
   ls_0 = ls_0 + "LastTrade=" + DoubleToStr(gi_232, 0) + ls_16;
   ls_0 = ls_0 + ls_8;
   Comment(ls_0);
}

int CntOrd(int a_cmd_0, int a_magic_4) {
   int l_count_8 = 0;
   for (int l_pos_12 = 0; l_pos_12 < OrdersTotal(); l_pos_12++) {
      cg = OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol())
         if (OrderType() == a_cmd_0 && (OrderMagicNumber() == a_magic_4 || a_magic_4 == 0)) l_count_8++;
   }
   return (l_count_8);
}

string ErrorDescription(int ai_0) {
   string ls_ret_4;
   switch (ai_0) {
   case 0:
   case 1:
      ls_ret_4 = "no error";
      break;
   case 2:
      ls_ret_4 = "common error";
      break;
   case 3:
      ls_ret_4 = "invalid trade parameters";
      break;
   case 4:
      ls_ret_4 = "trade server is busy";
      break;
   case 5:
      ls_ret_4 = "old version of the client terminal";
      break;
   case 6:
      ls_ret_4 = "no connection with trade server";
      break;
   case 7:
      ls_ret_4 = "not enough rights";
      break;
   case 8:
      ls_ret_4 = "too frequent requests";
      break;
   case 9:
      ls_ret_4 = "malfunctional trade operation";
      break;
   case 64:
      ls_ret_4 = "account disabled";
      break;
   case 65:
      ls_ret_4 = "invalid account";
      break;
   case 128:
      ls_ret_4 = "trade timeout";
      break;
   case 129:
      ls_ret_4 = "invalid price";
      break;
   case 130:
      ls_ret_4 = "invalid stops";
      break;
   case 131:
      ls_ret_4 = "invalid trade volume";
      break;
   case 132:
      ls_ret_4 = "market is closed";
      break;
   case 133:
      ls_ret_4 = "trade is disabled";
      break;
   case 134:
      ls_ret_4 = "not enough money";
      break;
   case 135:
      ls_ret_4 = "price changed";
      break;
   case 136:
      ls_ret_4 = "off quotes";
      break;
   case 137:
      ls_ret_4 = "broker is busy";
      break;
   case 138:
      ls_ret_4 = "requote";
      break;
   case 139:
      ls_ret_4 = "order is locked";
      break;
   case 140:
      ls_ret_4 = "long positions only allowed";
      break;
   case 141:
      ls_ret_4 = "too many requests";
      break;
   case 145:
      ls_ret_4 = "modification denied because order too close to market";
      break;
   case 146:
      ls_ret_4 = "trade context is busy";
      break;
   case 4000:
      ls_ret_4 = "no error";
      break;
   case 4001:
      ls_ret_4 = "wrong function pointer";
      break;
   case 4002:
      ls_ret_4 = "array index is out of range";
      break;
   case 4003:
      ls_ret_4 = "no memory for function call stack";
      break;
   case 4004:
      ls_ret_4 = "recursive stack overflow";
      break;
   case 4005:
      ls_ret_4 = "not enough stack for parameter";
      break;
   case 4006:
      ls_ret_4 = "no memory for parameter string";
      break;
   case 4007:
      ls_ret_4 = "no memory for temp string";
      break;
   case 4008:
      ls_ret_4 = "not initialized string";
      break;
   case 4009:
      ls_ret_4 = "not initialized string in array";
      break;
   case 4010:
      ls_ret_4 = "no memory for array\' string";
      break;
   case 4011:
      ls_ret_4 = "too long string";
      break;
   case 4012:
      ls_ret_4 = "remainder from zero divide";
      break;
   case 4013:
      ls_ret_4 = "zero divide";
      break;
   case 4014:
      ls_ret_4 = "unknown command";
      break;
   case 4015:
      ls_ret_4 = "wrong jump (never generated error)";
      break;
   case 4016:
      ls_ret_4 = "not initialized array";
      break;
   case 4017:
      ls_ret_4 = "dll calls are not allowed";
      break;
   case 4018:
      ls_ret_4 = "cannot load library";
      break;
   case 4019:
      ls_ret_4 = "cannot call function";
      break;
   case 4020:
      ls_ret_4 = "expert function calls are not allowed";
      break;
   case 4021:
      ls_ret_4 = "not enough memory for temp string returned from function";
      break;
   case 4022:
      ls_ret_4 = "system is busy (never generated error)";
      break;
   case 4050:
      ls_ret_4 = "invalid function parameters count";
      break;
   case 4051:
      ls_ret_4 = "invalid function parameter value";
      break;
   case 4052:
      ls_ret_4 = "string function internal error";
      break;
   case 4053:
      ls_ret_4 = "some array error";
      break;
   case 4054:
      ls_ret_4 = "incorrect series array using";
      break;
   case 4055:
      ls_ret_4 = "custom indicator error";
      break;
   case 4056:
      ls_ret_4 = "arrays are incompatible";
      break;
   case 4057:
      ls_ret_4 = "global variables processing error";
      break;
   case 4058:
      ls_ret_4 = "global variable not found";
      break;
   case 4059:
      ls_ret_4 = "function is not allowed in testing mode";
      break;
   case 4060:
      ls_ret_4 = "function is not confirmed";
      break;
   case 4061:
      ls_ret_4 = "send mail error";
      break;
   case 4062:
      ls_ret_4 = "string parameter expected";
      break;
   case 4063:
      ls_ret_4 = "integer parameter expected";
      break;
   case 4064:
      ls_ret_4 = "double parameter expected";
      break;
   case 4065:
      ls_ret_4 = "array as parameter expected";
      break;
   case 4066:
      ls_ret_4 = "requested history data in update state";
      break;
   case 4099:
      ls_ret_4 = "end of file";
      break;
   case 4100:
      ls_ret_4 = "some file error";
      break;
   case 4101:
      ls_ret_4 = "wrong file name";
      break;
   case 4102:
      ls_ret_4 = "too many opened files";
      break;
   case 4103:
      ls_ret_4 = "cannot open file";
      break;
   case 4104:
      ls_ret_4 = "incompatible access to a file";
      break;
   case 4105:
      ls_ret_4 = "no order selected";
      break;
   case 4106:
      ls_ret_4 = "unknown symbol";
      break;
   case 4107:
      ls_ret_4 = "invalid price parameter for trade function";
      break;
   case 4108:
      ls_ret_4 = "invalid ticket";
      break;
   case 4109:
      ls_ret_4 = "trade is not allowed";
      break;
   case 4110:
      ls_ret_4 = "longs are not allowed";
      break;
   case 4111:
      ls_ret_4 = "shorts are not allowed";
      break;
   case 4200:
      ls_ret_4 = "object is already exist";
      break;
   case 4201:
      ls_ret_4 = "unknown object property";
      break;
   case 4202:
      ls_ret_4 = "object is not exist";
      break;
   case 4203:
      ls_ret_4 = "unknown object type";
      break;
   case 4204:
      ls_ret_4 = "no object name";
      break;
   case 4205:
      ls_ret_4 = "object coordinates error";
      break;
   case 4206:
      ls_ret_4 = "no specified subwindow";
      break;
   default:
      ls_ret_4 = "unknown error";
   }
   return (ls_ret_4);
}

int Write(string as_0) {
   int l_file_8 = FileOpen(g_name_264, FILE_CSV|FILE_WRITE|FILE_READ, "/t");
   FileSeek(l_file_8, 0, SEEK_END);
   FileWrite(l_file_8, " Time " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS) + ": " + as_0);
   FileClose(l_file_8);
   Print(as_0);
   return (0);
}

int OrdSend(string a_symbol_0, int ai_8, double a_lots_12, double ad_20, int a_slippage_28, double ad_32, double ad_40, string a_comment_48 = "", int a_magic_56 = 0, int a_datetime_60 = 0, color a_color_64 = -1) {
   int l_ticket_80;
   int l_ticket_84;
   int l_stoplevel_68 = MarketInfo(a_symbol_0, MODE_STOPLEVEL);
   double ld_72 = 0;
   int l_count_88 = 0;
   switch (ai_8) {
   case 0:
      if (!IsTradeContextBusy() && IsTradeAllowed()) {
         while (l_count_88 < gi_212) {
            RefreshRates();
            l_ticket_80 = OrderSend(a_symbol_0, OP_BUY, a_lots_12, Ask, a_slippage_28, NormalizeDouble(ad_32, Digits), NormalizeDouble(ad_40, Digits), a_comment_48, a_magic_56, a_datetime_60, a_color_64);
            if (l_ticket_80 <= 0) {
               Write("Error Occured : " + ErrorDescription(GetLastError()));
               Write(Symbol() + " Buy @ " + Ask + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
               l_count_88++;
            } else {
               l_count_88 = gi_212;
               Write("Order opened : " + Symbol() + " Buy @ " + Ask + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
            }
            Sleep(1000 * gi_216);
         }
      }
      l_ticket_84 = l_ticket_80;
      break;
   case 1:
      if (!IsTradeContextBusy() && IsTradeAllowed()) {
         while (l_count_88 < gi_212) {
            RefreshRates();
            l_ticket_80 = OrderSend(a_symbol_0, OP_SELL, a_lots_12, Bid, a_slippage_28, NormalizeDouble(ad_32, Digits), NormalizeDouble(ad_40, Digits), a_comment_48, a_magic_56, a_datetime_60, a_color_64);
            if (l_ticket_80 <= 0) {
               Write("Error Occured : " + ErrorDescription(GetLastError()));
               Write(Symbol() + " Sell @ " + Bid + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
               l_count_88++;
            } else {
               l_count_88 = gi_212;
               Write("Order opened : " + Symbol() + " Sell @ " + Bid + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
            }
            Sleep(1000 * gi_216);
         }
      }
      l_ticket_84 = l_ticket_80;
      break;
   case 4:
      while (l_count_88 < gi_212) {
         RefreshRates();
         if (ad_20 - Ask < l_stoplevel_68 * Point) ld_72 = Ask + l_stoplevel_68 * Point;
         else ld_72 = ad_20;
         l_ticket_80 = OrderSend(a_symbol_0, OP_BUYSTOP, a_lots_12, NormalizeDouble(ld_72, Digits), a_slippage_28, NormalizeDouble(ad_32, Digits), NormalizeDouble(ad_40, Digits), a_comment_48, a_magic_56, a_datetime_60, a_color_64);
         if (l_ticket_80 <= 0) {
            Write("Error Occured : " + ErrorDescription(GetLastError()));
            Write(Symbol() + " Buy Stop @ " + ld_72 + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
            l_count_88++;
         } else {
            l_count_88 = gi_212;
            Write("Order opened : " + Symbol() + " Buy Stop@ " + ld_72 + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
         }
         Sleep(1000 * gi_216);
      }
      l_ticket_84 = l_ticket_80;
      break;
   case 5:
      if (!IsTradeContextBusy() && IsTradeAllowed()) {
         while (l_count_88 < gi_212) {
            RefreshRates();
            if (Bid - ad_20 < l_stoplevel_68 * Point) ld_72 = Bid - l_stoplevel_68 * Point;
            else ld_72 = ad_20;
            l_ticket_80 = OrderSend(a_symbol_0, OP_SELLSTOP, a_lots_12, NormalizeDouble(ld_72, Digits), a_slippage_28, NormalizeDouble(ad_32, Digits), NormalizeDouble(ad_40, Digits), a_comment_48, a_magic_56, a_datetime_60, a_color_64);
            if (l_ticket_80 <= 0) {
               Write("Error Occured : " + ErrorDescription(GetLastError()));
               Write(Symbol() + " Sell Stop @ " + ld_72 + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
               l_count_88++;
            } else {
               l_count_88 = gi_212;
               Write("Order opened : " + Symbol() + " Sell Stop @ " + ld_72 + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
            }
            Sleep(1000 * gi_216);
         }
      }
      l_ticket_84 = l_ticket_80;
      break;
   case 2:
      if (!IsTradeContextBusy() && IsTradeAllowed()) {
         while (l_count_88 < gi_212) {
            RefreshRates();
            if (Ask - ad_20 < l_stoplevel_68 * Point) ld_72 = Ask - l_stoplevel_68 * Point;
            else ld_72 = ad_20;
            l_ticket_80 = OrderSend(a_symbol_0, OP_BUYLIMIT, a_lots_12, NormalizeDouble(ld_72, Digits), a_slippage_28, NormalizeDouble(ad_32, Digits), NormalizeDouble(ad_40, Digits), a_comment_48, a_magic_56, a_datetime_60, a_color_64);
            if (l_ticket_80 <= 0) {
               Write("Error Occured : " + ErrorDescription(GetLastError()));
               Write(Symbol() + " Buy Limit @ " + ld_72 + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
               l_count_88++;
            } else {
               l_count_88 = gi_212;
               Write("Order opened : " + Symbol() + " Buy Limit @ " + ld_72 + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
            }
            Sleep(1000 * gi_216);
         }
      }
      l_ticket_84 = l_ticket_80;
      break;
   case 3:
      if (!IsTradeContextBusy() && IsTradeAllowed()) {
         while (l_count_88 < gi_212) {
            RefreshRates();
            if (ad_20 - Bid < l_stoplevel_68 * Point) ld_72 = Bid + l_stoplevel_68 * Point;
            else ld_72 = ad_20;
            l_ticket_80 = OrderSend(a_symbol_0, OP_BUYLIMIT, a_lots_12, NormalizeDouble(ld_72, Digits), a_slippage_28, NormalizeDouble(ad_32, Digits), NormalizeDouble(ad_40, Digits), a_comment_48, a_magic_56, a_datetime_60, a_color_64);
            if (l_ticket_80 <= 0) {
               Write("Error Occured : " + ErrorDescription(GetLastError()));
               Write(Symbol() + " Sell Limit @ " + ld_72 + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
               l_count_88++;
            } else {
               l_count_88 = gi_212;
               Write("Order opened : " + Symbol() + " Sell Limit @ " + ld_72 + " SL @ " + ad_32 + " TP @" + ad_40 + " ticket =" + l_ticket_80);
            }
            Sleep(1000 * gi_216);
         }
         l_ticket_84 = l_ticket_80;
      }
      break;
   default:
      Write("No valid type of order found");
      l_ticket_84 = -1;
   }
   return (l_ticket_84);
}

int OrdClose(int a_ticket_0, double a_lots_4, double ad_12, int a_slippage_20, color a_color_24 = -1) {
   int l_ord_close_36;
   double ld_unused_28 = 0;
   int l_count_44 = 0;
   if (!IsTradeContextBusy() && IsTradeAllowed()) {
      while (l_count_44 < gi_212) {
         RefreshRates();
         l_ord_close_36 = OrderClose(a_ticket_0, a_lots_4, NormalizeDouble(ad_12, Digits), a_slippage_20, a_color_24);
         if (l_ord_close_36 == 0) {
            Write("Error Occured : " + ErrorDescription(GetLastError()));
            Write(Symbol() + " Close @ " + ad_12 + " ticket =" + a_ticket_0);
            l_count_44++;
         } else {
            l_count_44 = gi_212;
            Write("Order closed : " + Symbol() + " Close @ " + ad_12 + " ticket =" + a_ticket_0);
         }
         Sleep(1000 * gi_216);
      }
   }
   int l_ord_close_40 = l_ord_close_36;
   return (l_ord_close_40);
}

int OrdModify(int a_ticket_0, double ad_4, double ad_12, double ad_20, int a_datetime_28, color a_color_32 = -1) {
   bool l_bool_44;
   double ld_unused_36 = 0;
   int l_count_52 = 0;
   if (!IsTradeContextBusy() && IsTradeAllowed()) {
      while (l_count_52 < gi_212) {
         RefreshRates();
         l_bool_44 = OrderModify(a_ticket_0, NormalizeDouble(ad_4, Digits), NormalizeDouble(ad_12, Digits), NormalizeDouble(ad_20, Digits), a_datetime_28, a_color_32);
         if (l_bool_44 == FALSE) {
            Write("Error Occured : " + ErrorDescription(GetLastError()));
            Write(Symbol() + " Modify @ " + ad_4 + " SL @ " + ad_12 + " TP @" + ad_20 + " ticket =" + a_ticket_0);
            l_count_52++;
         } else {
            l_count_52 = gi_212;
            Write("Order modified : " + Symbol() + " Modify @ " + ad_4 + " SL @ " + ad_12 + " TP @" + ad_20 + " ticket =" + a_ticket_0);
         }
         Sleep(1000 * gi_216);
      }
   }
   int l_bool_48 = l_bool_44;
   return (l_bool_48);
}

void TrailingPositions() {
   double l_bid_0;
   double l_ask_8;
   double l_point_16 = MarketInfo(OrderSymbol(), MODE_POINT);
   if (OrderType() == OP_BUY) {
      l_bid_0 = MarketInfo(OrderSymbol(), MODE_BID);
      if (BreakEven > 0) {
         if (l_bid_0 - OrderOpenPrice() > BreakEven * l_point_16)
            if (OrderStopLoss() - OrderOpenPrice() < 0.0) ModifyStopLoss(OrderOpenPrice() + 0.0 * l_point_16);
      }
      if (TrailingStop > 0) {
         if (l_bid_0 - OrderOpenPrice() > TrailingStop * l_point_16) {
            if (OrderStopLoss() < l_bid_0 - (TrailingStop + TrailingStep - 1) * l_point_16) {
               ModifyStopLoss(l_bid_0 - TrailingStop * l_point_16);
               return;
            }
         }
      }
   }
   if (OrderType() == OP_SELL) {
      l_ask_8 = MarketInfo(OrderSymbol(), MODE_ASK);
      if (BreakEven > 0) {
         if (OrderOpenPrice() - l_ask_8 > BreakEven * l_point_16)
            if (OrderOpenPrice() - OrderStopLoss() < 0.0) ModifyStopLoss(OrderOpenPrice() - 0.0 * l_point_16);
      }
      if (TrailingStop > 0) {
         if (OrderOpenPrice() - l_ask_8 > TrailingStop * l_point_16)
            if (OrderStopLoss() > l_ask_8 + (TrailingStop + TrailingStep - 1) * l_point_16 || OrderStopLoss() == 0.0) ModifyStopLoss(l_ask_8 + TrailingStop * l_point_16);
      }
   }
}

void ModifyStopLoss(double ad_0) {
   PlaySound("alert.wav");
   int li_8 = OrdModify(OrderTicket(), OrderOpenPrice(), ad_0, OrderTakeProfit(), 0, CLR_NONE);
}

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