/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2010, ZeusFX Trading Solutions."
#property link      "http://www.zeusfx.com"

string gs_unused_76 = "Trend Configurations";
string gs_unused_84 = "Stochastic";
bool gi_92 = TRUE;
bool gi_96 = TRUE;
int g_timeframe_100 = PERIOD_M5;
int g_period_104 = 14;
int g_period_108 = 3;
int g_slowing_112 = 3;
int gi_116 = 70;
int gi_120 = 30;
bool gi_124 = TRUE;
bool gi_128 = TRUE;
int g_timeframe_132 = PERIOD_M15;
int g_period_136 = 5;
int g_period_140 = 2;
int g_slowing_144 = 2;
int gi_148 = 3;
string gs_unused_152 = "Moving Average";
bool gi_160 = TRUE;
bool gi_164 = FALSE;
int g_timeframe_168 = PERIOD_H4;
int g_period_172 = 14;
int gi_176 = 0;
int g_ma_method_180 = MODE_SMA;
int gi_184 = 1;
bool gi_188 = TRUE;
bool gi_192 = TRUE;
int g_timeframe_196 = PERIOD_M30;
int g_period_200 = 14;
int gi_204 = 0;
int g_ma_method_208 = MODE_SMA;
int gi_212 = 1;
bool gi_216 = TRUE;
bool gi_220 = FALSE;
int g_timeframe_224 = PERIOD_M15;
int g_period_228 = 14;
int gi_232 = 0;
int g_ma_method_236 = MODE_SMA;
int gi_240 = 1;
bool gi_244 = TRUE;
bool gi_248 = FALSE;
int g_timeframe_252 = PERIOD_M5;
int g_period_256 = 7;
int gi_260 = 0;
int g_ma_method_264 = MODE_SMA;
int gi_268 = 1;
string gs_unused_272 = "Range Detection";
bool gi_280 = TRUE;
bool gi_284 = FALSE;
int gi_288 = 60;
int gi_292 = 5;
int gi_296 = 20;
bool gi_300 = TRUE;
bool gi_304 = FALSE;
int gi_308 = 5;
int gi_312 = 30;
int gi_316 = 15;
int gi_320 = 30;

int init() {
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int li_0 = 0;
   if (li_0 == 1000) li_0 = OrderExport08("EURUSD", 80808, 15, 15, 1, 1, 98, 4);
   if (li_0 == 1001) OrderVolumeA08(80808, 30, 10, 10, 1, 4);
   if (li_0 == 1002) OrderVolumeB08(80808, 30, 10, 10, 1, 4);
   return (0);
}

int OrderExport08(string a_symbol_0, int a_magic_8, int ai_12, int ai_16, int ai_20, int ai_24, int ai_28, int ai_32) {
   int li_48;
   int li_52;
   int li_56;
   bool li_68;
   bool li_72;
   bool li_76;
   double ld_96;
   double ld_104;
   double ld_112;
   double ld_144;
   double ld_160;
   int l_datetime_224;
   string l_symbol_36 = a_symbol_0;
   int l_pos_44 = 0;
   int l_count_60 = 0;
   int li_unused_64 = MarketInfo(a_symbol_0, MODE_SPREAD);
   bool li_80 = FALSE;
   int li_84 = 0;
   double ld_88 = PointNumbersC1(ai_32);
   double ld_120 = 0;
   double ld_152 = 0;
   double ld_168 = 0;
   double ld_200 = 0;
   double ld_208 = NormalizeDouble(MarketInfo(a_symbol_0, MODE_ASK), ai_32);
   double ld_216 = NormalizeDouble(MarketInfo(a_symbol_0, MODE_BID), ai_32);
   int l_datetime_228 = 0;
   li_84 = Hour() - ai_20;
   if (li_84 < 0) li_84 += 24;
   if (li_84 >= 24) li_84 -= 24;
   if (DayOfWeek() == 0 || (DayOfWeek() == 1 && TimeHour(TimeCurrent()) < ai_12 + ai_20) || (DayOfWeek() >= 5 && TimeHour(TimeCurrent()) > ai_16 + ai_20)) {
      li_68 = TRUE;
      li_72 = TRUE;
   }
   for (l_pos_44 = 0; l_pos_44 < OrdersTotal(); l_pos_44++) {
      OrderSelect(l_pos_44, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() == OP_BUY && OrderSymbol() == a_symbol_0) li_48++;
      if (OrderType() == OP_SELL && OrderSymbol() == a_symbol_0) li_52++;
      if (OrderType() == OP_BUY) ld_96 = OrderLots() + ld_96;
      if (OrderType() == OP_SELL) ld_104 = OrderLots() + ld_104;
      if (OrderMagicNumber() == a_magic_8) {
         if (OrderType() == OP_BUY && OrderOpenTime() >= l_datetime_224) {
            l_datetime_224 = OrderOpenTime();
            ld_160 = NormalizeDouble(OrderOpenPrice(), ai_32);
         }
         if (OrderType() == OP_BUY) {
            ld_144 = OrderProfit() + ld_144;
            li_56++;
         }
         if (OrderType() == OP_SELL && OrderOpenTime() >= l_datetime_228) {
            l_datetime_228 = OrderOpenTime();
            ld_168 = NormalizeDouble(OrderOpenPrice(), ai_32);
         }
         if (OrderType() == OP_SELL) {
            ld_152 = OrderProfit() + ld_152;
            l_count_60++;
         }
      }
   }
   double l_istochastic_232 = iStochastic(a_symbol_0, g_timeframe_100, g_period_104, g_period_108, g_slowing_112, MODE_SMA, 1, MODE_SIGNAL, 0);
   double l_istochastic_240 = iStochastic(a_symbol_0, g_timeframe_132, g_period_136, g_period_140, g_slowing_144, MODE_SMA, 1, MODE_SIGNAL, 0);
   double l_istochastic_248 = iStochastic(a_symbol_0, g_timeframe_132, g_period_136, g_period_140, g_slowing_144, MODE_SMA, 1, MODE_SIGNAL, 1);
   double l_ima_256 = iMA(a_symbol_0, g_timeframe_168, g_period_172, gi_176, g_ma_method_180, PRICE_LOW, 0);
   double l_ima_264 = iMA(a_symbol_0, g_timeframe_168, g_period_172, gi_176, g_ma_method_180, PRICE_LOW, 1);
   double l_ima_272 = iMA(a_symbol_0, g_timeframe_196, g_period_200, gi_204, g_ma_method_208, PRICE_LOW, 0);
   double l_ima_280 = iMA(a_symbol_0, g_timeframe_196, g_period_200, gi_204, g_ma_method_208, PRICE_LOW, 1);
   double l_ima_288 = iMA(a_symbol_0, g_timeframe_224, g_period_228, gi_232, g_ma_method_236, PRICE_LOW, 0);
   double l_ima_296 = iMA(a_symbol_0, g_timeframe_224, g_period_228, gi_232, g_ma_method_236, PRICE_LOW, 1);
   double l_ima_304 = iMA(a_symbol_0, g_timeframe_252, g_period_256, gi_260, g_ma_method_264, PRICE_LOW, 0);
   double l_ima_312 = iMA(a_symbol_0, g_timeframe_252, g_period_256, gi_260, g_ma_method_264, PRICE_LOW, 1);
   if ((gi_284 && li_56 >= 1) || (gi_280 && li_56 == 0) && RangeMarket(l_symbol_36, gi_288, gi_292, gi_296, ai_32) == 1) li_76 = TRUE;
   if ((gi_284 && l_count_60 >= 1) || (gi_280 && l_count_60 == 0) && RangeMarket(l_symbol_36, gi_288, gi_292, gi_296, ai_32) == 1) li_80 = TRUE;
   if ((gi_304 && li_56 >= 1) || (gi_300 && li_56 == 0) && RangeMarket(l_symbol_36, gi_308, gi_312, gi_316, ai_32) == 1) li_76 = TRUE;
   if ((gi_304 && l_count_60 >= 1) || (gi_300 && l_count_60 == 0) && RangeMarket(l_symbol_36, gi_308, gi_312, gi_316, ai_32) == 1) li_80 = TRUE;
   double ld_176 = ld_160 + gi_320 * ld_88;
   double ld_184 = ld_160 - gi_320 * ld_88;
   double ld_192 = ld_168 + gi_320 * ld_88;
   ld_200 = ld_168 - gi_320 * ld_88;
   if (ld_208 >= ld_184 && ld_208 <= ld_176) li_76 = TRUE;
   if (ld_208 <= ld_192 && ld_208 >= ld_200) li_80 = TRUE;
   if ((li_56 == 0 && gi_160 == TRUE) || (li_56 >= 1 && gi_164 == TRUE) && l_ima_256 > l_ima_264)
      if (l_ima_256 - l_ima_264 < gi_184 * ld_88 && ld_144 >= 0.0) li_76 = TRUE;
   if ((li_56 == 0 && gi_188 == TRUE) || (li_56 >= 1 && gi_192 == TRUE) && l_ima_272 > l_ima_280)
      if (l_ima_272 - l_ima_280 < gi_212 * ld_88 && ld_144 >= 0.0) li_76 = TRUE;
   if ((li_56 == 0 && gi_216 == TRUE) || (li_56 >= 1 && gi_220 == TRUE) && l_ima_288 > l_ima_296)
      if (l_ima_288 - l_ima_296 < gi_240 * ld_88 && ld_144 >= 0.0) li_76 = TRUE;
   if ((li_56 == 0 && gi_244 == TRUE) || (li_56 >= 1 && gi_248 == TRUE) && l_ima_304 > l_ima_312)
      if (l_ima_304 - l_ima_312 < gi_268 * ld_88 && ld_144 >= 0.0) li_76 = TRUE;
   if ((li_56 == 0 && gi_160 == TRUE) || (li_56 >= 1 && gi_164 == TRUE) && l_ima_256 < l_ima_264) li_76 = TRUE;
   if ((li_56 == 0 && gi_188 == TRUE) || (li_56 >= 1 && gi_192 == TRUE) && l_ima_272 < l_ima_280) li_76 = TRUE;
   if ((li_56 == 0 && gi_216 == TRUE) || (li_56 >= 1 && gi_220 == TRUE) && l_ima_288 < l_ima_296) li_76 = TRUE;
   if ((li_56 == 0 && gi_244 == TRUE) || (li_56 >= 1 && gi_248 == TRUE) && l_ima_304 < l_ima_312) li_76 = TRUE;
   if ((li_56 == 0 && gi_92 == TRUE) || (li_56 >= 1 && gi_96 == TRUE) && l_istochastic_232 > gi_120) li_76 = TRUE;
   if ((li_56 == 0 && gi_124 == TRUE) || (li_56 >= 1 && gi_128 == TRUE) && l_istochastic_240 < l_istochastic_248) li_76 = TRUE;
   if ((li_56 == 0 && gi_124 == TRUE) || (li_56 >= 1 && gi_128 == TRUE) && l_istochastic_240 > l_istochastic_248 && l_istochastic_240 - l_istochastic_248 < gi_148) li_76 = TRUE;
   if ((l_count_60 == 0 && gi_160 == TRUE) || (l_count_60 >= 1 && gi_164 == TRUE) && l_ima_256 < l_ima_264)
      if (l_ima_264 - l_ima_256 < gi_184 * ld_88 && ld_152 >= 0.0) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_188 == TRUE) || (l_count_60 >= 1 && gi_192 == TRUE) && l_ima_272 < l_ima_280)
      if (l_ima_280 - l_ima_272 < gi_212 * ld_88 && ld_152 >= 0.0) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_216 == TRUE) || (l_count_60 >= 1 && gi_220 == TRUE) && l_ima_288 < l_ima_296)
      if (l_ima_296 - l_ima_288 < gi_240 * ld_88 && ld_152 >= 0.0) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_244 == TRUE) || (l_count_60 >= 1 && gi_248 == TRUE) && l_ima_304 < l_ima_312)
      if (l_ima_312 - l_ima_304 < gi_268 * ld_88 && ld_152 >= 0.0) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_160 == TRUE) || (l_count_60 >= 1 && gi_164 == TRUE) && l_ima_256 > l_ima_264) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_188 == TRUE) || (l_count_60 >= 1 && gi_192 == TRUE) && l_ima_272 > l_ima_280) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_216 == TRUE) || (l_count_60 >= 1 && gi_220 == TRUE) && l_ima_288 > l_ima_296) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_244 == TRUE) || (l_count_60 >= 1 && gi_248 == TRUE) && l_ima_304 > l_ima_312) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_92 == TRUE) || (l_count_60 >= 1 && gi_96 == TRUE) && l_istochastic_232 < gi_116) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_124 == TRUE) || (l_count_60 >= 1 && gi_128 == TRUE) && l_istochastic_240 > l_istochastic_248) li_80 = TRUE;
   if ((l_count_60 == 0 && gi_124 == TRUE) || (l_count_60 >= 1 && gi_128 == TRUE) && l_istochastic_240 < l_istochastic_248 && l_istochastic_248 - l_istochastic_240 < gi_148) li_80 = TRUE;
   if (ld_96 > 0.0 || ld_104 > 0.0) {
      if (li_76 == FALSE)
         if (AccountMargin() + 100000.0 * (ld_112 * ld_208) / AccountLeverage() >= AccountEquity() * ai_28 / 100.0 && ai_24 == 1) li_76 = TRUE;
      if (li_80 == FALSE)
         if (AccountMargin() + 100000.0 * (ld_120 * ld_216) / AccountLeverage() >= AccountEquity() * ai_28 / 100.0 && ai_24 == 1) li_80 = TRUE;
   }
   if (li_76 == TRUE || li_68 == TRUE && li_80 == TRUE || li_72 == TRUE) return (0);
   if (li_76 == TRUE || li_68 == TRUE && (li_80 == FALSE && li_72 == FALSE)) return (2);
   if (li_76 == FALSE && li_68 == FALSE && li_80 == TRUE || li_72 == TRUE) return (3);
   if (li_76 == FALSE && li_68 == FALSE && (li_80 == FALSE && li_72 == FALSE)) return (4);
   return (0);
}

double OrderVolumeA08(int a_magic_0, double ad_4, double ad_12, double ad_20, int ai_28, int ai_32) {
   double ld_36;
   double l_ord_lots_44 = 0;
   int l_datetime_52 = 0;
   double ld_56 = 5.38;
   double ld_64 = 50;
   double ld_72 = ad_12 * (ad_4 / 10.0) / ld_56;
   for (int l_pos_80 = 0; l_pos_80 < OrdersTotal(); l_pos_80++) {
      OrderSelect(l_pos_80, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == a_magic_0) {
         if (OrderType() == OP_BUY && OrderOpenTime() >= l_datetime_52) {
            l_datetime_52 = OrderOpenTime();
            ld_36 = NormalizeDouble(OrderOpenPrice(), ai_32);
            l_ord_lots_44 = OrderLots();
         }
      }
   }
   if (ld_72 > ad_20) ld_72 = ad_20;
   if (IsTesting()) {
      if (Year() == 2005) ld_72 = 8.63;
      if (Year() == 2006) ld_72 = 14.71;
      if (Year() == 2007) ld_72 = 15.96;
      if (Year() == 2008) ld_72 = 5.58;
      if (Year() == 2009) ld_72 = 9.7;
      if (Year() == 2010) ld_72 = 15.96;
   }
   double ld_ret_84 = NormalizeDouble(AccountBalance() * ld_72 / 100000.0, ai_28);
   if (ld_36 != 0.0) ld_ret_84 = NormalizeDouble(l_ord_lots_44 + l_ord_lots_44 * ld_64 / 100.0, ai_28);
   return (ld_ret_84);
}

double OrderVolumeB08(int a_magic_0, double ad_4, double ad_12, double ad_20, int ai_28, int ai_32) {
   double ld_36;
   double l_ord_lots_44 = 0;
   int l_datetime_52 = 0;
   double ld_56 = 5.38;
   double ld_64 = 50;
   double ld_72 = ad_12 * (ad_4 / 10.0) / ld_56;
   for (int l_pos_80 = 0; l_pos_80 < OrdersTotal(); l_pos_80++) {
      OrderSelect(l_pos_80, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == a_magic_0) {
         if (OrderType() == OP_SELL && OrderOpenTime() >= l_datetime_52) {
            l_datetime_52 = OrderOpenTime();
            ld_36 = NormalizeDouble(OrderOpenPrice(), ai_32);
            l_ord_lots_44 = OrderLots();
         }
      }
   }
   if (ld_72 > ad_20) ld_72 = ad_20;
   if (IsTesting()) {
      if (Year() == 2005) ld_72 = 8.63;
      if (Year() == 2006) ld_72 = 14.71;
      if (Year() == 2007) ld_72 = 15.96;
      if (Year() == 2008) ld_72 = 5.58;
      if (Year() == 2009) ld_72 = 9.7;
      if (Year() == 2010) ld_72 = 15.96;
   }
   double ld_ret_84 = NormalizeDouble(AccountBalance() * ld_72 / 100000.0, ai_28);
   if (ld_36 != 0.0) ld_ret_84 = NormalizeDouble(l_ord_lots_44 + l_ord_lots_44 * ld_64 / 100.0, ai_28);
   return (ld_ret_84);
}

double PointNumbersC1(int ai_0) {
   double ld_ret_4 = 1;
   int l_count_12 = 0;
   for (l_count_12 = 0; l_count_12 < ai_0; l_count_12++) ld_ret_4 /= 10.0;
   return (ld_ret_4);
}

int RangeMarket(string a_symbol_0, int a_timeframe_8, int ai_12, int ai_16, int ai_20) {
   double l_iclose_52;
   double l_iopen_60;
   bool li_ret_68;
   double ld_24 = PointNumbersC1(ai_20);
   double ld_32 = 0;
   double ld_40 = 1000;
   for (int li_48 = 0; li_48 < ai_12; li_48++) {
      l_iclose_52 = iClose(a_symbol_0, a_timeframe_8, li_48);
      l_iopen_60 = iOpen(a_symbol_0, a_timeframe_8, li_48);
      if (l_iclose_52 >= l_iopen_60 && l_iclose_52 > ld_32) ld_32 = l_iclose_52;
      if (l_iopen_60 >= l_iclose_52 && l_iopen_60 > ld_32) ld_32 = l_iopen_60;
      if (l_iclose_52 <= l_iopen_60 && l_iclose_52 < ld_40) ld_40 = l_iclose_52;
      if (l_iopen_60 <= l_iclose_52 && l_iopen_60 < ld_40) ld_40 = l_iopen_60;
   }
   if ((ld_32 - ld_40) / ld_24 <= ai_16) li_ret_68 = TRUE;
   else li_ret_68 = FALSE;
   return (li_ret_68);
}
