/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Forex Invador Team"
#property link      "www.forexinvader.com"

bool gi_76 = FALSE;
bool gi_80 = TRUE;
extern double Lots = 1.0;
extern int TakeProfit = 25;
bool gi_96 = TRUE;
extern int StopLoss = 100;
bool gi_104 = TRUE;
extern bool UseTrailingStop = FALSE;
extern int TrailingStop = 0;
extern int Slippage = 3;
extern int MagicNumber = 1555667;
int g_bars_124;
int gi_unused_128;
bool gi_132 = FALSE;

int init() {
   g_bars_124 = Bars;
   if (gi_80) gi_unused_128 = 0;
   else gi_unused_128 = 1;
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int l_ticket_8;
   double l_price_12;
   double l_price_20;
   int li_0 = 0;
   if (gi_80 && Bars != g_bars_124) gi_132 = FALSE;
   int l_ord_total_4 = OrdersTotal();
   li_0 = 0;
   HideTestIndicators(TRUE);
   double l_imomentum_116 = iMomentum(NULL, 0, 200, PRICE_OPEN, 1);
   double l_imomentum_124 = iMomentum(NULL, 0, 200, PRICE_OPEN, 0);
   double l_imacd_76 = iMACD(NULL, 0, 90, 99, 88, PRICE_TYPICAL, MODE_MAIN, 0);
   double l_imacd_84 = iMACD(NULL, 0, 90, 99, 88, PRICE_TYPICAL, MODE_MAIN, 1);
   double l_imacd_92 = iMACD(NULL, 0, 90, 99, 88, PRICE_TYPICAL, MODE_SIGNAL, 0);
   double l_isar_100 = iSAR(NULL, 0, 0.005, 0.5, 1);
   double l_isar_108 = iSAR(NULL, 0, 0.005, 0.5, 0);
   double l_irsi_132 = iRSI(NULL, 0, 21, PRICE_CLOSE, 0);
   double l_iadx_140 = iADX(NULL, 0, 21, PRICE_CLOSE, MODE_MAIN, 0);
   HideTestIndicators(FALSE);
   bool li_148 = FALSE;
   for (int l_pos_152 = 0; l_pos_152 < l_ord_total_4; l_pos_152++) {
      OrderSelect(l_pos_152, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
         li_148 = TRUE;
         if (OrderType() == OP_BUY) {
            if (li_0 == 3 && (gi_80 && !gi_132) || (!gi_80 && Bars != g_bars_124)) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (gi_76) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!gi_80) g_bars_124 = Bars;
               li_148 = FALSE;
            } else {
               if (UseTrailingStop && TrailingStop > 0) {
                  if (Bid - OrderOpenPrice() > Point * TrailingStop) {
                     if (OrderStopLoss() < Bid - Point * TrailingStop) {
                        OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                        if (!gi_80) g_bars_124 = Bars;
                     }
                  }
               }
            }
         } else {
            if (li_0 == 4 && (gi_80 && !gi_132) || (!gi_80 && Bars != g_bars_124)) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (gi_76) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!gi_80) g_bars_124 = Bars;
               li_148 = FALSE;
            } else {
               if (UseTrailingStop && TrailingStop > 0) {
                  if (OrderOpenPrice() - Ask > Point * TrailingStop) {
                     if (OrderStopLoss() > Ask + Point * TrailingStop || OrderStopLoss() == 0.0) {
                        OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                        if (!gi_80) g_bars_124 = Bars;
                     }
                  }
               }
            }
         }
      }
   }
   if (l_isar_100 < l_isar_108 && l_imomentum_124 < 100.0 && l_imacd_76 > 0.0 && l_irsi_132 < 70.0 && l_iadx_140 > 25.0) li_0 = 1;
   if (l_isar_100 > l_isar_108 && l_imomentum_124 > 100.0 && l_imacd_76 < 0.0 && l_irsi_132 > 30.0 && l_iadx_140 < 25.0) li_0 = 2;
   if (li_0 == 1 && (gi_80 && !gi_132) || (!gi_80 && Bars != g_bars_124)) {
      if (!li_148) {
         if (AccountFreeMargin() < 1000.0 * Lots) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return (0);
         }
         if (gi_96) l_price_12 = Ask - StopLoss * Point;
         else l_price_12 = 0.0;
         if (gi_104) l_price_20 = Ask + TakeProfit * Point;
         else l_price_20 = 0.0;
         l_ticket_8 = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, l_price_12, l_price_20, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         if (l_ticket_8 > 0) {
            if (OrderSelect(l_ticket_8, SELECT_BY_TICKET, MODE_TRADES)) {
               Print("BUY order opened : ", OrderOpenPrice());
               if (gi_76) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
            } else Print("Error opening BUY order : ", GetLastError());
         }
         if (gi_80) gi_132 = TRUE;
         if (!gi_80) g_bars_124 = Bars;
         return (0);
      }
   }
   if (li_0 == 2 && (gi_80 && !gi_132) || (!gi_80 && Bars != g_bars_124)) {
      if (!li_148) {
         if (AccountFreeMargin() < 1000.0 * Lots) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return (0);
         }
         if (gi_96) l_price_12 = Bid + StopLoss * Point;
         else l_price_12 = 0.0;
         if (gi_104) l_price_20 = Bid - TakeProfit * Point;
         else l_price_20 = 0.0;
         l_ticket_8 = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, l_price_12, l_price_20, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         if (l_ticket_8 > 0) {
            if (OrderSelect(l_ticket_8, SELECT_BY_TICKET, MODE_TRADES)) {
               Print("SELL order opened : ", OrderOpenPrice());
               if (gi_76) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
            } else Print("Error opening SELL order : ", GetLastError());
         }
         if (gi_80) gi_132 = TRUE;
         if (!gi_80) g_bars_124 = Bars;
         return (0);
      }
   }
   if (!gi_80) g_bars_124 = Bars;
   return (0);
}
