/*
   G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
   Website: H t t p : / / W WW. mETa qUO tEs. ne T
   E-mail :  S UpPo RT@Me T a Quo T eS .n e T
*/
#property copyright "Copyright 2013, Onlinemoneythai"
#property link      "http://www.onlinemoneythai.com"

extern string RunEAonTimeframe = "H4";
extern string Products = "EA Profit V10 Trader (THAILAND)";
extern int MagicNumber = 1556;
extern string SettingOrder = "SettingOrder";
extern int MaxSpread = 20;
extern double Lots = 0.01;
extern int TakeProfit = 800;
extern int StopLoss = 1000;
extern int trailing = 20;
extern double Maxlot = 99.0;
extern int MaxOrder = 100;
extern string MoneyManagement = "AutoMoneyManagement";
extern bool AutoMoneyManagement = FALSE;
extern double PercentToRisk = 1.0;
extern double PercentSafety = 100.0;
extern string SetDeletePendingTime = "SetDeletependingTime ( M1,M5,M15,M30,H1,H4,D1)";
extern string DeletePendingTime = "M15";
extern string SetEMA = "Set Moving Average ";
extern int PeriodEMA = 50;
extern string Timeset = "Timeset";
extern int StartTrade = 0;
extern int EndTrade = 0;
int G_bars_220;
int G_ticket_228;
int G_ticket_232;
int Gi_240 = 0;
double Gd_268;

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   ObjectsDeleteAll(0, EMPTY);
   return (0);
}

// 1C827DFF0C63B286303A3EAEF673B56B
int f0_0() {
   int count_0 = 0;
   for (int pos_4 = 0; pos_4 < OrdersTotal(); pos_4++) {
      if (OrderSelect(pos_4, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
      if (OrderSymbol() == Symbol())
         if (OrderType() == OP_SELLSTOP) count_0++;
   }
   if (count_0 > 0) return (count_0);
   return (0);
}

// 2E14BEE9A9821BFFA968C7123D43E7E6
int f0_1() {
   int count_0 = 0;
   for (int pos_4 = 0; pos_4 < OrdersTotal(); pos_4++) {
      if (OrderSelect(pos_4, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
      if (OrderSymbol() == Symbol())
         if (OrderType() == OP_BUYSTOP) count_0++;
   }
   if (count_0 > 0) return (count_0);
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double iopen_8;
   int Li_0 = MaxSpread;
   int Li_4 = MaxSpread;
   if (Period() != PERIOD_H4)
   {
   Comment("\n ERROR :: Invalid Timeframe, Please Switch to H4 !");
   Print("ERROR :: Invalid Timeframe, Please Switch to H4 !");
   return (0);
   }
   if (OrdersTotal() > MaxOrder) return (0);
   if (StartTrade > EndTrade)
      if (Hour() >= EndTrade && Hour() < StartTrade) return (0);
   if (StartTrade < EndTrade)
      if (Hour() < StartTrade || Hour() >= EndTrade) return (0);
   if (Bars > G_bars_220) iopen_8 = iOpen(NULL, 0, 1);
   double iclose_16 = iClose(NULL, 0, 1);
   double bid_24 = Bid;
   double ima_32 = iMA(NULL, 0, PeriodEMA, 0, MODE_EMA, PRICE_CLOSE, 0);
   double Ld_40 = PercentToRisk / 1000.0;
   if (AutoMoneyManagement) Lots = NormalizeDouble(AccountBalance() * Ld_40 / PercentSafety / MarketInfo(Symbol(), MODE_TICKVALUE), 2);
   if (Lots > Maxlot) Lots = Maxlot;
   if (DeletePendingTime == "M1") Gd_268 = 1;
   if (DeletePendingTime == "M5") Gd_268 = 5;
   if (DeletePendingTime == "M15") Gd_268 = 15;
   if (DeletePendingTime == "M30") Gd_268 = 30;
   if (DeletePendingTime == "H1") Gd_268 = 60;
   if (DeletePendingTime == "H4") Gd_268 = 240;
   if (DeletePendingTime == "D1") Gd_268 = 1440;
   int datetime_48 = TimeCurrent() + 60.0 * Gd_268;
   if (Day() != Gi_240 || Gi_240 == 0) {
      if (f0_1() == 0 && iclose_16 > iopen_8 && bid_24 > ima_32 + Li_0 * Point) {
         G_ticket_228 = OrderSend(Symbol(), OP_BUYSTOP, Lots, Ask + Point * Li_0, 3, Bid - Point * StopLoss, Ask + Point * TakeProfit, "EA-PO-V10", MagicNumber, datetime_48,
            Blue);
      }
      if (f0_0() == 0 && iclose_16 > iopen_8 && bid_24 < ima_32 - Li_4 * Point) {
         G_ticket_232 = OrderSend(Symbol(), OP_SELLSTOP, Lots, Bid - Point * Li_4, 3, Ask + Point * StopLoss, Bid - Point * TakeProfit, "EA-PO-V10", MagicNumber, datetime_48,
            Red);
      }
      G_bars_220 = Bars;
      f0_2();
      f0_4();
      f0_3();
   }
   return (0);
}

// 7464F3B908A3CF705097CF5A67DB185F
void f0_2() {
bool Modified=false;
   for (int pos_0 = 0; pos_0 < OrdersTotal(); pos_0++) {
      if(OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES))
      {
      if (OrderType() == OP_BUY) {
         if (trailing > 0) {
            if (Bid - OrderOpenPrice() > trailing * Point)
               if (OrderStopLoss() == 0.0 || Bid - OrderStopLoss() > trailing * Point) Modified=OrderModify(OrderTicket(), OrderOpenPrice(), Bid - trailing * Point, OrderTakeProfit(), 0, Blue);
         }
      }
      if (OrderType() == OP_SELL) {
         if (trailing > 0) {
            if (OrderOpenPrice() - Ask > trailing * Point)
               if (OrderStopLoss() == 0.0 || OrderStopLoss() - Ask > trailing * Point) Modified=OrderModify(OrderTicket(), OrderOpenPrice(), Ask + trailing * Point, OrderTakeProfit(), 0, Red);
         }
      }
      }
   }
}

// 773E9ECACC0D186289BC481F1502B87E
void f0_3() {
   string Ls_0 = "";
   string Ls_8 = "\n";
   Ls_0 = Ls_0 + Ls_8;
   Ls_0 = Ls_0 + "#######################################" + Ls_8;
   Ls_0 = Ls_0 + "## " + "EA Profit V10" + Ls_8;
   Ls_0 = Ls_0 + "## " + "Copyright � 2013 onlinemoneythai.com" + Ls_8;
   Ls_0 = Ls_0 + "## " + "Visit: http://www.onlinemoneythai.com " + Ls_8;
   Ls_0 = Ls_0 + "#######################################" + Ls_8;
   Ls_0 = Ls_0 + "## EA MagicNumber :: " + MagicNumber + Ls_8;
   Ls_0 = Ls_0 + "#######################################" + Ls_8;
   Ls_0 = Ls_0 + "## Forex Server :: " + AccountServer() + Ls_8;
   Ls_0 = Ls_0 + "## AccountNumber :: " + AccountNumber() + Ls_8;
   Ls_0 = Ls_0 + "## AccountName :: " + AccountName() + Ls_8;
   Ls_0 = Ls_0 + "## Leverage :: " + AccountLeverage() + Ls_8;
   Ls_0 = Ls_0 + "#######################################" + Ls_8;
   Ls_0 = Ls_0 + "## Balance :: " + DoubleToStr(AccountBalance(), 2) + Ls_8;
   Ls_0 = Ls_0 + "## Equity :: " + DoubleToStr(AccountEquity(), 2) + Ls_8;
   Ls_0 = Ls_0 + "## Margin :: " + DoubleToStr(AccountMargin(), 2) + Ls_8;
   Ls_0 = Ls_0 + "## FreeMargin :: " + DoubleToStr(AccountFreeMargin(), 2) + Ls_8;
   Ls_0 = Ls_0 + "## MarginUsage :: " + DoubleToStr(100 - 100.0 * (AccountFreeMargin() / AccountBalance()), 2) + "%" + Ls_8;
   Ls_0 = Ls_0 + "## Profit :: " + DoubleToStr(AccountProfit(), 2) + Ls_8;
   Ls_0 = Ls_0 + "#######################################" + Ls_8;
   Ls_0 = Ls_0 + "## Symbol :: " + Symbol() + Ls_8;
   Ls_0 = Ls_0 + "## Price :: " + DoubleToStr(Bid, 5) + Ls_8;
   Ls_0 = Ls_0 + "#######################################" + Ls_8;
   Ls_0 = Ls_0 + "## Lots :: " + DoubleToStr(Lots, 2) + Ls_8;
   Ls_0 = Ls_0 + "## TakeProfit :: " + TakeProfit + Ls_8;
   Ls_0 = Ls_0 + "## StopLoss :: " + StopLoss + Ls_8;
   Ls_0 = Ls_0 + "## OrdersTotal :: " + OrdersTotal() + Ls_8;
   Ls_0 = Ls_0 + "#######################################" + Ls_8;
   Ls_0 = Ls_0 + "## Timeserver :: " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES) + Ls_8;
   Ls_0 = Ls_0 + "## Timeslocal :: " + TimeToStr(TimeLocal(), TIME_DATE|TIME_MINUTES) + Ls_8;
   Ls_0 = Ls_0 + "#######################################" + Ls_8;
   Comment(Ls_0);
}

// BD787A2F340C4AC21BA083035209F751
void f0_4() {
   ObjectCreate("EAname", OBJ_LABEL, 0, 0, 0);
   ObjectSet("EAname", OBJPROP_CORNER, 1);
   ObjectSet("EAname", OBJPROP_XDISTANCE, 20);
   ObjectSet("EAname", OBJPROP_YDISTANCE, 20);
   ObjectSetText("EAname", "EA Profit V10 Trader (THAILAND)", 30, "Tahoma", Yellow);
   ObjectCreate("line1", OBJ_LABEL, 0, 0, 0);
   ObjectSet("line1", OBJPROP_XDISTANCE, 1000);
   ObjectSet("line1", OBJPROP_YDISTANCE, 1);
   ObjectSetText("line1", "_________________", 60, "Tahoma", Red);
   ObjectCreate("line2", OBJ_LABEL, 0, 0, 0);
   ObjectSet("line2", OBJPROP_XDISTANCE, 1000);
   ObjectSet("line2", OBJPROP_YDISTANCE, 2);
   ObjectSetText("line2", "_________________", 65, "Tahoma", White);
   ObjectCreate("line3", OBJ_LABEL, 0, 0, 0);
   ObjectSet("line3", OBJPROP_XDISTANCE, 1000);
   ObjectSet("line3", OBJPROP_YDISTANCE, 3);
   ObjectSetText("line3", "_________________", 70, "Tahoma", Blue);
   ObjectCreate("line4", OBJ_LABEL, 0, 0, 0);
   ObjectSet("line4", OBJPROP_XDISTANCE, 1000);
   ObjectSet("line4", OBJPROP_YDISTANCE, 4);
   ObjectSetText("line4", "_________________", 75, "Tahoma", White);
   ObjectCreate("line5", OBJ_LABEL, 0, 0, 0);
   ObjectSet("line5", OBJPROP_XDISTANCE, 1000);
   ObjectSet("line5", OBJPROP_YDISTANCE, 5);
   ObjectSetText("line5", "_________________", 80, "Tahoma", Red);
   ObjectCreate("klc22", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("klc22", "Balance :: " + DoubleToStr(AccountBalance(), 2) + " ## Equity :: " + DoubleToStr(AccountEquity(), 2), 20, "Tahoma", Gold);
   ObjectSet("klc22", OBJPROP_CORNER, 1);
   ObjectSet("klc22", OBJPROP_XDISTANCE, 10);
   ObjectSet("klc22", OBJPROP_YDISTANCE, 200);
   ObjectCreate("klc23", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("klc23", "Lots :: " + DoubleToStr(Lots, 2) + " ## Profit :: " + DoubleToStr(AccountProfit(), 2), 20, "Tahoma", Gold);
   ObjectSet("klc23", OBJPROP_CORNER, 1);
   ObjectSet("klc23", OBJPROP_XDISTANCE, 10);
   ObjectSet("klc23", OBJPROP_YDISTANCE, 230);
}