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

 
Artyom Trishkin:

Problem code.

Why...? If it's about doubling the logic for every such crossing of the same line, then of course all the logic (which I didn't write) should be written directly by the person. I don't know his ultimate goal, maybe he wants to make a count of how many times price crosses each line, as long as it passes it...

I understood that the man did not manage to get such an event for his purposes. Now he will get such an event, and then it's up to his discretion.


It would be logical to rename the line itself to a certain format at the first crossing (or put some label in the description of this figure). And when all objects are crossed, check the line for absence of this mark.

If we are talking about ineffectiveness of trying all objects every tick, then it is another topic altogether.

 
Roman:

Try to use value returned by _Period variable for periods higher than H1 in your math calcul ations.
Then you will immediately know who is wrong.

No one in their right mind would use the values of named constants for mathematical calculations. Named constants are there to make it easier for you to understand what you are referring to, or which property identifier you are using to retrieve the data. Named constants replace the value of the requested property identifier with a textual description.

When fetching data from e.g. SymbolInfoDouble(), you can use the numeric value of the identifier to indicate which value you want to fetch from the function. But to do this, you have to remember which identifier value to substitute in the function. Named enum constants were introduced to release you from constant reference or to prevent you from memorizing by heart the value of each identifier of each function in MQL. To get the value of the current Ask price, you should either write the identifier value equal to 4 when requesting data for the current symbol: SymbolInfoDouble(NULL,4) or write SymbolInfoDouble(NULL,SYMBOL_ASK);

Why is it OK with you, and does not cause dissonance, that SYMBOL_ASK returns 4 and not the current Ask price?

Why are you picking on the chart period identifiers then? That's what the developers wanted. For their internal reasons. There is an identifier name for you, for example PERIOD_H4. You should not care what numerical value was assigned to it by the developer for some reason or other. You have been given a name (text replacement of a numeric value) of a constant - use it for your convenience. But to use the value of this constant in your calculations is, sorry, nonsense. This named constant is used to indicate from which graph you want to get the data. But it does not return the period of the graph. It's used for a damn different purpose - to make your life easier, to tell the function what it should return.

If you want the number of minutes in the period, get it from the number of seconds in the period divided by 60. And don't call something that isn't a crutch. Crutches are what you're doing - trying to use number names in your calculations.

That's a bummer...

 
Vadim Lin:

Why...? If it's about doubling the logic for every such crossing of the same line, then of course all the logic (which I didn't write) should be written directly by the person. I don't know his ultimate goal, maybe he wants to make a count of how many times price crosses each line, as long as it passes it...

I understood that the man did not manage to get such an event for his purposes. Now he will get such an event, and then it's up to his discretion.


It would be logical to rename the line itself to a certain format at the first crossing (or put some label in the description of this figure). And when all objects are crossed, check the line for absence of this mark.

If we are talking about ineffectiveness of trying all objects every tick, that's another topic.

You are using ancient functions that are about to vanish into oblivion. The code is not crossplatform because of that, though you could easily make it work on any platform without changes.

And renaming is a lot of fun. You just need to look at the names of the lines given out by the indicator, extract the explicit identifier from them and use it to find the right lines.

 
Vadim Lin:

Thank you very much! It waswchar_t that helped! I read about it, it stores 2 bytes per character, unlike char.

But the "str" function parameter still doesn't return the value assigned to it... I wonder why...

Probably because you have to return the return value from the function.

extern "C" __declspec(dllexport) wchar_t* __stdcall ToString(wchar_t* str)
{
   wchar_t wcs[256];
   wcscpy(wcs, str);

   wchar_t* addStr = L" --- Привет! ---";
   
   wchar_t* res = wcsncat(wcs, addStr, wcslen(addStr) + 1);
   
   return(res);
}
 
Artyom Trishkin:

You are using ancient functions that are about to fade into oblivion. And the code is not crossplatform, although you could easily make it work on any platform without changes.

And renaming is a lot of fun. You just need to look at the names of the lines in the indicator, extract the explicit identifier and use it to find the necessary lines.

Thanks for the edit!

Indeed, I've been programming in MQL4 relatively rarely, while I've hardly used MQL5. Therefore I admit, that some methods are outdated (but I'm working anyway!).

Нужно просто поглядеть какие имена линий выдаёт индикатор, вычленить из них их явный идентификатор

Definitely, but not you or me - we don't know the naming peculiarities of those lines. "Memorizing" such levels is also an option, but then the results of our "memorizations" would have to be saved somewhere in a file, and without that - with any collapse of the terminal the picture of what is going on would be quite unclear. Renaming, at least, will solve this problem, although this method may not be the best.

I could be wrong, but the person wrote that up to 100 lines are used at a time, and only lines, and there is nothing else on the chart. All lines, as I understand it, need to be monitored for crossovers. So what you are going to "extract" from the names, I don't know))

 
Artyom Trishkin:


The point is that the _Period variable should return timeframe values.
And the constants must correspond to period values, not just enum constants.
Otherwise we lose the meaning of this variable, which is specially designed to quickly get the timeframe value, without conversion by additional functions.

 
Vadim Lin:

Thanks for the edit!

Indeed, I've been programming in MQL4 relatively rarely over the last few years, and I've hardly used MQL5. Therefore, I admit that some methods are outdated (but I'm working anyway!).

Definitely, but not you or me - we don't know the naming peculiarities of those lines. "Memorizing" such levels is also an option, but then the results of our "memorizing" would have to be saved somewhere in a file, and without it - with any collapse of the terminal the picture of what is going on would be quite unclear. Renaming, at least, will solve this problem, although this method may not be the best.

I could be wrong, but the person wrote that up to 100 lines are used at a time, and only lines, and there is nothing else on the chart. All lines, as I understand it, need to be monitored for crossovers. So what you will be "picking out" from the names, I don't know))

If the terminal crashes, it will have to be restarted. The indicator will have to be applied to chart again, or to run Expert Advisor that uses data of this indicator (in this case, the Expert Advisor will load this indicator itself when accessing it). In this case (and even at normal restart of the terminal with an automatic loading of programs installed on the chart), the indicator will draw all of its lines anew - there is no need to save anything. These lines can be re-read later. Moreover, they have to be read anyway.

For the EA to monitor only lines created by the indicator, it is enough to look at names of lines created by the indicator and try to find the repeating substring in names - the same for all lines. These substring are used to find the necessary lines.

It's simple - just look at the list of objects when the indicator is running.

 
Roman:

The point is that the _Period variable must return timeframe values.
And the constants must correspond to period values, not just enum constants.
Otherwise we lose the meaning of this variable, which is specially designed to quickly get the timeframe value, without conversion by additional functions.

You've got people and horses mixed up everywhere... Not just on this issue. If you make changes according to your suggestions, half of everything that has worked so far will simply die.

Just equating a tick size with a point size is worth of nothing...

 
Roman:

Try to use the value returned by the _Period variable for periods higher than H1 in your mathematical calculations.
You will immediately see who is wrong.

I use it in almost every EA. It's not funny anymore. I'm sorry, this is the first time I've seen this.
 
Artyom Trishkin:

You've got people and horses mixed up everywhere... Not just on this issue. If you make changes according to your suggestions, half of everything hitherto working will simply die out.

Just equating the size of a tick with the size of a point...

Because there's a lot of inconsistency with the current reality.
And you are trying to find excuses for those inconsistencies.
On the contrary, I wrote that a tick is not equal to a point!
It's your own internal, invented point.
In view of the fact that Point used to correspond exactly to a point, when there was only a four digit.
But after the introduction of the fifth digit, you started making up names with your excuses.