Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1307

 
Hello!

I transferred an indicator from MQL4 to MQL5 and cannot understand why it does not work:

void GetDellName(string name_n = " ")
  {
   string vName;
   for(int i=ObjectsTotal()-1; i>=0; i--)
     {
      vName = ObjectName(i);
      if(StringFind(vName,name_n) !=-1)
         ObjectDelete(vName);
     }
  }

MetaEditor in MQL5 complains about:


'ObjectsTotal' - wrong parameters count

'ObjectName' - wrong parameters count

ObjectDelete' - wrong parameters count

Everything works in MQL4 with no errors.

Please help me understand

 
Sprut 185:
Hello!

I transferred an indicator from MQL4 to MQL5 and cannot understand why it does not work:


MetaEditor in MQL5 complains about:


'ObjectsTotal' - wrong parameters count

'ObjectName' - wrong parameters count

ObjectDelete' - wrong parameters count

Everything works in MQL4 with no errors.

Please help me to understand

1. Please paste the code correctly. When you edit your message, press the button Code and paste the code in the popup window that appears (I edited your message for the first time).

2. Read the help carefully. For exampleObjectsTotal

int  ObjectsTotal(
   long  chart_id,           // идентификатор графика
   int   sub_window=-1,      // индекс окна
   int   type=-1             // тип объекта     
   );
Документация по MQL5: Графические объекты / ObjectsTotal
Документация по MQL5: Графические объекты / ObjectsTotal
  • www.mql5.com
ObjectsTotal - Графические объекты - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Sprut 185:

how about this? - removes all horizontal and trend lines

//+------------------------------------------------------------------+
//|                                                  GetDellName.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   GetDellName();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetDellName(void)
  {
   int nHLines=ObjectsTotal(0,-1,OBJ_HLINE),
       nTrendLines=ObjectsTotal(0,-1,OBJ_TREND),i;
   string objName;
   for(i=0; i<nHLines; i++)
     {
      objName=ObjectName(0,i,0,OBJ_HLINE);
      ObjectDelete(0,objName);
     }
   for(i=0; i<nTrendLines; i++)
     {
      objName=ObjectName(0,i,0,OBJ_TREND);
      ObjectDelete(0,objName);
     }
   return(GetDellName());
  }
//+------------------------------------------------------------------+

-----------------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\------------------------------------------------------

or it removes all objects like this

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetDellName(void)
  {
   int ObjectsName=ObjectsTotal(0,-1,-1),i;
   string objName;
   for(i=0; i<ObjectsName; i++)
     {
      objName=ObjectName(0,i,0,-1);
      ObjectDelete(0,objName);
     }
   return(GetDellName());
  }
//+------------------------------------------------------------------+

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

or like this - as Alexey Viktorov says.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetDellName(void)
  {
   ObjectsDeleteAll(0,-1,-1);
//--- "clear" comment
   Comment("");
   return(false);
  }
//+------------------------------------------------------------------+
 
SanAlex:

how about this? - removes all horizontal and trend lines

Why is there a cycle?

int  ObjectsDeleteAll(
   long  chart_id,            // идентификатор графика
   int   sub_window=-1,       // индекс окна
   int   type=-1              // тип объекта для удаления
   );
 
Alexey Viktorov:

Why is there a cycle here???

honestly!? - I have no idea! - Just something to occupy myself with in the morning.

 
SanAlex:

how about this? - removes all horizontal and trend lines

-----------------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\------------------------------------------------------

or it removes all objects like this

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

or like Alexey Viktorov says.

it can also go like this

//+------------------------------------------------------------------+
//|                                                  GetDellName.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

string   m_name[]= {"1 имя объекта","2 имя объекта","3 имя объекта","4 имя объекта","5 имя объекта","6 имя объекта"};
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   GetDellName();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetDellName(void)
  {
   for(int i=0; i<ArraySize(m_name); i++)
     {
      ObjectDelete(0,m_name[i]);
     }
   return(false);
  }
//+------------------------------------------------------------------+

or like this

//+------------------------------------------------------------------+
//|                                                     FILTER_1.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
sinput string InpName_1 = "HorizontalTrend Line_1"; // FILTER_1
sinput string InpName   = "HorizontalTrend Line";   // FILTER
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//---
   EventSetMillisecondTimer(1);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   EventKillTimer();
   GetDellName("");
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(void)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTimer(void)
  {
   MqlRates rates[],rates_1[];
   int start_pos=0,count=1;
   if(CopyRates(Symbol(),Period(),start_pos,count,rates)!=count)
     {
      return;
     }
   if(CopyRates(Symbol(),Period(),start_pos,count,rates_1)!=count)
     {
      return;
     }
//---
   double price_line=0.0;
   if(ObjectFind(0,InpName)>=0)
     {
      long object_type=ObjectGetInteger(0,InpName,OBJPROP_TYPE);
      if(object_type==OBJ_HLINE)
         price_line=ObjectGetDouble(0,InpName,OBJPROP_PRICE);
      else
         if(object_type==OBJ_TREND)
            price_line=ObjectGetValueByTime(0,InpName,rates[0].time,0);
      if(price_line>0.0)
        {
         if(rates[0].open<price_line)
           {
            Alert("1");
            GetDellName(InpName);
           }
        }
     }
//---
   double price_line_1=0.0;
   if(ObjectFind(0,InpName_1)>=0)
     {
      long object_type_1=ObjectGetInteger(0,InpName_1,OBJPROP_TYPE);
      if(object_type_1==OBJ_HLINE)
         price_line_1=ObjectGetDouble(0,InpName_1,OBJPROP_PRICE);
      else
         if(object_type_1==OBJ_TREND)
            price_line_1=ObjectGetValueByTime(0,InpName_1,rates_1[0].time,0);
      if(price_line_1>0.0)
        {
         if(rates_1[0].open>price_line_1)
           {
            Alert("2");
            GetDellName(InpName_1);
           }
        }
     }
//---
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetDellName(string objName)
  {
   int nHLines=ObjectsTotal(0,-1,OBJ_HLINE),
       nTrendLines=ObjectsTotal(0,-1,OBJ_TREND),i;
   for(i=0; i<nHLines; i++)
     {
      objName=ObjectName(0,i,0,OBJ_HLINE);
      ObjectDelete(0,objName);
     }
   for(i=0; i<nTrendLines; i++)
     {
      objName=ObjectName(0,i,0,OBJ_TREND);
      ObjectDelete(0,objName);
     }
   return(false);
  }
//+------------------------------------------------------------------+
 

Need help setting up MT5 .

1. Problem In MT5 I have switched to a DEMO account but the button to place orders is not active, at the bottom you can see that there is no connection with the server and contract tickers for 2019 and 2020 are loaded from your database into the list, but there are no actual contracts.

 
gorod258:
Need help setting up MT5 from scratch .

https://www.metatrader5.com/ru/terminal/help/startworking/settings

Настройки платформы - Начало работы - Справка по MetaTrader 5
Настройки платформы - Начало работы - Справка по MetaTrader 5
  • www.metatrader5.com
Торговая платформа обладает множеством настроек, что позволяет организовать работу в ней так, как это удобно именно вам. Выполните команду...
 

I pre-set it, but for some reason part of the function doesn't work .

1. Problem In MT5 I have switched to a DEMO account but the button to place orders is not active, you can see at the bottom that there is no connection with the server and the contract tickers for 2019 and 2020 are loaded from your database into the list but there are no actual contracts.

Could you help ?

 
SanAlex:

honestly!? - I have no idea! - Just something to do in the morning.

Well, he'll delete it anyway, no strings attached.)

Reason: