← К каталогу
Исходный код · ID 636

sistemaea_byfreddy_trans_v3.mq4

Вы автор или правообладатель?

Сообщите нам, если считаете, что материал размещён без разрешения.

Краткий обзор

О программе

Данный советник предназначен для платформы MetaTrader 4 и реализует сеточную торговую стратегию с управлением позициями на основе уровня эквити торгового счёта. Советник открывает позиции BUY и SELL с заданным шагом сетки, а при достижении определённых порогов эквити автоматически закрывает открытые позиции и сбрасывает параметры для нового цикла торговли.

В советнике реализована система фильтрации по времени торговли с тремя настраиваемыми временными интервалами, а также поддержка трейлинг-стопа для управления защитой позиций. Параметры объёма позиций корректируются пошагово в зависимости от направления последнего закрытого ордера.

Советник поддерживает повторное открытие позиций при движении цены на определённое расстояние, настраиваемое количество попыток повторной отправки ордеров при ошибках, а также звуковые уведомления о закрытии позиций. На графике отображается текущий статус торгового времени.

Настройки программы

НастройкаОписание
s00 Текстовый заголовок раздела конфигурации стратегии
TamanoRejilla Шаг сетки в пунктах для открытия повторных позиций при включённом режиме повтора
s01 Текстовый заголовок раздела управления стоп-ордерами
CloseAll Переключатель автоматического закрытия всех открытых позиций при достижении заданного уровня эквити
EquitySignal Процентное значение эквити, при достижении которого активируется режим закрытия позиций
EquityClose Процентное значение эквити, при достижении которого происходит закрытие всех позиций
Plus Величина увеличения объёма лота при корректировке параметров сетки
Minus Величина уменьшения объёма лота при корректировке параметров сетки
StopMin Минимально допустимый объём лота для сеточных позиций
StopMax Максимально допустимый объём лота для сеточных позиций
TakeProfit Уровень тейк-профита для позиций в сеточном цикле
StopLoss1 Уровень стоп-лосса для первой позиции в сеточном цикле
s02 Текстовый заголовок раздела настройки объёма позиций
OrderLots1 Начальный объём лота для первой позиции в сеточном цикле
Slippage Допустимое проскальзывание цены при исполнении ордеров в пунктах
SegundosParaReintentarOperar Время в секундах, в течение которого советник повторяет попытки отправки ордера при ошибках
sh60 Текстовый заголовок раздела настройки торговых расписаний
sh70 Текстовый заголовок первого торгового расписания
Horario1_Desde Время начала первого торгового интервала в формате ЧЧ:ММ
Horario1_Hasta Время окончания первого торгового интервала в формате ЧЧ:ММ
sh80 Текстовый заголовок второго торгового расписания
Horario2_Desde Время начала второго торгового интервала в формате ЧЧ:ММ
Horario2_Hasta Время окончания второго торгового интервала в формате ЧЧ:ММ
sh90 Текстовый заголовок третьего торгового расписания
Horario3_Desde Время начала третьего торгового интервала в формате ЧЧ:ММ
Horario3_Hasta Время окончания третьего торгового интервала в формате ЧЧ:ММ
sh100 Текстовый разделитель в настройках
Получить полный код

Поиск по коду файла

/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: 
   E-mail : p******m*@gmail.com
*/

#import "user32.dll"
   int PostMessageA(int a0, int a1, int a2, int a3);
#import
#include <stdlib.mqh>

extern string s00 = "** Configuraci?n de la estrategia **"; // ????????? ?????????
extern bool Largos? = TRUE;       //  ?????????? BUY
extern bool Cortos? = TRUE;       //  ?????????? SELL
extern bool Repetir? = TRUE;      //  ??????, ???? ??????? ??? ?????? ??? ????????? ??????????? ???????? ???????

extern int TamanoRejilla = 10;    //  ???????????? ??? Repetir? = TRUE( ????????? ????????? ????)
extern string s01 = "** Gesti?n de stops **";  // ????????? ??????
int gi_108 = 0;

extern bool   CloseAll     = true; // ?????????? ????? ??????? ????????
extern double    EquitySignal = 1;   // Equity ??? ??????? ????????? ????? ???????? ???? ??????? ?? ?????( AccountEquity = Balans + EquitySignal% )
extern double    EquityClose  = 0.9;    // Equity ??? ??????? ????????? ??? ?????? ?? ?????( AccountEquity = Balans + EquitySignal% )
extern double Plus         = 0.1;  // ????? ?????????? ????
extern double Minus        = 0.2;  // ????? ?????????? ????
extern double StopMin      = 0.1;   // ???????????? ?????????? ??????????? ?????
extern double StopMax      = 2;   // ???????????? ?????????? ??????????? ?????
extern int TakeProfit = 30;
extern int StopLoss1 = 0;
 int StopLoss2 = 20;
 int StopLoss3 = 30;
extern string s02 = "** Tama?o de ?rdenes. 0 para desactivar **";
extern double OrderLots1 = 0.5;
 double OrderLots2 = 0.1;
 double OrderLots3 = 0.1;
bool gi_160 = FALSE; // TRUE;//                         // ???????? ?????
int gi_164 = 0;              // ??????? ??? ????????? ?????
int gi_168 = 100;            // ???? ????
bool gi_unused_172 = FALSE;
string gs_176 = "JP_GRID";   // ??????????? ???????
string gs_184 = "v1.0";
extern int Slippage = 1;
extern int SegundosParaReintentarOperar = 20; // ?????????? ??????? ?????????? ?????(??? ????????? ??????????)
double gd_200 = 0.0;        // ?????????? ????? ???????????? ???????????, ???? OrderLots = 0?
int gi_208 = 1;             // ????????? ??? ????????? ???????
int g_magic_212;            // ?????
double stepBuy;              // ????? buy ???????
double stepSell;             // ????? sell ???????
datetime t;                 // ????? ???????? ?????????? ??????
int    LastCloseType   = -1;          // ??? ?????????? ????????? ??????
bool   _close = false;      // ????? ??????? ???????? ????????
double    _equitySignal ;   // Equity ??? ??????? ????????? ????? ???????? ???? ??????? ?? ?????( AccountEquity = Balans + EquitySignal% )
double    _equityClose  ;   // Equity ??? ??????? ????????? ??? ?????? ?? ?????( AccountEquity = Balans + EquitySignal% )

string gs_unused_216 = "";
string gs_dummy_224;
string gs_dummy_232;
string gs_dummy_240;
string gs_dummy_248;
string gs_dummy_256;
string gs_dummy_264;
string gs_dummy_272;
string gs_dummy_280;
string gs_dummy_288;
string gs_dummy_296;
int gi_unused_304 = 0;
int gi_unused_308 = -1;
string gs_unused_312 = "";

extern string sh60 = "*** Horarios para la operativa **********";
extern bool OperarSiempre? = TRUE;                                                    // ????????? ????????? ??????????? ??? ?????
extern string sh70 = "*** Configurar Horario de Operaci?n 1 (de 00:00 a 23:59) ***";  // ??? ???????? ?????????? ?????? ?????????
extern bool OperarHorario1? = TRUE;                                                   
extern string Horario1_Desde = "07:30";
extern string Horario1_Hasta = "14:00";
extern string sh80 = "*** Configurar Horario de Operaci?n 2 (de 00:00 a 23:59) ***";
extern bool OperarHorario2? = FALSE;
extern string Horario2_Desde = "14:00";
extern string Horario2_Hasta = "22:00";
extern string sh90 = "*** Configurar Horario de Operaci?n 3 (de 00:00 a 23:59) ***";
extern bool OperarHorario3? = FALSE;
extern string Horario3_Desde = "22:00";
extern string Horario3_Hasta = "07:30";
extern string sh100 = "*****************************************";
string gs_horario_424 = "Horario";
int gi_unused_432 = 0;
double g_bid_436 = 0.0;    // ??????? ???????? Bid
int gi_unused_444 = 0;     // ??????? ???????? ?????
int g_time_448 = 0;        // ????? ?????? ???????? ????
int    NumberOfTry  = 3;               // ?????????? ???????? ???????
bool   UseSound     = True;            // ???????????? ???????? ??????
color  clCloseSell  = Red;             // ???? ?????? ???????? ???????
color  clCloseBuy   = Green;           // ???? ?????? ???????? ???????
color  clDelete     = Yellow;          // ???? ?????? ???????? ??????
string NameFileSound= "expert.wav";    // ???????????? ????????? ?????

int comprobarStopLoss(int ai_0) {
   int l_stoplevel_4 = MarketInfo(Symbol(), MODE_STOPLEVEL); // ???????? ?????????? ?????????? ??????? ????-????? ?? ???????????
   if (ai_0 != 0 && ai_0 < l_stoplevel_4) {                  // ???? ?? ????? 0 ? ?????? ???????????
      Alert("ERROR: El StopLoss m?nimo en ", Symbol(), " es: ", l_stoplevel_4);  // ?????? ????????? ?? ??????
      return (0);
   }
   return (1);                                               // ???? ???????? ?????????? 1       
}

int comprobarTakeProfit(int ai_0) {
   int l_stoplevel_4 = MarketInfo(Symbol(), MODE_STOPLEVEL); // ???????? ?????????? ?????????? ??????? 
   if (ai_0 != 0 && ai_0 < l_stoplevel_4) {                  // ???? ?? ????? 0 ? ?????? ???????????
      Alert("ERROR: El TakeProfit m?nimo en ", Symbol(), " es: ", l_stoplevel_4);  // ?????? ????????? ?? ??????
      return (0);
   }
   return (1);                                               // ???? ???????? ?????????? 1  
}

double getSL(int ai_0, int ai_4, double a_price_8 = 0.0) {
   if (ai_4 == 0) return (0);
   double ld_ret_16 = 0;
   double ld_24 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   ld_24 *= Point;
   if (ai_0 == 0 || ai_0 == 2 || ai_0 == 4) {
      if (a_price_8 == 0.0) {
         RefreshRates();
         a_price_8 = Ask;
      }
      ld_ret_16 = a_price_8 - ai_4 * Point;
      if (ld_ret_16 > a_price_8 - ld_24) ld_ret_16 = a_price_8 - ld_24;
   }
   if (ai_0 == 1 || ai_0 == 3 || ai_0 == 5) {
      if (a_price_8 == 0.0) {
         RefreshRates();
         a_price_8 = Bid;
      }
      ld_ret_16 = a_price_8 + ai_4 * Point;
      if (ld_ret_16 < a_price_8 + ld_24) ld_ret_16 = a_price_8 + ld_24;
   }
   return (ld_ret_16);
}

double getTP(int ai_0, int ai_4, double a_price_8 = 0.0) {
   if (ai_4 == 0) return (0);
   double ld_16 = 0;
   double ld_24 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   ld_24 *= Point;
   if (ai_0 == 0 || ai_0 == 2 || ai_0 == 4) {
      if (a_price_8 == 0.0) {
         RefreshRates();
         a_price_8 = Ask;
      }
      ld_16 = a_price_8 + ai_4 * Point;
      if (ld_16 < a_price_8 + ld_24) ld_16 = a_price_8 + ld_24;
   }
   if (ai_0 == 1 || ai_0 == 3 || ai_0 == 5) {
      if (a_price_8 == 0.0) {
         RefreshRates();
         a_price_8 = Bid;
      }
      ld_16 = a_price_8 - ai_4 * Point;
      if (ld_16 > a_price_8 - ld_24) ld_16 = a_price_8 - ld_24;
   }
   ld_16 = NormalizeDouble(ld_16, Digits);
   return (ld_16);
}

int abrirPosicion(int a_cmd_0, double a_price_4 = 0.0, double ad_12 = 0.0, double ad_20 = 0.0, double a_lots_28 = 0.0, string a_comment_36 = "", int a_datetime_44 = 0) {
   double l_price_48;
   color l_color_56;
   int l_ticket_60;
   int l_error_64;
   double l_price_68;
   double l_price_76;
   if (a_comment_36 == "") a_comment_36 = gs_176 + " " + gs_184 + " " + getPeriodAsString(Period()) + ";";
   double ld_84 = (MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0) * Point;
   int li_92 = SegundosParaReintentarOperar * 2;
   a_price_4 = NormalizeDouble(a_price_4, Digits);
   while (li_92 > 0) {
      RefreshRates();
      if (a_cmd_0 == OP_BUY || a_cmd_0 == OP_BUYLIMIT || a_cmd_0 == OP_BUYSTOP) {
         l_price_48 = NormalizeDouble(Ask, Digits);
         l_color_56 = Green;
      }
      if (a_cmd_0 == OP_SELL || a_cmd_0 == OP_SELLLIMIT || a_cmd_0 == OP_SELLSTOP) {
         l_price_48 = NormalizeDouble(Bid, Digits);
         l_color_56 = Red;
      }
      if (a_price_4 == 0.0) a_price_4 = l_price_48;
      if (a_lots_28 == 0.0) a_lots_28 = NormalizeLots(gd_200);
      else a_lots_28 = NormalizeLots(a_lots_28);
      if (a_cmd_0 != OP_BUY && a_cmd_0 != OP_SELL) {
         if (a_price_4 < l_price_48 && a_cmd_0 == OP_BUYSTOP) a_cmd_0 = 2;
         if (a_price_4 > l_price_48 && a_cmd_0 == OP_BUYLIMIT) a_cmd_0 = 4;
         if (a_price_4 > l_price_48 && a_cmd_0 == OP_SELLSTOP) a_cmd_0 = 3;
         if (a_price_4 < l_price_48 && a_cmd_0 == OP_SELLLIMIT) a_cmd_0 = 5;
         if (a_cmd_0 == OP_BUYLIMIT || a_cmd_0 == OP_BUYSTOP || a_cmd_0 == OP_SELLLIMIT || a_cmd_0 == OP_SELLSTOP) {
            if (MathAbs(l_price_48 - a_price_4) > ld_84) l_price_48 = a_price_4;
            else {
               if (a_cmd_0 == OP_BUYLIMIT || a_cmd_0 == OP_BUYSTOP) {
                  a_cmd_0 = 0;
                  a_datetime_44 = 0;
               }
               if (a_cmd_0 == OP_SELLLIMIT || a_cmd_0 == OP_SELLSTOP) {
                  a_cmd_0 = 1;
                  a_datetime_44 = 0;
               }
            }
         }
      }
      if (ad_12 != 0.0) l_price_68 = ad_12;
      else l_price_68 = getSL(a_cmd_0, gi_108, l_price_48);
      if (ad_20 != 0.0) l_price_76 = ad_20;
      else l_price_76 = getTP(a_cmd_0, TakeProfit, l_price_48);
      if (a_cmd_0 == OP_BUY || a_cmd_0 == OP_BUYLIMIT || a_cmd_0 == OP_BUYSTOP) {
         if (l_price_68 != 0.0 && l_price_48 - l_price_68 < ld_84) {
            if (l_price_48 - l_price_68 > 0.0) {
               l_price_68 = NormalizeDouble(l_price_48 - ld_84, Digits);
               Print("Cambiando el StopLoss al m?nimo de la plataforma");
            } else {
               l_price_68 = 0;
               Print("Eliminando StopLoss incorrecto");
            }
         }
         if (l_price_76 != 0.0 && l_price_76 - l_price_48 < ld_84) {
            if (l_price_76 - l_price_48 > 0.0) {
               l_price_76 = NormalizeDouble(l_price_48 + ld_84, Digits);
               Print("Cambiando el TakeProfit al m?nimo de la plataforma");
            } else {
               l_price_76 = 0;
               Print("Eliminando TakeProfit incorrecto");
            }
         }
      }
      if (a_cmd_0 == OP_SELL || a_cmd_0 == OP_SELLLIMIT || a_cmd_0 == OP_SELLSTOP) {
         if (l_price_68 != 0.0 && l_price_68 - l_price_48 < ld_84) {
            if (l_price_68 - l_price_48 > 0.0) {
               l_price_68 = NormalizeDouble(l_price_48 + ld_84, Digits);
               Print("Cambiando el StopLoss al m?nimo de la plataforma");
            } else {
               l_price_68 = 0;
               Print("Eliminando StopLoss incorrecto");
            }
         }
         if (l_price_76 != 0.0 && l_price_48 - l_price_76 < ld_84) {
            if (l_price_48 - l_price_76 > 0.0) {
               l_price_76 = NormalizeDouble(l_price_48 - ld_84, Digits);
               Print("Cambiando el TakeProfit al m?nimo de la plataforma");
            } else {
               l_price_76 = 0;
               Print("Eliminando TakeProfit incorrecto");
            }
         }
      }
      while (!IsTradeAllowed() || IsTradeContextBusy()) Sleep(1000);
      l_ticket_60 = OrderSend(Symbol(), a_cmd_0, a_lots_28, l_price_48, Slippage, l_price_68, l_price_76, a_comment_36, g_magic_212, a_datetime_44, l_color_56);
      if (l_ticket_60 < 0) {
         l_error_64 = GetLastError();
         Print("OrderSend fall? con error #", l_error_64);
         Print("Orden: ", a_cmd_0, " L=", a_lots_28, " pa=", l_price_48, " precio=" + a_price_4 + " sp=", Slippage, " sl=", l_price_68, " tp=", l_price_76, " c=", a_comment_36, " stoplevel=", ld_84, " Bid=", Bid);
         li_92--;
         Sleep(500);
      } else return (l_ticket_60);
   }
   Alert("Se intent? operar durante " + SegundosParaReintentarOperar + " segundos. Error #" + l_error_64);
   return (-1);
}

int getMagicNumber(bool ai_0 = FALSE) {
   int li_ret_4;                                            // ???????????? ????????
   if (!IsTesting()) li_ret_4 = WindowHandle(Symbol(), 0);  // ???? ?? ?????? ??????????? ????????? ?????????? ???? (window handle), ??????????? ????????? ??????
   else
      if (!IsVisualMode()) li_ret_4 = 23;                   // ????? ???? ?? ? ?????? ??????? ??????????? 23
   if (ai_0) {                                              // ???? ??????? ??????? ? ?????????? true
      for (int l_pos_8 = OrdersTotal() - 1; l_pos_8 >= 0; l_pos_8--) { // ?????????? ??? ??????
         OrderSelect(l_pos_8, SELECT_BY_POS);
         if (OrderSymbol() == Symbol()) {
            if (StringSubstr(OrderComment(), 0, StringLen(gs_176)) == gs_176 && StringFind(OrderComment(), " ", StringLen(gs_176) + 1) == -1 || StringSubstr(OrderComment(), StringFind(OrderComment(), " ", StringLen(gs_176) +
               1) + 1, StringLen(getPeriodAsString(Period()))) == getPeriodAsString(Period())) {
               Print("Retomando orden " + OrderTicket());
               li_ret_4 = OrderMagicNumber();   // ???? ??????? ????? ?????? ?????????? ? ??? ??????????? ???????? "JP_GRID" ....
               break;                           // ??????????? ????? ????? ??????
            }
         }
      }
   }
   return (li_ret_4);
}

void ajustarTrailingStopTodas(int ai_0, int ai_4, int ai_8 = 0) {
   for (int l_pos_12 = 0; l_pos_12 < OrdersTotal(); l_pos_12++)
      if ((OrderSelect(l_pos_12, SELECT_BY_POS) && OrderMagicNumber() == g_magic_212)) ajustarTrailingStop(OrderTicket(), ai_0, ai_4, ai_8);
}

int ajustarTrailingStop(int a_ticket_0, int ai_4, int ai_8, int ai_12 = 0) {
   int li_20;
   double l_price_24;
   double ld_32;
   int li_40;
   if (!OrderSelect(a_ticket_0, SELECT_BY_TICKET)) return (0);
   if (ai_8 < MarketInfo(OrderSymbol(), MODE_STOPLEVEL)) {
      Print("The SL cannot be modified, the minimum required distance is " + DoubleToStr(MarketInfo(OrderSymbol(), MODE_STOPLEVEL), 0) + " y se ha calculado " + DoubleToStr(ai_8, 0));
      return (0);
   }
   if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP) li_20 = (OrderClosePrice() - OrderOpenPrice()) / MarketInfo(OrderSymbol(), MODE_POINT);
   else
      if (OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT || OrderType() == OP_SELLSTOP) li_20 = (OrderOpenPrice() - OrderClosePrice()) / MarketInfo(OrderSymbol(), MODE_POINT);
   if (li_20 <= 0) return (0);
   if (li_20 > ai_4) {
      if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP) {
         l_price_24 = OrderOpenPrice() + (li_20 - ai_8) * Point;
         l_price_24 = NormalizeDouble(l_price_24, Digits);
         ld_32 = l_price_24 - ai_12 * Point;
         if (NormalizeDouble(OrderStopLoss(), Digits) < NormalizeDouble(ld_32, Digits) || OrderStopLoss() == 0.0) {
            li_40 = SegundosParaReintentarOperar * 2;
            while (li_40 > 0) {
               while (!IsTradeAllowed() || IsTradeContextBusy()) Sleep(1000);
               if (OrderModify(OrderTicket(), OrderOpenPrice(), l_price_24, OrderTakeProfit(), 0, Black)) return (1);
               Print("Error " + GetLastError() + " al ajustar TrailingStop, nuevoStop=" + l_price_24 + ", viejoStop=" + OrderStopLoss());
               li_40--;
               Sleep(500);
            }
         }
      }
      if (OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT || OrderTy

Показано первые 50% кода (символов: 21939)

Открыть по тарифу

Купите тариф с пакетом открытий или войдите, если тариф уже есть. Открытый файл останется в вашем кабинете навсегда.

Разовая покупка файла

На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.

Чтобы оформить заказ, введите email и перейдите к оплате.

Стоимость полного кода
2 193,90₽ ≈ $26.81