1 //+------------------------------------------------------------------+
\r
3 //| Copyright © 2010, MetaQuotes Software Corp. |
\r
4 //| http://www.metaquotes.net |
\r
5 //+------------------------------------------------------------------+
\r
6 #property copyright "Copyright © 2010, MetaQuotes Software Corp."
\r
7 #property link "http://www.metaquotes.net"
\r
15 extern double lot=0.01;
\r
19 extern double profit_close = 10.0;
\r
21 //+------------------------------------------------------------------+
\r
22 //| expert initialization function |
\r
23 //+------------------------------------------------------------------+
\r
31 //+------------------------------------------------------------------+
\r
32 //| expert deinitialization function |
\r
33 //+------------------------------------------------------------------+
\r
41 //+------------------------------------------------------------------+
\r
42 //| expert start function |
\r
43 //+------------------------------------------------------------------+
\r
47 int ticket, total,cntsell,cntbuy,first=0,second=0;
\r
52 int spread = MarketInfo(Symbol(), MODE_SPREAD)+3;
\r
55 int ordt=OrdersTotal();
\r
56 if(CntAll(OP_SELLSTOP)==0 && CntAll(OP_BUYSTOP)==0){first=1;}else{first=0;}
\r
57 if(CntAll(OP_SELLSTOP)+ CntAll(OP_BUYSTOP)==1){second=1;}else{second=0;}
\r
61 if (alertTag!=Time[0] && first==1 && second==0)
\r
64 if(CntAll(OP_SELLSTOP)==0 && CntAll(OP_BUYSTOP)==0)
\r
66 OrderSend(Symbol(),OP_BUYSTOP,lot,Ask+dis*Point,3,Ask,0,"My order BuyStop",16384,0,Green);
\r
69 OrderSend(Symbol(),OP_SELLSTOP,lot,Bid-dis*Point,3,Bid,0,"My order SellStop",16384,0,Red);
\r
76 if (alertTag!=Time[0] && second==1 && first==0)
\r
79 if(CntAll(OP_SELLSTOP)==0 || CntAll(OP_BUYSTOP)==0)
\r
85 for(int cnt=0;cnt<OrdersTotal();cnt++) {
\r
88 OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
\r
89 if(OrderType() == OP_SELL && Bid < OrderOpenPrice() - dis * Point) {
\r
90 OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss() - dis * Point, OrderTakeProfit(), 3, Red);
\r
91 } else if(OrderType()==OP_BUY && Ask > OrderOpenPrice() + dis * Point) {
\r
92 OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss() + dis * Point, OrderTakeProfit(), 3, Green);
\r
98 OrderSend(Symbol(),OP_BUYSTOP,lot,Ask+dis*Point,3,Ask,0,"My order BuyStop",16384,0,Green);
\r
100 OrderSend(Symbol(),OP_SELLSTOP,lot,Bid-dis*Point,3,Bid,0,"My order SellStop",16384,0,Red);
\r
106 if (AccountProfit() > profit_close) CloseAll();
\r
111 //+------------------------------------------------------------------+
\r
112 //+------------------------------------------------------------------+
\r
116 for(i=0;i<OrdersTotal();i++)
\r
118 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
\r
120 if(OrderType()==OP_BUY && a==1)
\r
122 OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
\r
125 if(OrderType()==OP_SELL && a==2)
\r
127 OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
\r
130 if(OrderType()==OP_BUYSTOP||OP_BUYLIMIT && a==3)
\r
132 OrderDelete(OrderTicket());
\r
135 if(OrderType()==OP_SELLSTOP||OP_SELLLIMIT && a==4 )
\r
137 OrderDelete(OrderTicket());
\r
144 //-------------------------------------------------------+
\r
145 //functions lots of functions
\r
146 //-------------------------------------------------------+
\r
147 //////////////////////////////////////////////////////////
\r
156 for(i=0;i<OrdersTotal();i++)
\r
158 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
\r
159 if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
\r
163 if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
\r
167 if(OrderType()==OP_BUYSTOP && OrderSymbol()==Symbol())
\r
171 if(OrderType()==OP_SELLSTOP && OrderSymbol()==Symbol())
\r
176 if(a==OP_BUY){return(buy);}
\r
177 if(a==OP_SELL){return(sell);}
\r
178 if(a==OP_BUYSTOP){return(buystop);}
\r
179 if(a==OP_SELLSTOP){return(sellstop);}
\r
182 ///////////////////////////////////////////////////
\r
186 if(Close[a]>Open[a]){value=1;}
\r
187 else if(Close[a]<Open[a]){value=-1;}
\r
188 else if(Close[a]==Open[a]){value=0;}
\r
191 /////////////////////////////////////
\r
195 for(i=0; i < OrdersTotal(); i++)
\r
197 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
\r
200 if(OrderType()==OP_BUY)
\r
202 OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
\r
205 if(OrderType()==OP_SELL)
\r
207 OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
\r
210 if(OrderType()==OP_BUYSTOP||OP_BUYLIMIT)
\r
212 OrderDelete(OrderTicket());
\r
215 if(OrderType()==OP_SELLSTOP||OP_SELLLIMIT)
\r
217 OrderDelete(OrderTicket());
\r