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

 

Forum on trading, automated trading systems & strategy testing

Any questions from newbies on MQL4 and MQL5, help and discussion on algorithms and codes

MakarFX, 2021.12.06 12:14

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

And in the case of an error, what will your function return, true?

 
Mihail Matkovskij #:

And in the event of an error, what will your function return, true?!

What error? Give me an example.
 
MakarFX #:

This, yes, should work.

 
Nerd Trader #:

Are you talking about colour change via property? I have such a variant, I need to understand why this one doesn't work.

It works, but reacts to any OnChartEven, i.e. deletes->creates with price "0"->moves to cursor. Hence the flickering

 
Nerd Trader #:

Are you talking about colour change via a property? I have that option, I need to understand why it doesn't work.

No. It's so that objects don't flicker and appear/disappear, don't bounce around like scalded and the CPU doesn't make noise...

So, what's wrong, when object in main window is "0" your function will return false? Explain the point with>=0... or equal to zero.

Look carefully.

if (ObjectFind(chart, name) >= 0)

At what range of values will the condition return true?

 
MakarFX #:
What error? Give an example.

What is usually true? Anything that is not 0 (I mentioned it above). And you have true only when the condition returns false at 0. The object is in the basement (ObjectFind(ch, name) > 0) - false. But error (-1) is true.

So, here is the correct variant:

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

No. It's so objects don't flicker and appear/disappear, jump around like scalded and the CPU doesn't make noise...

Pay close attention.

At what range of values will the condition return true?

And if
ObjectFind(chart, name)=-1

what then?

 
MakarFX #:

It works, but reacts to any OnChartEven, i.e. deletes->creates with price "0"->moves to cursor. Hence the flicker.

why? Why it does not happen for green line? The conditions are identical only inverse (price > Ask) for yellow and (price < Bid) for green.


Mihail Matkovskij #:

It prevents objects from flickering and appearing/disappearing, bouncing around like scalded animals and CPU noise...

For some reason, green and red lines have only one copy and do not flicker when the cursor is moved.


Mihail Mat kovskij #:

Look carefully.

At what value range will the function return true?

from zero and up?
 
Mihail Matkovskij #:

What is usually true? Anything that is not 0 (I mentioned it above). And you have true only when the condition returns false with a value of 0.

Look again carefully

 
MakarFX #:

Look again carefully.

Amended the message. Test your function and mine with incorrect Chart ID and when object is created in subwindow. And see what your function will return and what mine will return. And read the documentation carefully. All links and quote are given above.

Reason: