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

 
Nerd Trader #:

why? Why doesn't this happen for the green line? The conditions are identical only the inverse (price > Ask) for the yellow line and (price < Bid) for the green line.

But the green and red lines, for some reason, are created only in one instance and don't blink when the cursor moves.

from zero and above?

Interesting point...

You are looking for two lines

        if(ObjectFind("Buy Stop") == window || ObjectFind("not allowed") == window){

and you delete one.

          ObjectDelete(line_name);

The question is which one? What is the last name of "line_name"

 
Mihail Matkovskij #:

Completed the message. Test your function and mine with incorrect Chart ID and when object is created subwindow. And see what your function returns and what mine believes.

You're just out of the loop)


 
MakarFX #:
And if

what then?

Error. And you, true, for some reason!

 
Mihail Matkovskij #:

Error. And you, true, for some reason!

"-1" means no object. Since there is no object, true
 
MakarFX #:

You're just out of the loop.)


I've given you what checking the object's existence should look like. And that my function won't work? On the contrary, it's more versatile. If you need to work with a subwindow, it won't notice much difference.

 
Mihail Matkovskij #:

I've given you what checking the existence of the object should look like. And that my function won't work? On the contrary, it is more versatile. If you need to work with a subwindow, it won't make much difference.

Let me repeat the question

What if
ObjectFind(chart, name)=-1

What then?

 
MakarFX #:
"-1" - there is no object. Since there is no object - true

Your function will return true and when an error occurs:

Forum on trading, automated trading systems and trading strategy testing

Any questions from newbies about MQL4 and MQL5, tips and discussion about algorithms and codes

Mihail Matkovskij, 2021.12.06 12:38

Enriched your message. You should 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.


 
  string name = "name";

  ObjectCreate(1, name, OBJ_HLINE, 1,0,0);

  Print(FindObject("name"));

  if (objectExist(0, "name")) Print("objectExist Find");
  else Print("objectExist Object not found.");

...

bool objectExist(const long _chartID, const string _name) { return(ObjectFind(_chartID, _name) >= 0); }

bool FindObject(string name)
  {
   if(ObjectFind(0,name)) return(false);
   return(true);
  }
I create not in main window, it's still true (but Makar wrote for my situation only for main window). For objectExist it is clear, there >= 0.


If search for other object not "name", then Makar's variant will return false.
 
Mihail Matkovskij #:

Completed 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.

Mihail Matkovskij #:

I gave you what the object's existence check should look like. And my function won't work? On the contrary, it is more universal. If you need to work with a subwindow, it won't make much difference.


As for the universality of the function, well...

bool FindObject(string name,int win)
  {
   if(ObjectFind(0,name)!=win) return(false);
   return(true);
  }
 
MakarFX #:

An interesting point...

You're looking for two lines

and you remove one.

The question is which one? What is the last name of "line_name"?

The one that, by convention, is true