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

 
Priffekt:
Good afternoon, I have changed all the values, but I am interested in the possibility of disabling the function itself in the EA settings.

Good morning.

When you paste a piece of code, use the </> button, it will be much more readable, I wrote to you above that "it's better to attach this way".

In post 8518 I sent you your own code in which I've already added the switch. You just need to separate the first line to the incoming variables, the second line to OnTick.

 
Sergey Voytsekhovsky:

Of course, I am not very suitable for the role of advisor, but the task seems to be not difficult.

Please note that I didn't get into your code itself, there is a lot of controversy, even for me (dummies), starting with the fact that your function is of type void. This type is used either to indicate that the function does not return a value, or as a parameter of the function indicates the absence of parameters. And you have return(Exist) at the end of your code;

Declare an input variable, write it as a parameter for your function and exit the function if you set 'this variable to False.

The highlighted is absolutely wrong. No one forbids handling variables declared globally.

int n = 0;

int OnInit()
 {
  f();
 }

void OnTick()
 {
  Print(n);
  f();
 }

void f()
 {
  n += n*3+12;
 }
 
Priffekt:
Good afternoon, I have changed all the values, but I am interested in the possibility to disable the function itself in the EA settings.

If you want to be able to disable a function in EA settings, you have to set a variable flag

input bool flag = true; // флаг отключения

void OnTick()
 {
  if(flag)
   f();
 }

void f()
 {
  // что-то выполняем
 }
Function f() will be executed only if flag == true;
 
Alexey Viktorov:

This is absolutely incorrect. No one forbids processing of variables declared at the global level.

Strange, this is actually a quote from the MQL5 handbook, in full looks like this:

"The void type and the NULL constant.

Syntax void type is a fundamental type, along with the types char, uchar, bool, short, ushort, int, uint, color, long, ulong, datetime, float, double and string. This type is used either to indicate that the function does not return a value, or as a function parameter to indicate the absence of parameters.

A predefined constant variable NULL is of void type. It can be assigned to variables of any other fundamental types without transformation. It is also allowed to compare variables of fundamental types to NULL".


I quoted this fragment because the function in the author's text has the void type, i.e. it should not return anything but ".return(Exist);". Which probably is wrong, don't you think?

All the discussion of data handling was never even passed. I may be wrong somewhere, since I'm just learning the basics, but thanks for the information anyway.

 
 
 
Alekseu Fedotov:

"...return(Exist);" ,

return value, by function

like this

Yes, you're right, I was inattentive and attributed this return to the previous (above which) function.

 
Alexey Viktorov:

That's not what it's about... I just didn't read the highlighted one carefully.

Highlighted viod means no parameters. But you don't have to write it. No parameters, so don't...

Yes, you're right, I was inattentive too.

 

Question for the experts.

I'm trying to write an EA, found a script that suits my needs in terms of functionality. I want to make a function out of it, I'm preparing environment, of course there are intersections in standard libraries. I want to understand the difference between these entries and whether the sign " * " in itself any secret meaning, is it possible to rename them into a single type within the future functions?

CTrade         trade;
CPositionInfo  apos;
CSymbolInfo    asymbol;


CTrade         *m_trade;
CSymbolInfo    *m_symbol;
CPositionInfo  *m_position_info; 

 

Help, how do I find out the first time coordinate of the trend line?

price = NormalizeDouble(ObjectGetValueByShift("trend",0),Digits);//ЦЕНА НА ТЕКУЩЕМ
Reason: