Áѹà»Ô´µÒÁà§×è͹ààµè¨ÐãËé»Ô´·Õèà§×è͹䧵èÍä»·Óä§ÍÐ ¢Íº¤Ø³¤Ñº
extern double Lots=0.1;
extern int Slippage=3;
extern int MagicNumber1=2001;
extern int MagicNumber2=2002;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int i;
//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
for(i=1; i<=OrdersTotal(); i++)
{
if (OrderSelect(i-1,SELECT_BY_POS)==true)
{
if(OrderMagicNumber()==MagicNumber1) {int halt1=1;}
if(OrderMagicNumber()==MagicNumber2) {int halt2=1;}
}
}
}
//-------------------------------------------------------------------+
//-----------------------------------------------------------------
// Bar checks
//-----------------------------------------------------------------
if(iOpen(NULL,0,1)<iClose(NULL,0,1)) int BarOneUp=1;
if(iOpen(NULL,0,1)>iClose(NULL,0,1)) int BarOneDown=1;
if(iOpen(NULL,0,2)<iClose(NULL,0,2)) int BarTwoUp=1;
if(iOpen(NULL,0,2)>iClose(NULL,0,2)) int BarTwoDown=1;
if(iOpen(NULL,0,3)<iClose(NULL,0,3)) int BarThreeUp=1;
if(iOpen(NULL,0,3)>iClose(NULL,0,3)) int BarThreeDown=1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(BarOneDown==1&&BarTwoDown==1&&BarThreeUp==1&&halt2!=1&&Volume[1]>Volume[2]&&Volume[2]>Volume[3]){
int opensell1=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"sell",MagicNumber2,0,Red);
}
if(BarOneDown==1&&BarTwoDown==1&&BarThreeUp==1){CloseAllSellTrades();}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------
return(0);
}
//+------------------------------------------------------------------+
void CloseAllSellTrades() {
for (int i = OrdersTotal() - 1; i >= 0; i--) {
int closesell = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumber2))
if (OrderType() == OP_SELL)
// OrderClose( OrderTicket(), OrderLots(), Ask, SlippageClose);
{
RefreshRates();
for(int try = 1; try <= 2; try++)
if (!OrderClose( OrderTicket(), OrderLots(), Ask, Slippage))
{ Print("Îøèáêà ", GetLastError());
Print("Íå óäàëîñü çàêðûòü îðäåð, ïîïûòêà ", try);
Sleep(1000);
RefreshRates();
}
else
break;
}
}
}