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

 

Mixing Boolean and other conditions into one pile... OK. If you don't want to write good code, don't write it. I won't try to persuade you and argue with you.

MakarFX #:

And if we're talking about universality of the function, well...

Well, it's closer to common sense than your previous function.

True, the readability leaves a lot to be desired... But who ever thinks about it...? :)

 
Nerd Trader #:
The one that by convention is true

no, "line_name" will have the last name assigned to it.

 
Mihail Matkovskij #:

Mixing Boolean and other conditions into one pile... OK. If you don't want to write good code, don't write it. I'm not going to persuade or argue with you.

Okay, okay, I'll use your example.

 
There is no need to create and delete lines all the time. There are volume visibility flags on the timeframes. Need to hide and display.
 
Mihail Matkovskij #:

Mixing Boolean and other conditions into one pile... OK. If you don't want to write good code, don't write it. I won't persuade you and argue with you.

Well, it's closer to common sense than your previous function.

True, the readability leaves a lot to be desired... But who ever thinks of that...? :)

Specifically, what's wrong?

And you still haven't answered what your function returns at "-1"...

 
MakarFX #:

no, "line_name" will have the last name assigned to it.

Yeah, why would there be a problem with that? The object that passes the condition will be deleted anyway.
 
MakarFX #:

Specifically, what's wrong?

And you still haven't answered what your function will return at "-1".

it'll return false - I already checked.
 
Nerd Trader #:
it will return false - I've already checked
It should return true.
 
MakarFX #:
It has to be true.
With a logical NOT, it will be true :)
 
MakarFX #:

Specifically, what's wrong?

bool FindObject(string name, int win)
{
   if(ObjectFind(0, name) == win) 
     return(true);
   return(false);
}
A more compact version:
bool FindObject(string name,int win) { return (ObjectFind(0,name) == win); } 

But I thought you said your function claimed to be universal...? Then you forgot one very important detail:

bool FindObject(const long chart_id, const string name, const int win) { return (ObjectFind(chart_id, name) == win); } 

The most universal and reliable option.

And you never answered what your function will return "-1".

Are you too lazy to write a simple script to check? Okay. I did it for you:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {
  for (int i = -10; i <= 10; i++) 
    if (i)
      printf("%d - true", i);
    else
      printf("%d - false", i);
}
//+------------------------------------------------------------------+

And now look at the result:

-10 is true.

-9 is true.

-8 is true.

-7 - true

-6 - true

-5 - true

-4 - true

-3 - true

-2 - true

-1 - true

0 - false

1 - true

2 - true

3 - true

4 - true

5 - true

6 - true

7 - true

8 - true

9 - true

10 - true



All negative numbers are true. 0 is false. That's how it works... :)

So, your function will return true.

Forum on trading, automated trading systems & strategy testing

Any questions from newbies on MQL4 and MQL5, or any tips and discussion on algorithms and codes

MakarFX, 2021.12.06 12:14

bool FindObject(string name)
  {
   if(ObjectFind(0,name)) return(false);
   return(true);
  }

Mine will return false

bool objectExist(const long _chartID, const string _name) { return(ObjectFind(_chartID, _name) >= 0); } // чётко определим условие существования объекта!

As it should with negative values.