| 22 | 24 | double f0_3() { |
| 23 | 25 | double lots_0 = Lots; |
| 24 | 26 | int hist_total_8 = OrdersHistoryTotal(); |
| 25 | 27 | int count_12 = 0; |
| 26 | 28 | lots_0 = NormalizeDouble(AccountFreeMargin() * MaximumRisk / 1000.0, 1); |
| 27 | 29 | if (DecreaseFactor > 0.0) { |
| 28 | 30 | for (int pos_16 = hist_total_8 - 1; pos_16 >= 0; pos_16--) { |
| 29 | 31 | if (OrderSelect(pos_16, SELECT_BY_POS, MODE_HISTORY) == FALSE) { |
| 30 | 32 | Print("Error in history!"); |
| 31 | 33 | break; |
| 32 | 34 | } |
| 33 | 35 | if (OrderSymbol() != Symbol() || OrderType() > OP_SELL) continue; |
| 34 | 36 | if (OrderProfit() > 0.0) break; |
| 35 | 37 | if (OrderProfit() < 0.0) count_12++; |
| 36 | 38 | } |
| 37 | 39 | if (count_12 > 1) lots_0 = NormalizeDouble(lots_0 - lots_0 * count_12 / DecreaseFactor, 1); |
| 38 | 40 | } |
| 39 | 41 | if (lots_0 < 0.1) lots_0 = 0.1; |
| 40 | 42 | return (lots_0); |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | 46 | void f0_2() { |
| 44 | 47 | double ima_0; |
| 45 | 48 | int ticket_8; |
| 46 | 49 | if (Volume[0] <= 1.0) { |
| 47 | 50 | ima_0 = iMA(NULL, 0, MovingPeriod, MovingShift, MODE_SMA, PRICE_CLOSE, 0); |
| 48 | 51 | if (Open[1] > ima_0 && Close[1] < ima_0) ticket_8 = OrderSend(Symbol(), OP_SELL, f0_3(), Bid, 3, 0, 0, "", 20050610, 0, Red); |
| 49 | 52 | else |
| 50 | 53 | if (Open[1] < ima_0 && Close[1] > ima_0) ticket_8 = OrderSend(Symbol(), OP_BUY, f0_3(), Ask, 3, 0, 0, "", 20050610, 0, Blue); |
| 51 | 54 | } |
| 52 | 55 | } |
| 53 | 56 | |
| 54 | 58 | void f0_1() { |
| 55 | 59 | double ima_0; |
| 56 | 60 | if (Volume[0] <= 1.0) { |
| 57 | 61 | ima_0 = iMA(NULL, 0, MovingPeriod, MovingShift, MODE_SMA, PRICE_CLOSE, 0); |
| 58 | 62 | for (int pos_8 = 0; pos_8 < OrdersTotal(); pos_8++) { |
| 59 | 63 | if (OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES) == FALSE) break; |
| 60 | 64 | if (OrderMagicNumber() != 20050610 || OrderSymbol() != Symbol()) continue; |
| 61 | 65 | if (OrderType() == OP_BUY) { |
| 62 | 66 | if (!(Open[1] > ima_0 && Close[1] < ima_0)) break; |
| 63 | 67 | OrderClose(OrderTicket(), OrderLots(), Bid, 3, White); |
| 64 | 68 | return; |
| 65 | 69 | } |
| 66 | 70 | if (OrderType() == OP_SELL) { |
| 67 | 71 | if (!(Open[1] < ima_0 && Close[1] > ima_0)) break; |
| 68 | 72 | OrderClose(OrderTicket(), OrderLots(), Ask, 3, White); |
| 69 | 73 | return; |
| 70 | 74 | } |
| 71 | 75 | } |
| 72 | 76 | } |
| 73 | 77 | } |
| 74 | 78 | |