/*
   G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
   Website:  H tTP: / / w Ww.Me t A q u o tEs . N eT
   E-mail : SUppoRT @M etaQu o t es. n e t
*/
#property copyright "Copyright ?2008, Matt Tabone"
#property link      "http://www.metaquotes.net"

extern string TradingParameters = "------------------------------------------------------------";
extern double Order01LotSize = 0.01;
extern double Order02LotSize = 0.01;
extern int MaxDiffFromOpen = 10;
extern bool TakeSSTrades = TRUE;
extern int OrderSlippage = 3;
extern int EAMagicNumber = 20080709;
string Gs_116 = "PipNailer AutoTrader v1.0a";
int Gi_124;
int Gi_unused_128;
bool Gi_132;
bool Gi_136;
bool Gi_140;
bool Gi_144;
int G_day_of_year_156;
int G_day_of_year_160;
double Gd_164;
double Gd_172;
double Gd_180;
double G_iac_188;
double G_iac_196;
double G_iac_204;
double G_iac_212;
double G_iao_220;
double G_iao_228;
double G_iao_236;
double G_iao_244;
string Gs_dummy_252;
string Gs_dummy_260;
string Gs_dummy_268;
string Gs_dummy_276;
string Gs_dummy_284;
string Gs_dummy_292;
string Gs_dummy_300;
string Gs_dummy_308;
string Gs_dummy_316;
string Gs_dummy_324;

int init() {
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   if (AccountNumber() == 18449 || AccountNumber() == 18463 || IsDemo() == TRUE) {
      GetPrecision();
      GetSpread();
      UpdateOrders();
      PlaceOrders();
      PrintComments();
   } else Comment("This version can run on demos and specified accounts only.");
   return (0);
}

void GetPrecision() {
   Gi_124 = 4;
   if (Ask > 5.0) Gi_124 = 2;
}

void GetSpread() {
   if (Gi_124 == 4) {
      Gi_unused_128 = 10000.0 * (Ask - Bid) + 1.0;
      return;
   }
   Gi_unused_128 = 100.0 * (Ask - Bid) + 1.0;
}

void PlaceOrders() {
   int ticket_0;
   double Ld_4;
   Gd_164 = NormalizeDouble(iSAR(NULL, 0, 0.02, 0.2, 0), Gi_124);
   Gd_172 = NormalizeDouble(iSAR(NULL, 0, 0.02, 0.2, 1), Gi_124);
   Gd_180 = NormalizeDouble(iSAR(NULL, 0, 0.02, 0.2, 2), Gi_124);
   G_iac_188 = iAC(NULL, 0, 0);
   G_iac_196 = iAC(NULL, 0, 1);
   G_iac_204 = iAC(NULL, 0, 2);
   G_iac_212 = iAC(NULL, 0, 3);
   G_iao_220 = iAO(NULL, 0, 0);
   G_iao_228 = iAO(NULL, 0, 1);
   G_iao_236 = iAO(NULL, 0, 2);
   G_iao_244 = iAO(NULL, 0, 3);
   if (Gd_164 < Open[0]) {
      Gi_140 = FALSE;
      Gi_144 = FALSE;
      if (Gd_180 > Close[2] && Gd_180 > Open[2]) {
         if (Gd_172 < Close[1] && Gd_172 < Open[1]) {
            if (Close[1] > Open[1]) {
               if (G_iac_196 > G_iac_204 && G_iac_212 > G_iac_204)
                  if (G_iao_228 > G_iao_236 && G_iao_244 > G_iao_236) Ld_4 = Close[1] - Low[1];
            }
         }
      }
   }
   if (Ask <= Close[1] + MaxDiffFromOpen * Point && Ld_4 > 0.0) {
      if (Gi_132 == FALSE) {
         ticket_0 = OrderSend(Symbol(), OP_BUY, Order01LotSize, Ask, OrderSlippage, Low[1], Ask + NormalizeDouble(Ld_4, Gi_124), "Order1", EAMagicNumber, 0, Blue);
         if (ticket_0 > 0) {
            Gi_132 = TRUE;
            G_day_of_year_156 = TimeDayOfYear(TimeCurrent());
         }
      }
      if (Gi_136 == FALSE && G_day_of_year_160 != TimeDayOfYear(TimeCurrent())) {
         ticket_0 = OrderSend(Symbol(), OP_BUY, Order02LotSize, Ask, OrderSlippage, Low[1], 0, DoubleToStr(Ask + NormalizeDouble(Ld_4, Gi_124), Gi_124), EAMagicNumber, 0,
            Blue);
         if (ticket_0 > 0) {
            Gi_136 = TRUE;
            G_day_of_year_160 = TimeDayOfYear(TimeCurrent());
         }
      }
   }
   Ld_4 = 0;
   double Ld_unused_12 = 0;
   if (Gd_164 > Open[0]) {
      Gi_132 = FALSE;
      Gi_136 = FALSE;
      if (Gd_180 < Close[2] && Gd_180 < Open[2]) {
         if (Gd_172 > Close[1] && Gd_172 > Open[1]) {
            if (Close[1] < Open[1]) {
               if (G_iac_196 < G_iac_204 && G_iac_212 < G_iac_204)
                  if (G_iao_228 < G_iao_236 && G_iao_244 < G_iao_236) Ld_4 = High[1] - Close[1];
            }
         }
      }
   }
   if (Bid >= Close[1] - MaxDiffFromOpen * Point && Ld_4 > 0.0) {
      if (Gi_140 == FALSE) {
         ticket_0 = OrderSend(Symbol(), OP_SELL, Order01LotSize, Bid, OrderSlippage, High[1], Bid - NormalizeDouble(Ld_4, Gi_124), "Order1", EAMagicNumber, 0, Red);
         if (ticket_0 > 0) {
            Gi_140 = TRUE;
            G_day_of_year_156 = TimeDayOfYear(TimeCurrent());
         }
      }
      if (Gi_144 == FALSE && G_day_of_year_160 != TimeDayOfYear(TimeCurrent())) {
         ticket_0 = OrderSend(Symbol(), OP_SELL, Order02LotSize, Bid, OrderSlippage, High[1], 0, DoubleToStr(Bid - NormalizeDouble(Ld_4, Gi_124), Gi_124), EAMagicNumber, 0,
            Red);
         if (ticket_0 > 0) {
            Gi_144 = TRUE;
            G_day_of_year_160 = TimeDayOfYear(TimeCurrent());
         }
      }
   }
}

void UpdateOrders() {
   double Ld_4;
   for (int pos_0 = 0; pos_0 < OrdersTotal(); pos_0++) {
      OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == EAMagicNumber) {
         if (OrderComment() != "Order1") Ld_4 = NormalizeDouble(StrToDouble(OrderComment()), Gi_124);
         else Ld_4 = 0;
         if (OrderType() == OP_BUY) {
            if (Ld_4 > 0.0) {
               Gi_136 = TRUE;
               if (Bid >= Ld_4 && OrderStopLoss() != OrderOpenPrice()) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0, Blue);
            } else Gi_132 = TRUE;
            if (!(G_iac_196 < G_iac_204 && G_iao_228 < G_iao_236)) continue;
            OrderClose(OrderTicket(), OrderLots(), Bid, OrderSlippage, Blue);
            continue;
         }
         if (OrderType() == OP_SELL) {
            if (Ld_4 > 0.0) {
               Gi_144 = TRUE;
               if (Ask <= Ld_4 && OrderStopLoss() != OrderOpenPrice()) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0, Red);
            } else Gi_140 = TRUE;
            if (G_iac_196 > G_iac_204 && G_iao_228 > G_iao_236) OrderClose(OrderTicket(), OrderLots(), Ask, OrderSlippage, Red);
         }
      }
   }
}

void PrintComments() {
   string Ls_0 = "";
   string Ls_8 = "-------------------------------------------------";
   string Ls_16 = "\n";
   Ls_0 = Ls_8 + Ls_16;
   Ls_0 = Ls_0 + Gs_116 + Ls_16;
   Ls_0 = Ls_0 + AccountName() + " (" + AccountNumber() + ")" + Ls_16;
   Comment(Ls_0);
}
