Questions from Beginners MQL5 MT5 MetaTrader 5 - page 475

 
alph:
Can you tell me please, such a rate tester in real life? And is it good or bad result for the year with depo 3000$?

A strategy tester always lies, even though the simulation quality is 99.9%!

The only option to check the EA is to put it on a real-time VPN server on a demo account... Microsoft Azure gives almost a free server for a month, you need $1 to look it up on YouTube!...There are other VPN services, but they have 10 days maximum of free use.

 

Guys! Is it possible to programmatically prohibit manual trading in an EA?

 

Can you please tell me why this block removes all pending stop orders on any symbols set in the terminal, ignoring magic and _Symbol?

//--------------------------------------------------------------------------------------------------------------
//       Блок удаления отложенников по типу ордера
//--------------------------------------------------------------------------------------------------------------
int dell_ord_by_type(int type_ord, int _magic)
{   
   bool ticketmdf;
   int j;
  
   int orders=OrdersTotal();
   for(int i=0;i<orders;i++)//--- пробежим по списку ордеров
   {     
         if( OrderGetString(ORDER_SYMBOL) ==Symbol() && OrderGetInteger(ORDER_MAGIC)==_magic && OrderGetInteger(ORDER_TYPE) ==type_ord)   
         {  
            if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_STOP || OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_STOP)
            {       
               for(j=Appempts; j>0; j--) 
               { 
               //----------------------------------------------------------------------
               MqlTradeResult result={0}; 
            MqlTradeRequest request={0};
            request.order=OrderGetTicket(i);
            request.symbol = _Symbol;
            request.magic = _magic;
            request.action=TRADE_ACTION_REMOVE;
            ticketmdf=OrderSend(request,result);
            
                  if(ticketmdf==true)
                  {
                     Print("Успешно удалён ордер");
                     Sleep(2000);
                     break;                    
                  }
                  if(ticketmdf==false)                     
                  {
                     Print("Ошибка при удалении ордера # ",+GetLastError());
                     Sleep(7000);
                  }
               }                            
            }                       
         }                        
   }
   return(true);  
}
 
Aleksandr Prishenko:

Can you please tell me why this block removes all pending stop orders on any symbols set in the terminal, ignoring magic and _Symbol?

1. the order has to be selected first;

2. The loop should be built from the last order, i.e. for( i = orders-1; i >= 0; i-- )

 
Aleksandr Prishenko:

Can you tell me why this unit deletes all pending stop orders on any symbols set in the terminal, ignoring magic and _Symbol?

I need to select the orders:

...
   int orders=OrdersTotal();
   for(int i=0;i<orders;i++)//--- пробежим по списку ордеров
     {
      if(OrderSelect(ххх,ххх,хххх)==true)
        {
         if(OrderGetString(ORDER_SYMBOL)==Symbol() && OrderGetInteger(ORDER_MAGIC)==_magic && OrderGetInteger(ORDER_TYPE)==type_ord)
           {
...
 
Vladimir Tkach:

Guys! Is it possible to programmatically prohibit manual trading in an EA?

Of course not.
 
Karputov Vladimir:

You have to choose your orders:

The statement is correct. The implementation is not correct. Where do you get the ticket for OrderSelect()?
 

Is this the right thing to do?

Alexey Kozitsyn andKarputov Vladimir thanks for the tips!

int dell_ord_by_type(int type_ord, int _magic)
{   
   bool ticketmdf;
   int j;
 int orders=OrdersTotal();
   for(int i=0;i<orders;i++)//--- пробежим по списку ордеров
   { 
   ResetLastError();    
  ulong ticket=OrderGetTicket(i);
      if(ticket!=0)// если ордер успешно скопирован в кэш, работаем с ним  

      {      
         if( OrderGetString(ORDER_SYMBOL) ==_Symbol && OrderGetInteger(ORDER_MAGIC)==_magic && OrderGetInteger(ORDER_TYPE) ==type_ord)   
         {  
            if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_STOP || OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_STOP)
            {       
               for(j=Appempts; j>0; j--)
               { 
 

You have written above: when orders are deleted, the cycle must be reversed. When an order is deleted, the indexes of the remaining orders are shifted.

int dell_ord_by_type(int type_ord, int _magic)
{
   ulong nOrderTicket = 0;
   
   for(int i = OrdersTotal() - 1; i >= 0; i--)   //--- пробежим по списку ордеров
   {
      nOrderTicket = OrderGetTicket(i);
        
      if(nOrderTicket > 0 && OrderGetString(ORDER_SYMBOL) == Symbol() && OrderGetInteger(ORDER_MAGIC) == _magic && OrderGetInteger(ORDER_TYPE) == type_ord)   
      {  
         if(OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_STOP || OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_STOP)
         {       
            // удаляем
         }
      }
   }
        
   return(0);  
}
 
By the way, why do you declare a function as int if it returns true in your version, and always? )