Navigation:Home > Content >

Cash-profit_1.1.mq4

Time: 2016-08-09 | Download file:Cash-profit_1.1.mq4

/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2010, Impish"
#property link      ""

#include 

int gi_76 = 5007679;
extern int cSeconds = 14;
extern int MinPriceShot = 7;
extern int MaxOrdersCount = 1;
extern double RiskPercent = 120.0;
double gd_100 = 0.1;
extern int TakeProfit = 22;
extern int StopLoss = 10;
extern int TrailingStop = 5;
extern int Slippage = 3;
extern int BuyMagic = 11;
extern int SellMagic = 12;
int gi_unused_132;
int gi_136 = 2;
double gd_140;
int gi_148;
int gi_152;
int g_datetime_156 = 0;
double g_close_160 = -1.0;
string gs_168 = "lblfincp_";

int init() {
   gd_140 = Ask - Bid;
   gi_unused_132 = -1;
   gi_148 = TrailingStop;
   gi_152 = TrailingStop;
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int li_12;
   int li_16;
   int li_20;
   if (!IsOptimization() && !IsTesting() && !IsVisualMode()) {
      DrawLogo();
      DrawStats();
   }
   gd_100 = LotsOptimized();
   int l_datetime_0 = TimeCurrent();
   double l_close_4 = Close[0];
   if (g_close_160 != -1.0) {
      li_12 = l_close_4 / Point - g_close_160 / Point;
      li_16 = l_datetime_0 - g_datetime_156;
      li_20 = OrdersTotalCountByTypeANDMagic(OP_BUY, BuyMagic) + OrdersTotalCountByTypeANDMagic(OP_SELL, SellMagic);
      if (MathAbs(li_12) >= MinPriceShot && li_16 <= cSeconds) {
         if (li_20 < MaxOrdersCount) {
            if (ND(l_close_4) > ND(g_close_160)) {
               OpenBuy(gd_100);
               Comment("\nUP = " + DoubleToStr(MathAbs(li_12), 0));
            }
            if (ND(l_close_4) < ND(g_close_160)) {
               OpenSell(gd_100);
               Comment("\nDN = " + DoubleToStr(MathAbs(li_12), 0));
            }
         } else Comment("Количество ордеров превысило максимальное!");
         g_close_160 = l_close_4;
         g_datetime_156 = l_datetime_0;
      }
      if (li_16 >= cSeconds) {
         if (li_20 < MaxOrdersCount) {
            if (ND(l_close_4) > ND(g_close_160)) {
               Comment("Not Open" 
               + "\nUP = " + DoubleToStr(MathAbs(li_12), 0));
            }
            if (ND(l_close_4) < ND(g_close_160)) {
               Comment("Not Open" 
               + "\nDN = " + DoubleToStr(MathAbs(li_12), 0));
            }
         } else Comment("Количество ордеров превысило максимальное!");
         g_close_160 = l_close_4;
         g_datetime_156 = l_datetime_0;
      }
   } else {
      g_close_160 = l_close_4;
      g_datetime_156 = l_datetime_0;
   }
   DoTrail();
   return (0);
}

int OrdersTotalCountByTypeANDMagic(int a_cmd_0, int a_magic_4) {
   int l_count_8 = 0;
   for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) {
      if (!OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES)) Print("Не получилось выбрать ордер. Ошибка " + ErrorDescription(GetLastError()));
      else {
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == a_cmd_0)
               if (OrderMagicNumber() == a_magic_4) l_count_8++;
         }
      }
   }
   return (l_count_8);
}

void OpenBuy(double a_lots_0) {
   int l_error_48;
   int l_ord_total_12 = OrdersTotal();
   double l_price_24 = 0;
   double l_price_32 = 0;
   RefreshRates();
   double l_ask_16 = Ask;
   if (TakeProfit > 0) {
      l_price_24 = l_ask_16 + gd_140 + TakeProfit * Point;
      if (l_price_24 - l_ask_16 < (MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0) * Point) l_price_24 = Bid + (MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0) * Point;
   }
   if (StopLoss > 0) l_price_32 = l_ask_16 - StopLoss * Point - gd_140;
   while (IsTradeContextBusy()) Sleep(1000);
   int l_datetime_40 = TimeCurrent();
   int l_ticket_44 = OrderSend(Symbol(), OP_BUY, a_lots_0, l_ask_16, Slippage, l_price_32, l_price_24, "", BuyMagic, 0, Blue);
   if (l_ticket_44 == -1) {
      while (l_ticket_44 == -1 && TimeCurrent() - l_datetime_40 < 60 && !IsTesting()) {
         l_error_48 = GetLastError();
         Print("Ошибка открытия ордера BUY. (" + l_error_48 + ")" + ErrorDescription(l_error_48));
         if (l_error_48 == 148/* ERR_TRADE_TOO_MANY_ORDERS */) return;
         Sleep(1000);
         while (IsTradeContextBusy()) Sleep(1000);
         Print("Повтор");
         RefreshRates();
         l_ask_16 = Ask;
         if (TakeProfit > 0) {
            l_price_24 = l_ask_16 + gd_140 + TakeProfit * Point;
            if (l_price_24 - l_ask_16 < (MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0) * Point) l_price_24 = Bid + (MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0) * Point;
         }
         if (StopLoss > 0) l_price_32 = l_ask_16 - StopLoss * Point - gd_140;
         l_ticket_44 = OrderSend(Symbol(), OP_BUY, a_lots_0, l_ask_16, Slippage, l_price_32, l_price_24, "", BuyMagic, 0, Blue);
      }
      if (l_ticket_44 == -1) {
         l_error_48 = GetLastError();
         Print("Ошибка открытия ордера BUY. (" + l_error_48 + ")" + ErrorDescription(l_error_48));
      }
   }
   if (l_ticket_44 != -1) Print("Открыто BUY на " + Symbol() + " " + Period() + " объемом " + DoubleToStr(a_lots_0, gi_136) + "!");
}

void OpenSell(double a_lots_0) {
   int l_error_48;
   int l_ord_total_12 = OrdersTotal();
   double l_price_24 = 0;
   double l_price_32 = 0;
   RefreshRates();
   double l_bid_16 = Bid;
   if (TakeProfit > 0) {
      l_price_24 = l_bid_16 - TakeProfit * Point - gd_140;
      if (l_bid_16 - l_price_24 < (MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0) * Point) l_price_24 = Ask - (MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0) * Point;
   }
   if (StopLoss > 0) l_price_32 = l_bid_16 + StopLoss * Point + gd_140;
   while (IsTradeContextBusy()) Sleep(1000);
   int l_datetime_40 = TimeCurrent();
   int l_ticket_44 = OrderSend(Symbol(), OP_SELL, a_lots_0, l_bid_16, Slippage, l_price_32, l_price_24, "", SellMagic, 0, Red);
   if (l_ticket_44 == -1) {
      while (l_ticket_44 == -1 && TimeCurrent() - l_datetime_40 < 60 && !IsTesting()) {
         l_error_48 = GetLastError();
         Print("Ошибка открытия ордера SELL. (" + l_error_48 + ")" + ErrorDescription(l_error_48));
         if (l_error_48 == 148/* ERR_TRADE_TOO_MANY_ORDERS */) return;
         Sleep(1000);
         while (IsTradeContextBusy()) Sleep(1000);
         Print("Повтор");
         RefreshRates();
         l_bid_16 = Bid;
         l_bid_16 = Bid;
         if (TakeProfit > 0) {
            l_price_24 = l_bid_16 - TakeProfit * Point - gd_140;
            if (l_bid_16 - l_price_24 < (MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0) * Point) l_price_24 = Ask - (MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0) * Point;
         }
         if (StopLoss > 0) l_price_32 = l_bid_16 + StopLoss * Point + gd_140;
         l_ticket_44 = OrderSend(Symbol(), OP_SELL, a_lots_0, l_bid_16, Slippage, l_price_32, l_price_24, "", SellMagic, 0, Red);
      }
      if (l_ticket_44 == -1) {
         l_error_48 = GetLastError();
         Print("Ошибка открытия ордера SELL. (" + l_error_48 + ")" + ErrorDescription(l_error_48));
      }
   }
   if (l_ticket_44 != -1) Print("Открыто SELL на " + Symbol() + " " + Period() + " объемом " + DoubleToStr(a_lots_0, gi_136) + "!");
}

void DoTrail() {
   int li_unused_0 = StopLoss;
   int li_unused_4 = StopLoss;
   for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) {
      OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol()) {
         if (OrderType() == OP_BUY) {
            if (OrderMagicNumber() == BuyMagic) {
               if (Bid - gi_148 * Point > OrderOpenPrice() && OrderOpenPrice() > OrderStopLoss()) {
                  if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - gi_148 * Point, OrderTakeProfit(), 0, Pink)) Print("Не получилось модифицировать ордер №" + OrderTicket() + ". Ошибка№" + GetLastError());
               } else {
                  if (OrderStopLoss() > OrderOpenPrice() && Bid - OrderStopLoss() >= TrailingStop * Point)
                     if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * Point, OrderTakeProfit(), 0, Pink)) Print("Не получилось модифицировать ордер №" + OrderTicket() + ". Ошибка№" + GetLastError());
               }
            }
         } else {
            if (OrderType() == OP_SELL) {
               if (OrderMagicNumber() == SellMagic) {
                  if (Ask + gi_152 * Point < OrderOpenPrice() && OrderStopLoss() > OrderOpenPrice() || OrderStopLoss() == 0.0) {
                     if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + gi_152 * Point, OrderTakeProfit(), 0, Pink)) Print("Не получилось модифицировать ордер №" + OrderTicket() + ". Ошибка№" + GetLastError());
                  } else {
                     if (OrderStopLoss() < OrderOpenPrice() && OrderStopLoss() - Ask >= TrailingStop * Point)
                        if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop * Point, OrderTakeProfit(), 0, Pink)) Print("Не получилось модифицировать ордер №" + OrderTicket() + ". Ошибка№" + GetLastError());
                  }
               }
            }
         }
      }
   }
}

double ND(double ad_0) {
   return (NormalizeDouble(ad_0, Digits));
}

double LotsOptimized() {
   double l_lotstep_0 = MarketInfo(Symbol(), MODE_LOTSTEP);
   double l_minlot_8 = MarketInfo(Symbol(), MODE_MINLOT);
   int li_16 = 0;
   if (l_lotstep_0 == 0.01) li_16 = 2;
   else li_16 = 1;
   double l_minlot_20 = NormalizeDouble(MathFloor(AccountBalance() * RiskPercent / 100.0) / 1000.0, li_16);
   if (l_minlot_20 < l_minlot_8) l_minlot_20 = l_minlot_8;
   return (l_minlot_20);
}

void DrawLogo() {
   string l_name_0 = gs_168 + "L_1";
   if (ObjectFind(l_name_0) == -1) {
      ObjectCreate(l_name_0, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_0, OBJPROP_CORNER, 0);
      ObjectSet(l_name_0, OBJPROP_XDISTANCE, 390);
      ObjectSet(l_name_0, OBJPROP_YDISTANCE, 10);
   }
   ObjectSetText(l_name_0, "F O R E X", 28, "Arial", DarkTurquoise);
   l_name_0 = gs_168 + "L_2";
   if (ObjectFind(l_name_0) == -1) {
      ObjectCreate(l_name_0, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_0, OBJPROP_CORNER, 0);
      ObjectSet(l_name_0, OBJPROP_XDISTANCE, 382);
      ObjectSet(l_name_0, OBJPROP_YDISTANCE, 50);
   }
   ObjectSetText(l_name_0, "I  N  V  E  S  T  O  R", 16, "Arial", Gold);
   l_name_0 = gs_168 + "L_3";
   if (ObjectFind(l_name_0) == -1) {
      ObjectCreate(l_name_0, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_0, OBJPROP_CORNER, 0);
      ObjectSet(l_name_0, OBJPROP_XDISTANCE, 397);
      ObjectSet(l_name_0, OBJPROP_YDISTANCE, 75);
   }
   ObjectSetText(l_name_0, "www.forex-investor.net", 12, "Arial", Gray);
   l_name_0 = gs_168 + "L_4";
   if (ObjectFind(l_name_0) == -1) {
      ObjectCreate(l_name_0, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_0, OBJPROP_CORNER, 0);
      ObjectSet(l_name_0, OBJPROP_XDISTANCE, 382);
      ObjectSet(l_name_0, OBJPROP_YDISTANCE, 57);
   }
   ObjectSetText(l_name_0, "_____________________", 12, "Arial", Gray);
   l_name_0 = gs_168 + "L_5";
   if (ObjectFind(l_name_0) == -1) {
      ObjectCreate(l_name_0, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_0, OBJPROP_CORNER, 0);
      ObjectSet(l_name_0, OBJPROP_XDISTANCE, 382);
      ObjectSet(l_name_0, OBJPROP_YDISTANCE, 76);
   }
   ObjectSetText(l_name_0, "_____________________", 12, "Arial", Gray);
}

double GetProfitForDay(int ai_0) {
   double ld_ret_4 = 0;
   for (int l_pos_12 = 0; l_pos_12 < OrdersHistoryTotal(); l_pos_12++) {
      if (!(OrderSelect(l_pos_12, SELECT_BY_POS, MODE_HISTORY))) break;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == BuyMagic || OrderMagicNumber() == SellMagic)
         if (OrderCloseTime() >= iTime(Symbol(), PERIOD_D1, ai_0) && OrderCloseTime() < iTime(Symbol(), PERIOD_D1, ai_0) + 86400) ld_ret_4 += OrderProfit();
   }
   return (ld_ret_4);
}

void DrawStats() {
   double ld_0 = GetProfitForDay(0);
   string l_name_8 = gs_168 + "1";
   if (ObjectFind(l_name_8) == -1) {
      ObjectCreate(l_name_8, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_8, OBJPROP_CORNER, 1);
      ObjectSet(l_name_8, OBJPROP_XDISTANCE, 10);
      ObjectSet(l_name_8, OBJPROP_YDISTANCE, 15);
   }
   ObjectSetText(l_name_8, "Заработок сегодня: " + DoubleToStr(ld_0, 2), 12, "Courier New", Yellow);
   ld_0 = GetProfitForDay(1);
   l_name_8 = gs_168 + "2";
   if (ObjectFind(l_name_8) == -1) {
      ObjectCreate(l_name_8, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_8, OBJPROP_CORNER, 1);
      ObjectSet(l_name_8, OBJPROP_XDISTANCE, 10);
      ObjectSet(l_name_8, OBJPROP_YDISTANCE, 30);
   }
   ObjectSetText(l_name_8, "Заработок вчера: " + DoubleToStr(ld_0, 2), 12, "Courier New", Yellow);
   ld_0 = GetProfitForDay(2);
   l_name_8 = gs_168 + "3";
   if (ObjectFind(l_name_8) == -1) {
      ObjectCreate(l_name_8, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_8, OBJPROP_CORNER, 1);
      ObjectSet(l_name_8, OBJPROP_XDISTANCE, 10);
      ObjectSet(l_name_8, OBJPROP_YDISTANCE, 45);
   }
   ObjectSetText(l_name_8, "Заработок позавчера: " + DoubleToStr(ld_0, 2), 12, "Courier New", Yellow);
   l_name_8 = gs_168 + "4";
   if (ObjectFind(l_name_8) == -1) {
      ObjectCreate(l_name_8, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_8, OBJPROP_CORNER, 1);
      ObjectSet(l_name_8, OBJPROP_XDISTANCE, 10);
      ObjectSet(l_name_8, OBJPROP_YDISTANCE, 75);
   }
   ObjectSetText(l_name_8, "Баланс: " + DoubleToStr(AccountBalance(), 2), 14, "Courier New", Yellow);
}

Recommend