Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1001

 

Can you please tell me why I'm getting errors

2019.02.17 06:13:28.974 Test_4G_CB (Si Splice,H1)       1 Тут ошибка 4202 Графический объект не найден
2019.02.17 06:13:28.983 Test_4G_CB (Si Splice,H1)       2 Тут ошибка 4202 Графический объект не найден

in this code

      if(ObjectFind(chart,name)<0)
        {
         Print("1 Тут ошибка ",GetLastError()," ",cLng::CodeDescription(GetLastError()));
         ResetLastError();
         graphic.Create(chart,name,0,0,0,pix_X,pix_Y);//Создает графический ресурс, привязанный к объекту чарта 
         Print("2 Тут ошибка ",GetLastError()," ",cLng::CodeDescription(GetLastError()));
         ResetLastError();
        }

If the first error is still understandable - an object is not found, but the implementation of the search for a missing object without an error is not clear, the second error is not clear, while the object is clearly created - the chart is formed and the reason for the error is not clear.

How to get rid of errors?

 
Aleksey Vyazmikin:

Can you please tell me why I'm getting errors

in this code

If the first error is still understandable - an object is not found, but the implementation of the search for a missing object without an error is not clear, the second error is not clear, while the object is clearly created - the chart is formed and the reason for the error is not clear.

How to get rid of the error?

ResetLastError() must be done before calling the function. What is it here:

graphic.Create()

is unclear. If this is CCanvas, then the Create() method creates a graphical resource without reference to the chart object. And it returns either true or false:

Create

Creates a graphical resource without binding to a chart object.

virtual bool  Create(
   const string       name,                                 // имя
   const int          width,                                // ширина
   const int          height,                               // высота
   ENUM_COLOR_FORMAT  clrfmt=COLOR_FORMAT_XRGB_NOALPHA      // формат
   );

Parameters

name

[in] Base for the name of the graphical resource. The resource name is formed during creation by adding a pseudo-random string.

width

Width [in] Width (X size) in pixels.

height

[in] Height (Y-axis size) in pixels.

clrfmt=COLOR_FORMAT_XRGB_NOALPHA

[in] Color processing method. See the ResourceCreate() function description for more details on the colour handling methods.

The return value is

true - if successful, otherwise false


Generally, it's hard to understand from what you have shown.

But you can try it this way:

//+------------------------------------------------------------------+
ResetLastError();
if(ObjectFind(chart,name)<0)
  {
   Print("1 Тут ошибка потому, что объекта нет ещё",GetLastError()," ",cLng::CodeDescription(GetLastError()));
   ResetLastError();
   if(!graphic.Create(chart,name,0,0,0,pix_X,pix_Y))
      Print("2 Тут ошибка ",GetLastError()," ",cLng::CodeDescription(GetLastError()));
  }
//+------------------------------------------------------------------+

If you have CGraphic there, you need to get into the Create() code to understand what it returns, as there's not a word about it in the help:

Документация по MQL5: Стандартная библиотека / Научные графики / CGraphic / Create
Документация по MQL5: Стандартная библиотека / Научные графики / CGraphic / Create
  • www.mql5.com
Стандартная библиотека / Научные графики / CGraphic / Create - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Artyom Trishkin:

ResetLastError() must be performed before the function is called. What's here:

is unclear. If it's CCanvas, the Create() method creates a graphical resource without reference to a chart object. And it returns either true or false:

Create

Creates a graphical resource without binding to a chart object.

Parameters

name

[in] Base for the name of the graphical resource. The resource name is formed during creation by adding a pseudo-random string.

width

Width [in] Width (X size) in pixels.

height

[in] Height (Y-axis size) in pixels.

clrfmt=COLOR_FORMAT_XRGB_NOALPHA

[in] Color processing method. See the ResourceCreate() function description for more details on the colour handling methods.

The return value is

true - if successful, otherwise false


Generally, it's hard to understand from what you have shown.

But you can try it this way:

If you have CGraphic there, you need to get into Create() code to understand what it returns, as there's not a word about it in the help:

I have already checked above with error reset and localized the place where the error occurs.

Besides, it occurs twice from different functions there - after the first function the error is cleared, but then it occurs again.

And my variant of creation

Create

Creates a graphical resource linked to the chart object.

bool Create (
const longchart,// chart ID
const stringname,//name
const intsubwin,// number of subwindow
const intx1,//coordinate x1
const inty1,//coordinate y1
const intx2,//coordinate x2
const inty2//coordinate y1
)

Parameters

chart

The [in] identifier of the chart.

name

[in] Name.

subwin

[Subwindow number.

x1

[Coordinate X1.

y1

[in] Coordinate Y1.

x2

[in] Coordinate X2.

y2

[in] Coordinate Y2.

 
Aleksey Vyazmikin:

I have already checked above with an error reset and localised where the error occurs

You do not reset the error before accessing the object search function.

 
Artyom Trishkin:

You don't reset the error before accessing the object search function.

Yes, in the code quote I don't reset, as I've already checked the code above - there's no error there, so I've erased similar check lines as shown below.

 
Hello, my alert function reads a string from a file and outputs it in either Chinese or Japanese characters, how can I fix it?
 
Artyom Trishkin:

You don't reset the error before calling the object search function.

Once again I decided to repeat the experiment, here is the code

      //--- отключим показ ценового графика
      ChartSetInteger(0,CHART_SHOW,false);
      long chart=ChartID();

      CGraphic graphic;
         Print("0 Тут ошибка ",GetLastError()," ",cLng::CodeDescription(GetLastError()));
         ResetLastError();
      if(ObjectFind(chart,name)<0)
        {
         Print("1 Тут ошибка ",GetLastError()," ",cLng::CodeDescription(GetLastError()));
         ResetLastError();
         graphic.Create(chart,name,0,0,0,pix_X,pix_Y);//Создает графический ресурс, привязанный к объекту чарта 
         Print("2 Тут ошибка ",GetLastError()," ",cLng::CodeDescription(GetLastError()));
         ResetLastError();
        }

Here is the result.

2019.02.17 08:55:19.845 Test_4G_CB (Si Splice,H1)       0 Тут ошибка 0 Операция выполнена успешно
2019.02.17 08:55:19.860 Test_4G_CB (Si Splice,H1)       1 Тут ошибка 4202 Графический объект не найден
2019.02.17 08:55:19.860 Test_4G_CB (Si Splice,H1)       2 Тут ошибка 4202 Графический объект не найден
Any idea what caused the error?
 
Denis Nikolaev:
Hello, my alert function reads a string from a file and outputs it in either Chinese or Japanese characters, how can I fix it?

Configure the fonts in Windows. Set Russian for "Language for programmes that do not support Unicode".

"Regional standards" - "Advanced".

 
Vladimir Karputov:

Configure the fonts in Windows. Set Russian for "Language for programmes that do not support Unicode".

"Regional Standards - Advanced.

This did not work.

I get an automatic translation to Japanese or Chinese of a line read from a file, why is this happening?

 
Aleksey Vyazmikin:

Once again I decided to repeat the experiment, here is the code

Here's the result

Any idea what caused the error?

Well, since you reset the last error, look in the wilds of CGraphic where this error code occurs.

Reason: