Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 726

 
Igor Petrov:

Thank you very much !!!

Could you please tell me if this (CHARTEVENT_CLICK) can be used when testing an EA?
 
Yuriy Vins:
Please tell me if this (CHARTEVENT_CLICK) can be used when testing an EA?

Alas, no.

 
ukrop1203:

I downloaded the data from MetaQuotes Software Corp in the "History Center" menu, what does the broker's data have to do with it?

Who downloaded the terminal from, that's where the data is pulled into MT4. And more precisely, and most likely - whose account you are logged in at the moment of downloading, it pulls the history from there.

 
Vladimir Baskakov:
What are you saying?

That people like you should be stripped of your status as a salesman. Go be an apprentice sanitation worker.

 
Andrei Novichkov:

That people like you should be stripped of your status as a Salesman. Go be an apprentice sanitation worker.

Have a nice day.
 

Hi all,

I put a close orders button in the EA, but it closes all orders in the terminal. I just need it on the current chart. Can you please help?

//----------------------------------------------------------------------
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---            
   if(sparam== "CloseButton")
      {
      CloseAllOpenPositions(MaxSlippage); 
      ObjectSetInteger(0,"CloseButton",OBJPROP_STATE,false);    
      }   
      if(sparam== "CloseBuy")
      {
      CloseAllBuy(MaxSlippage); 
      ObjectSetInteger(0,"CloseBuy",OBJPROP_STATE,false);    
      }         
         if(sparam== "CloseSell")
      {
      CloseAllSell(MaxSlippage); 
      ObjectSetInteger(0,"CloseSell",OBJPROP_STATE,false);    
      }         
//---      
  }
  
//+------------------------------------------------------------------+
void CloseAllOpenPositions(int intMaxSlippage)
  {
   bool checkOrderClose = true;        
   int index = OrdersTotal()-1;   
   while (index >=0 && OrderSelect (index,SELECT_BY_POS,MODE_TRADES)==true)
      {
         
      if (OrderType()==OP_BUY || OrderType()==OP_SELL)
         {         
         checkOrderClose = OrderClose (OrderTicket(), OrderLots(), OrderClosePrice(), MaxSlippage, CLR_NONE); 
         
         if(checkOrderClose == false)
            {
            int errorCode = GetLastError();
            
            if (errorCode == 1 || errorCode == 2 || errorCode == 5 || errorCode == 6 || errorCode == 64 || errorCode == 65 || errorCode == 132 || errorCode == 133 || errorCode == 139) break;
            else continue;        
            }          
         }           
      index--;
     }     
  }
  //----------------------------------------------------------------------------
 
Carcass77:

Hi all,

I put a close orders button in the EA, but it closes all orders in the terminal. I just need it on the current chart. Can you please help?

Replace the close function

//+------------------------------------------------------------------+
void CloseAllOpenPositions(int intMaxSlippage)
  {
   bool checkOrderClose=true;
   int index=OrdersTotal()-1;
   while(index>=0 && OrderSelect(index,SELECT_BY_POS,MODE_TRADES)==true)
     {
      if(OrderSymbol()==Symbol())   //Добавил  
        {

         if(OrderType()==OP_BUY || OrderType()==OP_SELL)
           {
            checkOrderClose=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),intMaxSlippage,CLR_NONE);

            if(checkOrderClose==false)
              {
               int errorCode=GetLastError();

               if(errorCode==1 || errorCode==2 || errorCode==5 || errorCode==6 || errorCode==64 || errorCode==65 || errorCode==132 || 
                errorCode==133||errorCode==139) break;
               else continue;
              }
           }

        }
      index--;
     }
  }
//+------------------------------------------------------------------+
 
Alekseu Fedotov:

Replace the closing function

It's working. Thank you very much.

 
Also, wanted to add a multiplier function for the step with each trade. Any tips?
 
Carcass77:
Also, wanted to add a multiplier function for the step with each trade. Any tips?

If it is a question of increasing the lot size of a new order relative to the maximum lot size of already open orders, then when counting orders, remember the maximum lot size of orders

like this:

//_______________________________________________________________________
//возвращает суммарное кол-во открытых рыночных ордеров, в переменных
// lotmaxbuy_ и lotmaxsell_ вернет максимальные лоты по типам ордеров
int NumberOfOrders(int magic_,double &lotmaxbuy_,double &lotmaxsell_)
  {
   int i,ot,buy_=0,sell_=0,k=OrdersTotal();
   lotmaxbuy_=0.0; lotmaxsell_=0.0;
   for(i=0; i<k; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         ot=OrderType();
         if((OrderMagicNumber()==magic_) && (OrderSymbol()==_Symbol))
           {
            if(ot==OP_BUY) { buy_++;  lotmaxbuy_  = fmax(lotmaxbuy_,OrderLots());  }
            if(ot==OP_SELL){ sell_++; lotmaxsell_ = fmax(lotmaxsell_,OrderLots()); }
           }
        }
     }
   return(buy_+sell_);
  }
//+------------------------------------------------------------------+