/*
   Generated by EX4-TO-MQ4 decompiler V4.0.220.2c []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2008, At The Best."
#property link      "http://www.metaquotes.net"
extern string EAName = "At The Best v 1.0";
int g_magic_84 = 0;
bool gi_88 = FALSE;
extern bool EachTickMode = TRUE;
extern double Lots = 0.1;
int g_slippage_104 = 3;
extern bool UseStopLoss = FALSE;
extern int StopLoss = 30;
extern bool UseTakeProfit = TRUE;
extern int TakeProfit = 15;
bool gi_124 = FALSE;
int gi_128 = 15;
extern bool UseMM = TRUE;
extern double MaximumRisk = 0.03;
extern bool UseHedge = TRUE;
extern bool UseMicroLot = TRUE;
int g_bars_152;
int gi_156;
string g_ticket_160;
bool gi_168 = FALSE;
double g_ord_open_price_172;
bool gi_180 = FALSE;
string gs_unused_184 = "";
string gs_unused_192 = "";
bool gi_unused_208 = FALSE;
double LotsOptimized() {
   double ld_ret_0 = 0.1;
   int li_unused_8 = 0;
   ld_ret_0 = NormalizeDouble(AccountFreeMargin() * MaximumRisk / 1000.0, 2);
   if (UseMicroLot == FALSE) {
      if (ld_ret_0 > 100.0) ld_ret_0 = 100;
      if (ld_ret_0 < 0.1) ld_ret_0 = 0.1;
   } else {
      if (ld_ret_0 > 100.0) ld_ret_0 = 100;
      if (ld_ret_0 < 0.01) ld_ret_0 = 0.01;
   }
   return (ld_ret_0);
}
void CloseAllBuyOrders(string as_0) {
   int l_ord_total_8 = OrdersTotal();
   for (int l_ord_total_12 = l_ord_total_8; l_ord_total_12 >= 0; l_ord_total_12--) {
      if (OrderSelect(l_ord_total_12, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol() && OrderComment() + "[tp]" == as_0)
            if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 5, Violet);
         if (OrderSymbol() == Symbol() && DoubleToStr(OrderTicket(), 0) + "[tp]" == as_0)
            if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 5, Violet);
      }
   }
}
void CloseAllSellOrders(string as_0) {
   int l_ord_total_8 = OrdersTotal();
   for (int l_ord_total_12 = l_ord_total_8; l_ord_total_12 >= 0; l_ord_total_12--) {
      if (OrderSelect(l_ord_total_12, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol() && OrderComment() + "[tp]" == as_0)
            if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 5, Violet);
         if (OrderSymbol() == Symbol() && DoubleToStr(OrderTicket(), 0) + "[tp]" == as_0)
            if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 5, Violet);
      }
   }
}
int start() {
   string ls_unused_0;
   int li_16;
   int l_ord_total_20;
   int l_ticket_24;
   double l_price_28;
   double l_price_36;
   bool li_44;
   double l_istochastic_48;
   double ld_56;
   double l_iwpr_64;
   double ld_72;
   double l_irsi_80;
   double ld_unused_88;
   double l_istochastic_96;
   double ld_104;
   double l_iwpr_112;
   double ld_120;
   double l_irsi_128;
   double ld_unused_136;
   int l_hist_total_144;
   double ld_148;
   double ld_156;
   double l_ord_takeprofit_164;
   double l_ord_open_price_172;
   double l_ord_lots_180;
   string ls_188;
   HideTestIndicators(TRUE);
   string ls_unused_196 = "";
   string ls_unused_204 = "";
   int li_unused_212 = 0;
   string ls_216 = Year() + "-" + Month() + "-" + Day();
   int l_str2time_224 = StrToTime(ls_216);
   if (gi_180 == FALSE) {
      li_16 = 0;
      if (EachTickMode && Bars != g_bars_152) gi_168 = FALSE;
      l_ord_total_20 = OrdersTotal();
      li_16 = 0;
      li_44 = FALSE;
      for (int l_pos_228 = 0; l_pos_228 < l_ord_total_20; l_pos_228++) {
         OrderSelect(l_pos_228, SELECT_BY_POS, MODE_TRADES);
         if (OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
            li_44 = TRUE;
            if (OrderType() == OP_BUY) {
               if (li_16 == 3 && (EachTickMode && !gi_168) || (!EachTickMode && Bars != g_bars_152)) {
                  OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_104, MediumSeaGreen);
                  if (gi_88) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
                  if (!EachTickMode) g_bars_152 = Bars;
                  li_44 = FALSE;
               } else {
                  if (gi_124 && gi_128 > 0) {
                     if (Bid - OrderOpenPrice() > Point * gi_128) {
                        if (OrderStopLoss() < Bid - Point * gi_128) {
                           OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * gi_128, OrderTakeProfit(), 0, MediumSeaGreen);
                           if (!((!EachTickMode))) continue;
                           g_bars_152 = Bars;
                           continue;
                        }
                     }
                  }
                  if (UseHedge) {
                     OrderSelect(0, SELECT_BY_POS);
                     g_ord_open_price_172 = OrderOpenPrice();
                     g_ticket_160 = OrderTicket();
                     if (OrdersTotal() == 1)
                        if (Ask <= g_ord_open_price_172 - TakeProfit * Point) OrderSend(Symbol(), OP_BUY, 2.0 * Lots, Ask, 3, 0, Ask + TakeProfit * Point, g_ticket_160, 12345, 0, Green);
                     if (OrdersTotal() == 2) {
                        if (Ask <= g_ord_open_price_172 - TakeProfit << 1 * Point) {
                           OrderSend(Symbol(), OP_BUY, 2.0 * (2.0 * Lots), Ask, 3, 0, Ask + TakeProfit * Point, g_ticket_160, 12345, 0, Green);
                           g_magic_84 = 3;
                        }
                     }
                     if (OrdersTotal() == 3) {
                        if (Ask <= g_ord_open_price_172 - 3 * TakeProfit * Point) {
                           OrderSend(Symbol(), OP_BUY, 2.0 * (2.0 * (2.0 * Lots)), Ask, 3, 0, Ask + TakeProfit * Point, g_ticket_160, 12345, 0, Green);
                           g_magic_84 = 4;
                        }
                     }
                  }
               }
            } else {
               if (li_16 == 4 && (EachTickMode && !gi_168) || (!EachTickMode && Bars != g_bars_152)) {
                  OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_104, DarkOrange);
                  if (gi_88) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
                  if (!EachTickMode) g_bars_152 = Bars;
                  li_44 = FALSE;
               } else {
                  if (gi_124 && gi_128 > 0) {
                     if (OrderOpenPrice() - Ask > Point * gi_128) {
                        if (OrderStopLoss() > Ask + Point * gi_128 || OrderStopLoss() == 0.0) {
                           OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * gi_128, OrderTakeProfit(), 0, DarkOrange);
                           if (!((!EachTickMode))) continue;
                           g_bars_152 = Bars;
                           continue;
                        }
                     }
                  }
                  if (UseHedge) {
                     OrderSelect(0, SELECT_BY_POS);
                     g_ord_open_price_172 = OrderOpenPrice();
                     g_ticket_160 = OrderTicket();
                     if (OrdersTotal() == 1)
                        if (Bid >= g_ord_open_price_172 + TakeProfit * Point) OrderSend(Symbol(), OP_SELL, 2.0 * Lots, Bid, 3, 0, Bid - TakeProfit * Point, g_ticket_160, 12345, 0, Green);
                     if (OrdersTotal() == 2)
                        if (Bid >= g_ord_open_price_172 + TakeProfit << 1 * Point) OrderSend(Symbol(), OP_SELL, 2.0 * (2.0 * Lots), Bid, 3, 0, Bid - TakeProfit * Point, g_ticket_160, 12345, 0, Green);
                     if (OrdersTotal() == 3)
                        if (Bid >= g_ord_open_price_172 + 3 * TakeProfit * Point) OrderSend(Symbol(), OP_SELL, 2.0 * (2.0 * (2.0 * Lots)), Bid, 3, 0, Bid - TakeProfit * Point, g_ticket_160, 12345, 0, Green);
                  }
               }
            }
         }
      }
      l_istochastic_48 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, gi_156 + 0);
      ld_56 = 5;
      l_iwpr_64 = iWPR(NULL, 0, 14, gi_156 + 0);
      ld_72 = -92;
      l_irsi_80 = iRSI(NULL, 0, 14, PRICE_CLOSE, gi_156 + 0);
      ld_unused_88 = 45;
      l_istochastic_96 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, gi_156 + 0);
      ld_104 = 95;
      l_iwpr_112 = iWPR(NULL, 0, 14, gi_156 + 0);
      ld_120 = -7;
      l_irsi_128 = iRSI(NULL, 0, 14, PRICE_CLOSE, gi_156 + 0);
      ld_unused_136 = 65;
      if (l_istochastic_48 <= ld_56 && l_iwpr_64 <= ld_72) li_16 = 1;
      if (l_istochastic_96 >= ld_104 && l_iwpr_112 >= ld_120) li_16 = 2;
      if (UseMM == TRUE) Lots = LotsOptimized();
      if (li_16 == 1 && (EachTickMode && !gi_168) || (!EachTickMode && Bars != g_bars_152)) {
         if (!li_44) {
            if (AccountFreeMargin() < 1000.0 * Lots) {
               Print("We have no money. Free Margin = ", AccountFreeMargin());
               return (0);
            }
            if (UseStopLoss) l_price_28 = Ask - StopLoss * Point;
            else l_price_28 = 0.0;
            if (UseTakeProfit) l_price_36 = Ask + TakeProfit * Point;
            else l_price_36 = 0.0;
            l_ticket_24 = OrderSend(Symbol(), OP_BUY, Lots, Ask, g_slippage_104, l_price_28, l_price_36, "1st", g_magic_84, 0, DodgerBlue);
            if (l_ticket_24 > 0) {
               if (OrderSelect(l_ticket_24, SELECT_BY_TICKET, MODE_TRADES)) {
                  Print("BUY order opened : ", OrderOpenPrice());
                  if (gi_88) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
               } else Print("Error opening BUY order : ", GetLastError());
            }
            if (EachTickMode) gi_168 = TRUE;
            if (!EachTickMode) g_bars_152 = Bars;
            return (0);
         }
      }
      if (li_16 == 2 && (EachTickMode && !gi_168) || (!EachTickMode && Bars != g_bars_152)) {
         if (!li_44) {
            if (AccountFreeMargin() < 1000.0 * Lots) {
               Print("We have no money. Free Margin = ", AccountFreeMargin());
               return (0);
            }
            if (UseStopLoss) l_price_28 = Bid + StopLoss * Point;
            else l_price_28 = 0.0;
            if (UseTakeProfit) l_price_36 = Bid - TakeProfit * Point;
            else l_price_36 = 0.0;
            l_ticket_24 = OrderSend(Symbol(), OP_SELL, Lots, Bid, g_slippage_104, l_price_28, l_price_36, "1st", g_magic_84, 0, DeepPink);
            if (l_ticket_24 > 0) {
               if (OrderSelect(l_ticket_24, SELECT_BY_TICKET, MODE_TRADES)) {
                  Print("SELL order opened : ", OrderOpenPrice());
                  if (gi_88) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
               } else Print("Error opening SELL order : ", GetLastError());
            }
            if (EachTickMode) gi_168 = TRUE;
            if (!EachTickMode) g_bars_152 = Bars;
            return (0);
         }
      }
      if (OrdersTotal() >= 1) {
         l_hist_total_144 = OrdersHistoryTotal();
         OrderSelect(l_hist_total_144 - 1, SELECT_BY_POS, MODE_HISTORY);
         l_ord_takeprofit_164 = OrderTakeProfit();
         l_ord_open_price_172 = OrderOpenPrice();
         l_ord_lots_180 = OrderLots();
         ld_156 = TakeProfit * Point;
         ls_188 = OrderComment();
         if (OrderType() == OP_BUY) {
            ld_148 = l_ord_takeprofit_164 - l_ord_open_price_172;
            ld_156 = TakeProfit * Point;
            if (NormalizeDouble(ld_148, 4) == NormalizeDouble(ld_156, 4) && l_ord_lots_180 != Lots) CloseAllBuyOrders(ls_188);
         }
         if (OrderType() == OP_SELL) {
            ld_148 = l_ord_open_price_172 - l_ord_takeprofit_164;
            ld_156 = TakeProfit * Point;
            if (NormalizeDouble(ld_148, 4) == NormalizeDouble(ld_156, 4) && l_ord_lots_180 != Lots) CloseAllSellOrders(ls_188);
         }
      }
      if (!EachTickMode) g_bars_152 = Bars;
   }
   return (0);
}
             
            
            
            
Comments