Thursday, June 13, 2013 14:30:34
F:\Compile\Moving Average.mq4F:\Compile\Moving Average2.mq4
11 
22extern double Lots = 0.1;
33extern double MaximumRisk = 0.02;
44extern double DecreaseFactor = 3.0;
55extern double MovingPeriod = 12.0;
66extern double MovingShift = 6.0;
77 
 8// 3B4FF059E3EA91105A3BBDBF7628BC6B
8int f0_0(string as_unused_0) {9int f0_0(string Grps_unused_0) {
910   int count_8 = 0;
1011   int count_12 = 0;
1112   for (int pos_16 = 0; pos_16 < OrdersTotal(); pos_16++) {
1213      if (OrderSelect(pos_16, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
1314      if (OrderSymbol() == Symbol() && OrderMagicNumber() == 20050610) {
1415         if (OrderType() == OP_BUY) count_8++;
1516         if (OrderType() == OP_SELL) count_12++;
1617      }
1718   }
1819   if (count_8 > 0) return (count_8);
1920   return (-count_12);
2021}
2122                                                                                                                                                                                                                                                                                                  
 23// EBFE91FAEB07FF5788FD1001AD46AE29
2224double f0_3() {
2325   double lots_0 = Lots;
2426   int hist_total_8 = OrdersHistoryTotal();
2527   int count_12 = 0;
2628   lots_0 = NormalizeDouble(AccountFreeMargin() * MaximumRisk / 1000.0, 1);
2729   if (DecreaseFactor > 0.0) {
2830      for (int pos_16 = hist_total_8 - 1; pos_16 >= 0; pos_16--) {
2931         if (OrderSelect(pos_16, SELECT_BY_POS, MODE_HISTORY) == FALSE) {
3032            Print("Error in history!");
3133            break;
3234         }
3335         if (OrderSymbol() != Symbol() || OrderType() > OP_SELL) continue;
3436         if (OrderProfit() > 0.0) break;
3537         if (OrderProfit() < 0.0) count_12++;
3638      }
3739      if (count_12 > 1) lots_0 = NormalizeDouble(lots_0 - lots_0 * count_12 / DecreaseFactor, 1);
3840   }
3941   if (lots_0 < 0.1) lots_0 = 0.1;
4042   return (lots_0);
4143}
4244                                                                                                                                                                                                                                                                                                                                            
 45// CB17DEBBAA4E3FCCC1627B748C11F14C
4346void f0_2() {
4447   double ima_0;
4548   int ticket_8;
4649   if (Volume[0] <= 1.0) {
4750      ima_0 = iMA(NULL, 0, MovingPeriod, MovingShift, MODE_SMA, PRICE_CLOSE, 0);
4851      if (Open[1] > ima_0 && Close[1] < ima_0) ticket_8 = OrderSend(Symbol(), OP_SELL, f0_3(), Bid, 3, 0, 0, "", 20050610, 0, Red);
4952      else
5053         if (Open[1] < ima_0 && Close[1] > ima_0) ticket_8 = OrderSend(Symbol(), OP_BUY, f0_3(), Ask, 3, 0, 0, "", 20050610, 0, Blue);
5154   }
5255}
5356                                                                                                                                                                                                                                                                                                                                          
 57// 792CA38593D2232BE04E6146E4A427A1
5458void f0_1() {
5559   double ima_0;
5660   if (Volume[0] <= 1.0) {
5761      ima_0 = iMA(NULL, 0, MovingPeriod, MovingShift, MODE_SMA, PRICE_CLOSE, 0);
5862      for (int pos_8 = 0; pos_8 < OrdersTotal(); pos_8++) {
5963         if (OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
6064         if (OrderMagicNumber() != 20050610 || OrderSymbol() != Symbol()) continue;
6165         if (OrderType() == OP_BUY) {
6266            if (!(Open[1] > ima_0 && Close[1] < ima_0)) break;
6367            OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);
6468            return;
6569         }
6670         if (OrderType() == OP_SELL) {
6771            if (!(Open[1] < ima_0 && Close[1] > ima_0)) break;
6872            OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);
6973            return;
7074         }
7175      }
7276   }
7377}
7478                                                                                                                                                                                                                                                                                                                 
 79// EA2B2676C28C0DB26D39331A336C6B92
7580void start() {
7681   if (Bars < 100 || IsTradeAllowed() == FALSE) return;
7782   if (f0_0(Symbol()) == 0) {
7883      f0_2();
7984      return;
8085   }
8186   f0_1();
8287}
8388