Navigation:Home > Content >

PipByPip_v1.5.mq4

Time: 2014-10-05 | Download file:PipByPip_v1.5.mq4

#property copyright "Copyright © 2010, http://wellforex.ru"
#property link      "[email protected]"
/*
#import "pplib.dll"
   int calcpp(double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, int a10, int a11, double a12);
#import
*/
extern int Magic = 100010;
extern double Lots = 0.1;
extern int Sensitivity = 16;
extern int TimeStart = 3;
extern int TimeEnd = 9;
extern int StartTake = 24;
extern double K_NextLot = 1.0;
extern double K_Step = 1.3;
extern int OrderMax = 12;
extern bool Stops = TRUE;
extern int Stop = 300;
int gi_132 = 5;
int gi_136;
int gi_140;
int gi_144;
int gi_148;
int gi_152;
int gi_160 = 0;
int gi_168 = 0;
int gi_172 = 5;
int gi_176;
int gi_180;
int gi_184;
double gd_188 = 0.0;
double gd_196;
double gd_204;
double gd_212;
double gd_220;
double gd_228;
double gd_236;
double gd_244;
double gd_252;
double gd_260;
double gd_268;
double gd_276;
double gd_284;
double gd_292;
double gd_300;
double gd_308;
double gd_316;
double gd_324;
double gd_332;
double gd_340;
double gd_348;
string gs_pipbypip_372 = "PipByPip";
int gi_380 = 10;
int gi_384 = 0;
int gi_388 = 0;
int gi_392;
int gi_396;
int gi_400;
bool gi_404 = TRUE;
bool gi_408 = TRUE;
int gi_428;
int gi_432;
bool gi_436;
bool gi_440;
int gi_444 = 10;
int gi_448 = 40;
int gi_452 = 60;
int gi_456 = 10;
int gi_460;

int init() {
   //gi_460 = calcpp(1, 200, 200, 200, 1, 1, 1, 1, 1, 1, 1, 1, 1);
   if (TerminalCompany() == "InstaForex Companies Group") gi_456 = TRUE;
   gi_400 = TimeCurrent();
   f0_6();
   PlaySound("news.wav");
   return (0);
}

void deinit() {
   ObjectDelete("Logo7");
   ObjectDelete("Logo27");
   ObjectDelete("Logo25");
}

int start() {
/*
   if (AccountNumber() != gi_460) {
      Comment("Неверный счёт, бесплатное подключение к счёту - http://wellforex.ru");
      Print("Неверный счёт, бесплатное подключение к счёту - http://wellforex.ru");
      return;
   }
   */
   gi_144 = StartTake;
   gi_172 = MarketInfo(Symbol(), MODE_DIGITS);
   if (gi_172 == 5 || gi_172 == 3) gi_380 = 10;
   if (gi_172 == 4 || gi_172 == 2) gi_380 = 1;
   gd_204 = MarketInfo(Symbol(), MODE_SPREAD);
   if (gd_204 > gd_212) gd_212 = gd_204;
   gd_220 += gd_204;
   gi_184++;
   gd_228 = gd_220 / gi_184;
   gd_188 = Lots;
   if ((!IsOptimization()) && !IsTesting()) {
      Comment(" ", "   \n------------------------------------------------------------------", "   \nAccountNumber : ", DoubleToStr(AccountNumber(), 0), "   \n", TerminalCompany(),
         "   \nCurrent Server Time : " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS), "   \n------------------------------------------------------------------", "   \nSets: Lot = ",
         DoubleToStr(gd_188, 2), " / Sens = ", DoubleToStr(Sensitivity, 0), " / Take-Step = ", DoubleToStr(StartTake, 0), "   \nSets: WorkTime = ", DoubleToStr(TimeStart,
         0), " - ", DoubleToStr(TimeEnd, 0), " hr / K_NextLot = ", DoubleToStr(K_NextLot, 1), "   \nCurrent spread = ", gd_204, "   \nMax spread = ", gd_212, "   \nMedium spread = ",
         NormalizeDouble(gd_228, 1), "   \nOpen orders = ", DoubleToStr(gi_388, 0), "   \nOpen orders on symbol = ", DoubleToStr(gi_384, 0), "   \nMinLot on symbol = ", DoubleToStr(MarketInfo(Symbol(),
         MODE_MINLOT), 2), "   \n------------------------------------------------------------------");
   }
   if (Volume[0] <= 10.0 && Volume[0] < gi_396 || Volume[0] == 1.0) {
      gi_148 = f0_4(Magic);
      gi_152 = f0_0(Magic);
      gi_404 = TRUE;
      gi_408 = TRUE;
      gi_392 = 60;
      if (gi_148 > 0) gi_404 = FALSE;
      if (gi_152 > 0) gi_408 = FALSE;
      if (gi_148 >= 4 && f0_11(Magic) >= -10.0) f0_10();
      if (gi_152 >= 4 && f0_3(Magic) >= -10.0) f0_5();
      if (gi_148 >= 2 && f0_11(Magic) >= 10.0) f0_10();
      if (gi_152 >= 2 && f0_3(Magic) >= 10.0) f0_5();
      if (gi_148 == 1 && TimeCurrent() - gi_428 > 3600 && f0_11(Magic) >= gi_444) f0_10();
      if (gi_152 == 1 && TimeCurrent() - gi_432 > 3600 && f0_3(Magic) >= gi_444) f0_5();
      if (gi_148 == 1 && gi_440) f0_10();
      if (gi_152 == 1 && gi_436) f0_5();
      gd_268 = Ask;
      gd_276 = iHigh(NULL, PERIOD_H1, 1);
      gd_284 = iLow(NULL, PERIOD_H1, 1);
      gd_292 = iClose(NULL, PERIOD_H1, 1);
      gd_300 = iHigh(NULL, PERIOD_H1, 2);
      gd_308 = iLow(NULL, PERIOD_H1, 2);
      gd_316 = iClose(NULL, PERIOD_H1, 2);
      gd_324 = iHigh(NULL, PERIOD_H1, 3);
      gd_332 = iLow(NULL, PERIOD_H1, 3);
      gd_340 = Bid;
      gi_176 = Sensitivity;
      gi_180 = gi_380;
      gd_348 = Point;
      gd_196 = 0;
      gd_196 = calcpp(gd_268, gd_276, gd_284, gd_292, gd_300, gd_308, gd_316, gd_324, gd_332, gd_340, gi_176, gi_180, gd_348);
      gi_436 = FALSE;
      gi_440 = FALSE;
      if (gd_196 > 0.0) gi_436 = TRUE;
      if (gd_196 < 0.0) gi_440 = TRUE;
      gi_384 = f0_9(Magic);
      gi_388 = f0_8(Magic);
      gi_148 = f0_4(Magic);
      gi_152 = f0_0(Magic);
      if (gi_384 > 0) f0_7(Magic);
      if (TimeCurrent() - gi_400 < 300) return;
      if (Hour() < TimeStart || Hour() >= TimeEnd) return;
      gi_136 = StartTake;
      gi_140 = gi_144;
      if (gi_436 && gi_404 && gi_148 == 0 && Hour() != 10) {
         gd_236 = NormalizeDouble(Ask + gi_136 * gi_380 * Point, gi_172);
         f0_2(Blue, Magic);
      }
      if (gi_440 && gi_408 && gi_152 == 0 && Hour() != 10) {
         gd_236 = NormalizeDouble(Bid - gi_136 * gi_380 * Point, gi_172);
         f0_1(Red, Magic);
      }
   }
   gi_396 = Volume[0];
   return (0);
}

void f0_7(int ai_0) {
   double ld_12;
   double ld_20;
   double ld_28;
   double ld_36;
   int li_4 = OrdersTotal();
   double ld_44 = 0;
   double ld_52 = 0;
   bool li_60 = FALSE;
   gi_160 = 0;
   while (gi_160 <= li_4) {
      OrderSelect(gi_160, SELECT_BY_POS);
      if (OrderMagicNumber() == ai_0 && OrderSymbol() == Symbol()) {
         if (OrderType() == OP_BUY) {
            ld_12 = OrderOpenPrice();
            ld_20 = OrderTakeProfit();
            gi_428 = OrderOpenTime();
            gd_252 = OrderLots();
         }
         if (OrderType() == OP_SELL) {
            ld_28 = OrderOpenPrice();
            ld_36 = OrderTakeProfit();
            gi_432 = OrderOpenTime();
            gd_260 = OrderLots();
         }
      }
      gi_160++;
   }
   gi_140 = gi_144;
   if (gi_148 > 1) gi_140 = gi_144 * MathPow(K_Step, gi_148);
   if (NormalizeDouble(Ask, gi_172) - ld_12 < (-(gi_140 * gi_380 * Point)) && gi_148 > 0 && gi_148 < OrderMax) {
      gd_188 = gd_252 * K_NextLot;
      gd_236 = 0;
      f0_2(Blue, ai_0);
      li_4 = OrdersTotal();
      for (gi_160 = 0; gi_160 <= li_4; gi_160++) {
         OrderSelect(gi_160, SELECT_BY_POS);
         if (OrderMagicNumber() == ai_0 && OrderSymbol() == Symbol() && OrderType() == OP_BUY) {
            ld_44 += OrderOpenPrice() * OrderLots();
            ld_52 += OrderLots();
         }
      }
      ld_44 = NormalizeDouble(ld_44 / ld_52, gi_172);
      gd_244 = NormalizeDouble(ld_44 + StartTake * gi_380 * Point, gi_172);
      for (gi_160 = 0; gi_160 < li_4; gi_160++) {
         if (OrderSelect(gi_160, SELECT_BY_POS) && OrderType() == OP_BUY && OrderMagicNumber() == ai_0 && OrderSymbol() == Symbol() && NormalizeDouble(OrderTakeProfit(), gi_172) != NormalizeDouble(gd_244,
            gi_172)) {
            for (int li_8 = 1; li_8 <= gi_132; li_8++) {
               while (!IsTradeAllowed()) Sleep(2000);
               RefreshRates();
               li_60 = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), gd_244, 0, Green);
               if (li_60) break;
               if (!li_60) Print("OrderModify Buy failed with error #", GetLastError());
               Sleep(5000);
            }
         }
      }
   }
   gi_140 = gi_144;
   if (gi_152 > 1) gi_140 = gi_144 * MathPow(K_Step, gi_152);
   if (ld_28 - NormalizeDouble(Bid, gi_172) < (-(gi_140 * gi_380 * Point)) && gi_152 > 0 && gi_152 < OrderMax) {
      gd_188 = gd_260 * K_NextLot;
      gd_236 = 0;
      f0_1(Red, ai_0);
      li_4 = OrdersTotal();
      for (gi_160 = 0; gi_160 <= li_4; gi_160++) {
         OrderSelect(gi_160, SELECT_BY_POS);
         if (OrderMagicNumber() == ai_0 && OrderSymbol() == Symbol() && OrderType() == OP_SELL) {
            ld_44 += OrderOpenPrice() * OrderLots();
            ld_52 += OrderLots();
         }
      }
      ld_44 = NormalizeDouble(ld_44 / ld_52, gi_172);
      gd_244 = NormalizeDouble(ld_44 - StartTake * gi_380 * Point, gi_172);
      for (gi_160 = 0; gi_160 < li_4; gi_160++) {
         if (OrderSelect(gi_160, SELECT_BY_POS) && OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == ai_0 && NormalizeDouble(OrderTakeProfit(),
            gi_172) != NormalizeDouble(gd_244, gi_172)) {
            for (li_8 = 1; li_8 <= gi_132; li_8++) {
               while (!IsTradeAllowed()) Sleep(2000);
               RefreshRates();
               li_60 = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), gd_244, 0, Green);
               if (li_60) break;
               if (!li_60) Print("OrderModify Sell failed with error #", GetLastError());
               Sleep(5000);
            }
         }
      }
   }
}

void f0_2(color ai_0, int ai_4) {
   int li_12;
   bool li_24 = FALSE;
   double ld_28 = 0;
   if (Stops) ld_28 = NormalizeDouble(Bid, gi_172) - Stop * gi_380 * Point;
   for (int li_8 = 1; li_8 <= gi_132; li_8++) {
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      li_12 = OrderSend(Symbol(), OP_BUY, gd_188, NormalizeDouble(Ask, gi_172), gi_380 * 2, 0, 0, gs_pipbypip_372 + " (" + Symbol() + ")", ai_4, 0, ai_0);
      Sleep(2000);
      if (li_12 > 0) {
         if (!(OrderSelect(li_12, SELECT_BY_TICKET, MODE_TRADES))) continue;
         for (int li_16 = 1; li_16 <= gi_132; li_16++) {
            while (!IsTradeAllowed()) Sleep(2000);
            RefreshRates();
            if (gd_236 == 0.0) break;
            li_24 = OrderModify(OrderTicket(), OrderOpenPrice(), ld_28, gd_236, 0, Green);
            if (li_24) break;
            if (!li_24) Print("OrderModify Buy failed with error #", GetLastError());
            Sleep(5000);
         }
         PlaySound("news.wav");
      } else {
         Print("Error opening BUY order : ", GetLastError());
         PlaySound("timeout.wav");
         Sleep(5000);
      }
   }
}

void f0_1(color ai_0, int ai_4) {
   int li_12;
   bool li_24 = FALSE;
   double ld_28 = 0;
   if (Stops) ld_28 = NormalizeDouble(Ask, gi_172) + Stop * gi_380 * Point;
   for (int li_8 = 1; li_8 <= gi_132; li_8++) {
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      li_12 = OrderSend(Symbol(), OP_SELL, gd_188, NormalizeDouble(Bid, gi_172), gi_380 * 2, 0, 0, gs_pipbypip_372 + " (" + Symbol() + ")", ai_4, 0, ai_0);
      Sleep(2000);
      if (li_12 > 0) {
         if (!(OrderSelect(li_12, SELECT_BY_TICKET, MODE_TRADES))) continue;
         for (int li_16 = 1; li_16 <= gi_132; li_16++) {
            while (!IsTradeAllowed()) Sleep(2000);
            RefreshRates();
            if (gd_236 == 0.0) break;
            li_24 = OrderModify(OrderTicket(), OrderOpenPrice(), ld_28, gd_236, 0, Green);
            if (li_24) break;
            if (!li_24) Print("OrderModify Sell failed with error #", GetLastError());
            Sleep(5000);
         }
         PlaySound("news.wav");
      } else {
         Print("Error opening SELL order : ", GetLastError());
         PlaySound("timeout.wav");
         Sleep(5000);
      }
   }
}

int f0_9(int ai_0) {
   int li_4 = OrdersTotal();
   int li_8 = 0;
   for (gi_160 = 0; gi_160 < li_4; gi_160++) {
      OrderSelect(gi_160, SELECT_BY_POS);
      if (OrderSymbol() == Symbol() && OrderType() == OP_BUY || OrderType() == OP_SELL && OrderMagicNumber() == ai_0) li_8++;
   }
   return (li_8);
}

int f0_8(int ai_0) {
   int li_4 = OrdersTotal();
   int li_8 = 0;
   for (gi_160 = 0; gi_160 < li_4; gi_160++) {
      OrderSelect(gi_160, SELECT_BY_POS);
      if (OrderType() == OP_BUY || OrderType() == OP_SELL && OrderMagicNumber() == ai_0) li_8++;
   }
   return (li_8);
}

int f0_4(int ai_0) {
   int li_4 = OrdersTotal();
   int li_8 = 0;
   for (gi_160 = 0; gi_160 < li_4; gi_160++) {
      OrderSelect(gi_160, SELECT_BY_POS);
      if (OrderSymbol() == Symbol() && OrderType() == OP_BUY && OrderMagicNumber() == ai_0) li_8++;
   }
   return (li_8);
}

int f0_0(int ai_0) {
   int li_4 = OrdersTotal();
   int li_8 = 0;
   for (gi_160 = 0; gi_160 < li_4; gi_160++) {
      OrderSelect(gi_160, SELECT_BY_POS);
      if (OrderSymbol() == Symbol() && OrderType() == OP_SELL && OrderMagicNumber() == ai_0) li_8++;
   }
   return (li_8);
}

void f0_10() {
   bool li_8;
   int li_0 = OrdersTotal();
   for (int li_4 = li_0 - 1; li_4 >= 0; li_4--) {
      OrderSelect(li_4, SELECT_BY_POS, MODE_TRADES);
      li_8 = FALSE;
      for (int li_12 = 1; li_12 <= gi_132; li_12++) {
         while (!IsTradeAllowed()) Sleep(5000);
         RefreshRates();
         if (OrderType() == OP_BUY && OrderMagicNumber() == Magic) li_8 = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, gi_172), 5 * gi_380, Yellow);
         if (li_8 || OrderType() != OP_BUY || OrderMagicNumber() != Magic) break;
         if (!li_8) Print("OrderSend CloseBuy failed with error #", GetLastError(), " Try ", li_12);
         if (li_12 == gi_132) Print("Warning!!!Last try failed!");
         Sleep(5000);
      }
   }
}

void f0_5() {
   bool li_8;
   int li_0 = OrdersTotal();
   for (int li_4 = li_0 - 1; li_4 >= 0; li_4--) {
      OrderSelect(li_4, SELECT_BY_POS, MODE_TRADES);
      li_8 = FALSE;
      for (int li_12 = 1; li_12 <= gi_132; li_12++) {
         while (!IsTradeAllowed()) Sleep(5000);
         RefreshRates();
         if (OrderType() == OP_SELL && OrderMagicNumber() == Magic) li_8 = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, gi_172), 5 * gi_380, Yellow);
         if (li_8 || OrderType() != OP_SELL || OrderMagicNumber() != Magic) break;
         if (!li_8) Print("OrderSend CloseSell failed with error #", GetLastError(), " Try ", li_12);
         if (li_12 == gi_132) Print("Warning!!!Last try failed!");
         Sleep(5000);
      }
   }
}

double f0_11(int ai_0) {
   int li_4 = OrdersTotal();
   double ld_8 = 0;
   double ld_16 = 0;
   for (gi_160 = 0; gi_160 < li_4; gi_160++) {
      OrderSelect(gi_160, SELECT_BY_POS);
      if (OrderType() == OP_BUY && OrderMagicNumber() == ai_0) ld_8 += OrderProfit() / (gi_456 * OrderLots());
   }
   return (ld_8);
}

double f0_3(int ai_0) {
   int li_4 = OrdersTotal();
   double ld_8 = 0;
   double ld_16 = 0;
   for (gi_160 = 0; gi_160 < li_4; gi_160++) {
      OrderSelect(gi_160, SELECT_BY_POS);
      if (OrderType() == OP_SELL && OrderMagicNumber() == ai_0) ld_8 += OrderProfit() / (gi_456 * OrderLots());
   }
   return (ld_8);
}

void f0_6() {
   int li_0 = 15;
   string ls_4 = "Logo" + "7";
   if (ObjectFind(ls_4) == -1) {
      ObjectCreate(ls_4, OBJ_LABEL, 0, 0, 0);
      ObjectSet(ls_4, OBJPROP_CORNER, 0);
      ObjectSet(ls_4, OBJPROP_XDISTANCE, 7);
      ObjectSet(ls_4, OBJPROP_YDISTANCE, 1 * li_0);
   }
   ObjectSetText(ls_4, "PipByPip v1.5 release 15.03.2012", 8, "Verdana", DodgerBlue);
   ls_4 = "Logo" + "27";
   if (ObjectFind(ls_4) == -1) {
      ObjectCreate(ls_4, OBJ_LABEL, 0, 0, 0);
      ObjectSet(ls_4, OBJPROP_CORNER, 3);
      ObjectSet(ls_4, OBJPROP_XDISTANCE, 5);
      ObjectSet(ls_4, OBJPROP_YDISTANCE, 5);
   }
   ObjectSetText(ls_4, "http://wellforex.ru", 8, "Verdana", Silver);
   ls_4 = "Logo" + "25";
   if (ObjectFind(ls_4) == -1) {
      ObjectCreate(ls_4, OBJ_LABEL, 0, 0, 0);
      ObjectSet(ls_4, OBJPROP_CORNER, 3);
      ObjectSet(ls_4, OBJPROP_XDISTANCE, 5);
      ObjectSet(ls_4, OBJPROP_YDISTANCE, 20);
   }
   ObjectSetText(ls_4, "WELLFOREX", 10, "Verdana", Red);
}

int calcpp(double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, int a10, int a11, double a12)
{
  int v13; 

  v13 = 0;
  if ((a11 * a10) * a12 + a0 < (a1 + a2 + a3) / 3.0 )
    v13 = 72737;
  if ( a9 - (a11 * a10) * a12 > (a1 + a2 + a3) / 3.0 )
    v13 = -72737;
  return (v13);
}

Recommend