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

 
Nerd Trader #:
Yes indeed as much as 8 pieces, but the chart does not show that the price is 0 does not matter, the line still clings to the cursor (follows it)

Don't use ObjectDelete because the line runs away to "0" every time

better
      ObjectSetString(0,"line 1",OBJPROP_NAME,line_name);
      ObjectSetInteger(0,line_name,OBJPROP_COLOR,clrRed);
 
MakarFX #:

Don't use ObjectDelete because the line runs away to "0" every time

better
I have the renaming option and yes it works. In the case of ObjectDelete() then why green and red lines are created in one instance and do not flicker? And yellow line (Stop Loss) if already there is why it is infinitely proliferate when it is below Bid?
 

0 means false. Anything not 0 istrue. But has anyone thought about readability of such code, where all kinds of conditions are mixed?

if(!ObjectFind("Buy Stop"))

It is not a boolean value. But it can be easily turned into a boolean:

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

So the main thing is to have the right approach to code writing. Then you willnever have such problems.

 
Nerd Trader #:
I have the renaming option and yes it works. In the case of ObjectDelete() why green and red lines are created in one instance and don't blink? And yellow line, if it already has one, why does it keep multiplying infinitely?

These lines are in your control.

if(id==CHARTEVENT_OBJECT_CLICK){

And the lines that flicker react to any OnChartEvent, because

if(ObjectGetInteger(0,"Button Stop Order",OBJPROP_STATE))
 
Mihail Matkovskij #:

0 means false. Anything not 0 istrue. But has anyone thought about readability of such code, where all kinds of conditions are mixed?

It is not a boolean value. But it can be easily turned into a boolean:

So the main thing is to have the right approach to code writing. Then you willnever have such problems.

return(ObjectFind(_chartID, _name) >= 0)

And if the object is "0" in the main window, it will return false?

 
MakarFX #:

And the lines that flicker react to any OnChartEvent, because.

I told him: Button pressed - create line, button released - delete (same with other types of objects that can be linked to). But he said: it's nothing, I'll do everything "normally". :)

 
Nerd Trader #:

And if the object is "0" in the main window, it will return false?

That's what can defeat your reluctance to read the documentation!

https://www.mql5.com/ru/docs/objects/objectfind

https://docs.mql4.com/ru/objects/objectfind

Return value

If successful, the function returns the number of the subwindow (0 means main chart window) where the found object is located. If no object is found, the function returns a negative number. To get more information aboutthe error, callGetLastError() function.

Документация по MQL5: Графические объекты / ObjectFind
Документация по MQL5: Графические объекты / ObjectFind
  • www.mql5.com
ObjectFind - Графические объекты - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
MakarFX #:

These lines are in your control.

And the lines that flicker react to any OnChartEvent, because

as well as the green line, in general all lines also react to cursor movement. I just realized that all three lines are created in the spread area because the yellow line "Sell Stop" has the condition if(price > Ask) for the green line "Buy Stop" (price < Bid) and for the grey line "not allowed"(price > Bid && price < Ask )
 
Nerd Trader #:

And if the object is "0" in the main window, will it return false?

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

I told him: Button pressed - create line, button released - delete (same with other types of objects that can be attached to). But he said: it's nothing, I'll do it properly. :)

Do you mean the colour change via property? I have such an option, I need to understand why it doesn't work.

Mihail Matkovskij #:

Here's something that might defeat your unwillingness to read the documentation?!

https://www.mql5.com/ru/docs/objects/objectfind

https://docs.mql4.com/ru/objects/objectfind

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