#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

extern int g_ma_method_88 = 0;
extern int g_period_92 = 52;
extern int gi_96 = 0;
extern int g_applied_price_100 = 0;
extern double Lots = 0.01;
extern bool RiskMM = TRUE;
extern double RiskPercent = 1.0;
extern double MinLots = 0.01;
extern double MaxLots = 100.0;
double G_pips_128 = 1000.0;
double G_pips_136 = 1000.0;
double G_pips_144 = 1000.0;
double G_pips_152 = 1000.0;
double G_slippage_160 = 5.0;
string G_str_concat_168 = "";
int G_ticket_176;
int G_ticket_180;
double G_price_184;
double G_price_192;
double G_price_200;
double G_price_208;

int start() {
   RefreshRates();
   if (RiskMM) CalculateMM();
   double icustom_0 = iCustom(NULL, 0, "!XPS v8 OSCILLATOR", g_ma_method_88, g_period_92, gi_96, g_applied_price_100, 0, 1);
   double icustom_8 = iCustom(NULL, 0, "!XPS v8 OSCILLATOR", g_ma_method_88, g_period_92, gi_96, g_applied_price_100, 0, 2);
   bool Li_16 = FALSE;
   int Li_unused_20 = 0;
   double lots_24 = Lots / 1.0;
   double lots_32 = Lots / 1.0;
   if (icustom_0 > 0.0) {
      Li_16 = TRUE;
      G_str_concat_168 = "\n\n";
      G_str_concat_168 = StringConcatenate(G_str_concat_168, 
      "\n                                                                 BULLISH TREND: ", ConvertBoolToStr(Li_16));
      G_str_concat_168 = StringConcatenate(G_str_concat_168, "              BUY TRADE: Allowed");
      G_str_concat_168 = StringConcatenate(G_str_concat_168, 
      "\n                                                                 XARD BUYER Trade One:  ", " Takeprofit1: ", G_pips_136 / 10.0, "pips ", "   Stoploss1: ", G_pips_128 / 10.0,
         "pips");
      G_str_concat_168 = StringConcatenate(G_str_concat_168, 
      "\n                                                                 XARD BUYER Trade Two:  ", " Takeprofit2: ", G_pips_152 / 10.0, "pips ", "   Stoploss2: ", G_pips_144 / 10.0,
         "pips");
      G_ticket_176 = OrderSend(Symbol(), OP_BUY, lots_24, Ask, G_slippage_160, 0, 0);
      G_price_184 = Ask - G_pips_128 * Point;
      G_price_200 = Ask + G_pips_136 * Point;
      OrderModify(G_ticket_176, OrderOpenPrice(), G_price_184, G_price_200, 0, Blue);
      G_ticket_180 = OrderSend(Symbol(), OP_BUY, lots_32, Ask, G_slippage_160, 0, 0);
      G_price_192 = Ask - G_pips_144 * Point;
      G_price_208 = Ask + G_pips_152 * Point;
      OrderModify(G_ticket_180, OrderOpenPrice(), G_price_192, G_price_208, 0, Blue);
   } else {
      if (icustom_0 < 0.0) {
         Li_unused_20 = 1;
         G_str_concat_168 = "\n\n";
         G_str_concat_168 = StringConcatenate(G_str_concat_168, 
         "\n                                                                 BULLISH TREND: ", ConvertBoolToStr(Li_16));
         G_str_concat_168 = StringConcatenate(G_str_concat_168, "              BUY TRADE: Refused");
      }
   }
   Comment(G_str_concat_168);
   int error_40 = GetLastError();
   Print("error=", error_40);
   return (0);
}

string ConvertBoolToStr(bool Ai_0) {
   if (Ai_0) return ("True");
   return ("False");
}

void CalculateMM() {
   double minlot_0 = MarketInfo(Symbol(), MODE_MINLOT);
   double maxlot_8 = MarketInfo(Symbol(), MODE_MAXLOT);
   Lots = AccountBalance() / 20000.0 * RiskPercent;
   Lots = MathMin(maxlot_8, MathMax(minlot_0, Lots));
   if (minlot_0 < 0.1) Lots = NormalizeDouble(Lots, 2);
   else {
      if (minlot_0 < 1.0) Lots = NormalizeDouble(Lots, 1);
      else Lots = NormalizeDouble(Lots, 0);
   }
   if (Lots < minlot_0) Lots = minlot_0;
   if (Lots > maxlot_8) Lots = maxlot_8;
}