A question for MQL connoisseurs - page 3

 

Somewhere I got the advice to always check if an object exists before using ObjectCreate (or ObjectSet? I don't remember)

In general, I use this variant

if (ObjectFind("AsignalGF")==-1)
      {ObjectCreate("AsignalGF",OBJ_LABEL,0,0,0,0,0);
      ObjectSet("AsignalGF",OBJPROP_CORNER,1);
      ObjectSet("AsignalGF",OBJPROP_XDISTANCE,12*1);
      ObjectSet("AsignalGF",OBJPROP_YDISTANCE,1*5);
      ObjectSetText("AsignalGF",CharToStr(110),38,"Wingdings",DimGray);}
 
leonid553:

Good afternoon.

Spent half a day already and can't figure it out.

Please advise what may be the error here ? Could it be in INIT function ?

the error could be

1. If you call WindowFind() in init() or in a function that is called in init

2. windowFind() and you have #property indicator_chart_window declared, since windowFind() is called for subwindow

3. there is no indicator with the name you are looking for in the window

 
keekkenen:

3. the indicator with the name you are looking for is not in the window

mmm... what do you mean object?
 
Abzasc:
mmm... what do you mean object?

what does this have to do with the object ?

The object is secondary, because it is trying to be rendered in a window which does not exist,

besides, if the object is created, there will be no error, if the object is created secondarily, ObjectCreate() will return false

 
keekkenen:

what does this have to do with the object ?

The object is secondary, because it is trying to be rendered in a window that doesn't exist,

besides, if the object is created, no error will occur, if the object is created secondarily, ObjectCreate() will return false

Got it, thanks :)
 
keekkenen:

error can be

1. if you call WindowFind() in init() or in function which is called in init

2. windowFind() and you have #property indicator_chart_window declared, because windowFind() is called for subwindow

3. the indicator with the name you are looking for is not present in the window


1. No, I call the function in START : object("Symbol1", Symbol_1, 11, Color_1, 5);

2. You have declared #property indicator_separate_window

3. So how can an indicator be missing if its window is present ?

Here is the function itself :

void object(string name, string _text, int fontsize, color color_, int value) {
// задаем окно индикатора
 ObjectCreate(name+ WindowExpertName(), OBJ_LABEL, WindowFind(WindowExpertName()), 0, 0);
 // задаем текстовую метку в окне
ObjectSetText(name+ WindowExpertName(), _text, fontsize, "Times New Roman", color_);
 ObjectSet(name+ WindowExpertName(), OBJPROP_CORNER, 1);//задаем правый угол
 ObjectSet(name+ WindowExpertName(), OBJPROP_XDISTANCE, 4);//задаем х-координату
 ObjectSet(name+ WindowExpertName(), OBJPROP_YDISTANCE, value);//задаем у-коордтнату 
                                     }
I don't call anything at all in INIT. Maybe I should add something there as well?



 
Abzasc:

Somewhere I got the advice to always check if an object exists before using ObjectCreate (or ObjectSet? I don't remember)

In general, I use this variant.

What name should I specify in (ObjectFind("AsignalGF") -

What should I set the name of the indicator or the name (array) of the line drawn by the indicator?

 
leonid553:

Which name should I set in (ObjectFind("AsignalGF") -

indicator name or the (array) name of the line drawn by the indicator?

The name of the object that is created/changed.
 

I think I got it. I set the name of the object in the function.

ObjectCreate(name+ WindowExpertName(), OBJ_LABEL, WindowFind(WindowExpertName()), 0, 0);


 
leonid553:

I set the name of the object in the function. ObjectCreate(name+ WindowExpertName(), ....);

Yeah, that's what we're looking for.