1 //+------------------------------------------------------------------+
\r
3 //| Copyright © 2011, Zarko Asenov |
\r
4 //| http://jaltoh.6x.to |
\r
5 //+------------------------------------------------------------------+
\r
6 #property copyright "Copyright © 2011, Zarko Asenov"
\r
7 #property link "http://jaltoh.6x.to"
\r
9 //--- input parameters
\r
10 extern string Pair1="EURUSD";
\r
11 extern string Pair2="USDCHF";
\r
12 extern int MA_Period=32;
\r
13 extern double MA_Threshold=0.0001;
\r
14 extern double Lot_Size = 0.1;
\r
15 extern int Magic_Number = 43434343;
\r
16 extern double Profit_Threshold = 5.0;
\r
17 extern int Max_Order_Pairs = 1;
\r
19 double neg_threshold;
\r
20 int order_pairs = 0;
\r
23 close_all(int magic_number)
\r
27 if (order_pairs < 1) return (true);
\r
29 for (int i = 0; i < OrdersTotal(); i++) {
\r
31 OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
\r
33 if (OrderSymbol() != Pair1 && OrderSymbol() != Pair2) continue;
\r
34 else if (OrderMagicNumber() != magic_number) continue;
\r
36 int ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, Gray);
\r
39 Print("Close order failed with error #", GetLastError() );
\r
45 if (rc == true) order_pairs = 0;
\r
51 calc_profit(int magic_number)
\r
53 double presult = 0.0;
\r
55 for (int i = 0; i < OrdersTotal(); i++) {
\r
56 OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
\r
58 if (OrderSymbol() != Pair1 && OrderSymbol() != Pair2) continue;
\r
59 else if (OrderMagicNumber() != magic_number) continue;
\r
61 presult += OrderProfit();
\r
71 if (TimeCurrent() - Time[0] < Period() * 60.0 * 0.75) return (false);
\r
75 //+------------------------------------------------------------------+
\r
76 //| expert initialization function |
\r
77 //+------------------------------------------------------------------+
\r
81 neg_threshold = -1.0 * MA_Threshold;
\r
85 //+------------------------------------------------------------------+
\r
86 //| expert deinitialization function |
\r
87 //+------------------------------------------------------------------+
\r
95 //+------------------------------------------------------------------+
\r
96 //| expert start function |
\r
97 //+------------------------------------------------------------------+
\r
101 if ( calc_profit(Magic_Number) > Profit_Threshold) close_all(Magic_Number);
\r
104 double ehl1 = iCustom(Pair1, Period(), "Ehlers ZeroLag MA Osc", MA_Period, 50, 2.0, 0, 0, Pair1, 2, 0);
\r
105 double ehl1_diff = iCustom(Pair1, Period(), "Ehlers ZeroLag MA Osc", MA_Period, 50, 2.0, 0, 0, Pair1, 0, 0);
\r
106 if (ehl1_diff < 0.0 && ehl1 > neg_threshold) return (0);
\r
107 if (ehl1_diff > 0.0 && ehl1 < MA_Threshold) return (0);
\r
109 double ehl2 = iCustom(Pair1, Period(), "Ehlers ZeroLag MA Osc", MA_Period, 50, 2.0, 0, 0, Pair2, 2, 0);
\r
110 double ehl2_diff = iCustom(Pair1, Period(), "Ehlers ZeroLag MA Osc", MA_Period, 50, 2.0, 0, 0, Pair2, 0, 0);
\r
111 if (ehl2_diff < 0.0 && ehl2 > neg_threshold) return (0);
\r
112 if (ehl2_diff > 0.0 && ehl2 < MA_Threshold) return (0);
\r
114 if (order_pairs() > Max_Order_Pairs) return(0);
\r
116 if (end_is_neigh() == false) return(0);
\r
118 if (ehl1 < neg_threshold && ehl2 > MA_Threshold) {
\r
119 OrderSend(Pair1, OP_SELL, Lot_Size, MarketInfo(Pair1, MODE_BID), 3, 0.0, 0.0, "Hedger", Magic_Number);
\r
120 OrderSend(Pair2, OP_BUY, Lot_Size, MarketInfo(Pair2, MODE_ASK), 3, 0.0, 0.0, "Hedger", Magic_Number);
\r
122 } else if (ehl1 > MA_Threshold && ehl2 < neg_threshold) {
\r
123 OrderSend(Pair1, OP_BUY, Lot_Size, MarketInfo(Pair1, MODE_ASK), 3, 0.0, 0.0, "Hedger", Magic_Number);
\r
124 OrderSend(Pair2, OP_SELL, Lot_Size, MarketInfo(Pair2, MODE_BID), 3, 0.0, 0.0, "Hedger", Magic_Number);
\r
132 //+------------------------------------------------------------------+