[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 571

 
I think I've fixed it.
Files:
 
Not that one)) that one. That one makes more sense.
Files:
sellbuy_2.mq4  3 kb
 
check out the second advisor, maybe it will give you some ideas..... has been composing all night tonight :)
 
Frostr:
check out the second advisor, maybe it will give you some ideas..... has been composing all night tonight :)

i got this. try it.
//+------------------------------------------------------------------+
extern int    stoploss   = 0,          // уровень выставления SL, если 0, то SL не выставляется
              takeprofit = 0,          // уровень выставления TP, если 0, то TP не выставляется
              Magic      = 123456;     // уникальный номер ордера
extern double Lot        = 0.1;        // объем ордера
extern int    slippage   = 3;          // Максимально допустимое отклонение цены для рыночных ордеров
extern int    MaxOrders  = 3;          // Максимально допустимое количество ордеров BUY или SELL
extern int    CycleCount = 5;          // количество попыток открытия ордера
//+------------------------------------------------------------------+
double SL,TP;
int    Count,Total,LastTotal;
string ord;
//+------------------------------------------------------------------+
int start()
   {
   Total=fTotal();
   if(Total==LastTotal&&LastTotal!=0)return(0);
   int Buy,Sell;
   if(Count==0)
      {
      MathSrand(TimeLocal()); 
      if(NormalizeDouble(MathMod(MathRand(),2),0)==0)ord="Buy";else ord="Sell";
   } 
   if(ord=="Buy")OrdCount("Buy");
   if(ord=="Sell")OrdCount("Sell");
   if(Count>=MaxOrders)return(0);
   if(ord=="Buy")
      {
      if(takeprofit!=0)TP=NormalizeDouble(Ask+takeprofit*Point,Digits);else TP=0;
      if(stoploss!=0)SL=NormalizeDouble(Ask-stoploss*Point,Digits);else SL=0;
      OPENORDER("Buy");
      if(takeprofit!=0)TP=NormalizeDouble(Bid-takeprofit*Point,Digits);else TP=0;
      if(stoploss!=0)SL=NormalizeDouble(Bid+stoploss*Point,Digits);else SL=0;
      OPENORDER("Sell");
   }
   if(ord=="Sell")
      {
      if(takeprofit!=0)TP=NormalizeDouble(Bid-takeprofit*Point,Digits);else TP=0;
      if(stoploss!=0)SL=NormalizeDouble(Bid+stoploss*Point,Digits);else SL=0;
      OPENORDER("Sell");
      if(takeprofit!=0)TP=NormalizeDouble(Ask+takeprofit*Point,Digits);else TP=0;
      if(stoploss!=0)SL=NormalizeDouble(Ask-stoploss*Point,Digits);else SL=0;
      OPENORDER("Buy");
   }
   LastTotal=fTotal();
   return(0);
}
//+------------------------------------------------------------------+
void OPENORDER(string ord)
   {
   int error,err;
   while(true)
      { 
      error=-1;
      if(ord=="Buy" )error=OrderSend(Symbol(),OP_BUY, Lot,NormalizeDouble(Ask,Digits),slippage,SL,TP,"BUY",Magic,0,Blue);
      if(ord=="Sell")error=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,SL,TP,"SELL",Magic,0,Red);
      if(error==-1) //неудачная покупка OK
         { 
         ShowERROR();err++;Sleep(2000);RefreshRates();
      }
      if (err>=CycleCount)break;
   }
   return;
} 
//+------------------------------------------------------------------+
void ShowERROR()
   {
   int err=GetLastError();
   switch(err)
      { 
      case 1   : return;
      case 2   : Alert("Нет связи с торговым сервером ",Symbol());return;
      case 3   : Alert("Error неправильные параметры ",Symbol());return;
      case 130 : Alert("Error близкие стопы Ticket ",Symbol());return;
      case 134 : Alert("Недостаточно денег ",Symbol());return;
      case 146 : Alert("Error Подсистема торговли занята ",Symbol());return;
      case 129 : Alert("Error Неправильная цена ",Symbol());return;
      case 131 : Alert("Error Неправильный объем ",Symbol());return;
      case 4200: Alert("Error Объект уже существует ",Symbol());return;
      default  : Alert("Error " ,err," ",Symbol());return;
   }
}
//+------------------------------------------------------------------+
int fTotal()
   {
   int Tot=OrdersTotal();
   int BuyCount=0,SellCount=0;
   if(Tot>0)
      {
      for(int i=0;i<OrdersTotal();i++)
         {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
            {
            if(OrderSymbol()==Symbol()&&(Magic==0||OrderMagicNumber()==Magic))
               {
               switch (OrderType())
                  {
                  case OP_BUY :BuyCount++; break;
                  case OP_SELL:SellCount++;break;
               }
            }
         }
      }
   }
   return(BuyCount+SellCount);
}
//+------------------------------------------------------------------+
int OrdCount(string ord)
   {
   int Type;Count=0;
   if(ord=="Buy")Type=OP_BUY;
   if(ord=="Sell")Type=OP_SELL;
   for(int i=0;i<OrdersTotal();i++)
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
         {
         if(OrderSymbol()==Symbol())
            {
            if(OrderType()==Type)
               {
               if(Magic==0||OrderMagicNumber()==Magic)Count++;
            }
         }
      }
   }
   return(Count);
}
//+------------------------------------------------------------------+
 
I have it opening 500 orders or 1000 how to reduce?
 
Frostr:
I have it opening 500 orders or 1000 how to reduce?

Who is he?
 
rigonich:

Who is he?



Councillor )

 
Frostr:



Advisor )


Clearly an advisor, but which one?
 

I put your data into the Expert Advisor and ran it )

Was that not the right way to do it?

 
file://localhost/C:/Users/mv/Desktop/StrategyTester.htm