Errors, bugs, questions - page 2458

 

When switching from MQL4 to MQL5 I encountered a glitch:

Code:

ResetLastError();

int ObjTotal = ObjectsTotal(0);

int Error = GetLastError();

returns:

ObjTotal = 0.

Error = 4022

What is this error and why it is not mentioned in the documentation?

I tried different variants: ObjectsTotal(0, -1, -1), ObjectsTotal(ChartID(), 0, OBJ_TREND), etc.

The result is the same.

How to make it work?

Terminal: MetaTrader 5, Version 5.00 build 2025.
 
Игорь Евдокимов:

Advice: If you want to ask something, insert the FULL code, not a piece of it.

What's the point: anyone takes your code and runs it on their own. And almost no one looks at chunky code - chunky code is disrespectful.

Example of your code:

//+------------------------------------------------------------------+
//|                                                            1.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   ResetLastError();
   int ObjTotal=ObjectsTotal(0);
   int Error=GetLastError();
   Print("ObjectsTotal: ",ObjTotal,", GetLastError: ",Error);
//---
  }
//+------------------------------------------------------------------+

Run it on a graph that doesn't have any graphical objects on it. Result:

2019.05.10 13:26:59.169 1 (EURUSD,H1)   ObjectsTotal: 0, GetLastError: 0

That is, there is no error.


Using the terminal:

2019.05.10 13:25:35.665 MetaTrader 5 x64 build 2025 started (MetaQuotes Software Corp.)
2019.05.10 13:25:35.668 Windows 10 (build 17763) x64, IE 11, UAC, Intel Core i3-3120 M  @ 2.50 GHz, Memory: 3712 / 8077 Mb, Disk: 77 / 415 Gb, GMT+2
2019.05.10 13:25:35.668 C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075
Files:
1.mq5  2 kb
 
Vladimir Karputov:

A word of advice: if you want to ask something, insert the FULL code, not a piece.

Thanks for the advice, that's what I'll do.

However, the question remains open.

Clarification: if the piece of code from the previous post is in the OnDeinit() function of the indicator, the result is this:

2019.05.10 14:08:20.105 PtS (EURUSD,H1) ObjectsTotal: 0, GetLastError: 4022

If you run the same code after deleting the indicator from the chart, like the script (1.mq5 from the previous post), we get

2019.05.10 14:08:33.609 1 (EURUSD,H1) ObjectsTotal: 8575, GetLastError: 0

Please help me to understand the reason.

Gentlemen developers! What is this error that is not in the documentation?

 
Vladislav Andruschenko :

error in strategy tester during optimisation.

" task rejected by tester agent "

For example if your account currency is EUR,

  • EURJPY No problem
  • Error at GBPJPY


If your account currency is USD

  • USDCAD No Problem
  • USDJPY No Problem
  • Error at EURAUD


appears when other currency pairs are used in the code.

In my example it's using calculation of dynamic lot



i.e. when EA is requesting price of another currency.

@Vladislav Andruschenko

Hi, did you get any answer or solution to this problem?

 
Vladimir Pastushak:

When the schedule/period is changed, PBB receives a value of 10, no matter what value you have specified in the input field.

At the moment of re-initialisation, it is as if it were the first run.

There are two ways to solve your problem

1 - Storing PBB value in global variables and get the period from there.

2 - When OnChartEvent triggers, reinitialize MA indicator and get a new handle...

Checked all options. It does not work.

Fault in MQL5.

It does not initialize new values. Only with parameter input int PBB_=. No other options. This is not good at all.

 
Uladzimir Izerski:

Checked all the options. Doesn't work.

Flaw in MQL5 program.

New values are not initialized. Only with input int PBB_= parameter. No other options. This is not good at all.

Everything is fine in MQL, you just don't understand what you are doing in your code and how everything works...

Once again, when you callChartSetSymbolPeriod(0,_Symbol,_Period);

You're resetting everything to default...

Alternatively, try the inite to request a value from your text field.

When you start indicator for the first time, everything is created and when you change data in the field, it will call new unity and set value from your text field...

 
Vladimir Pastushak:

Everything is fine in MQL, you just don't understand what you're doing in the code and how everything works...

Once again, when you callChartSetSymbolPeriod(0,_Symbol,_Period);

You're resetting everything to default...

Alternatively, try to query the value from your text field in the init.

After logic, the first start of the indicator, everything is created, but when you change data in the field, there will be a new call in the unity and value setting from your text field...

I tried it with the text field and through GlobalVariable, but I've never tried anything. It's as silent as in a tank.

In other variantOnCalculate works without problems.

 
Uladzimir Izerski:

I tried both from a text field and via GlobalVariable and whatever else I tried. It's as silent as a tank.

The other version of OnCalculate works without problems.

That means you are doing something wrong

 
When I accessed my account a window opens and says that I should not read the unprepared "rows", although it says that authorization allows connection to the account...What should I do?
 
Vladimir Pastushak:

Then you're doing something wrong.

You've already posted the code.

If I'm inept, someone must be a pro. I don't see it yet.

I accept your effort to find an answer. There's more to it than that. That is, at the level of the developers.