[Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate oltre. Da nessuna parte senza di te - 4. - pagina 570

 
Non quello)) quello. Quello ha più senso
File:
sellbuy_2.mq4  3 kb
 
guarda il secondo consigliere, forse ti darà qualche idea..... ha composto tutta la notte :)
 
Frostr:
guarda il secondo consigliere, forse ti darà qualche idea..... ha composto tutta la notte :)

Ce l'ho, provalo.
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
 
Ho aperto 500 ordini o 1000 come ridurre?
 
Frostr:
Ho aperto 500 ordini o 1000 come ridurre?

Chi è?
 
rigonich:

Chi è?



Consigliere )

 
Frostr:



Consigliere )


Chiaramente un consigliere, ma quale?
 

Ho messo i tuoi dati nell'Expert Advisor e l'ho eseguito)

Non era questo il modo giusto per farlo?

 
file://localhost/C:/Utenti/mv/Desktop/StrategyTester.htm
 
Frostr:

Ho messo i tuoi dati nell'Expert Advisor e l'ho fatto funzionare)

Non era questo il modo giusto per farlo?


Non capisco che tipo di dati? Ti ho appena dato il codice EA. compilalo ed eseguilo, basta dargli un nome. Non l'ho testato, l'ho solo ricompilato come è venuto fuori e l'ho messo fuori. Se non funziona correttamente, fatemelo sapere e cercherò di capire perché.