Can we determine whether an indicator is attached or if it is being run through iCustom?

 

hi!

i have an indicator which draws quite a lot of objects onto a chart when it is attached. these objects are in addition to the lines associated with the indicator buffers. when i call this indicator from within an EA obviously the latter lines do not show up on the chart BUT all of the other objects that are drawn by the indicator do get drawn on the chart. is it possible to tell from within the indicator whether it is actually attached to a chart or if it is being called through iCustom?

thanks, andrew.

 
collierab:. is it possible to tell from within the indicator whether it is actually attached to a chart or if it is being called through iCustom?

thanks, andrew.


I would add a new external parameter to the indicator which by default means "attached", and when you call it through iCustom set this parameter to "called".

The indi needs to be modified to skip the part where the objects are created when this parameter is "called".

this parameter may be any type you like, "attached", "called" are only example, it may be 0, 1 as well.

 
thanks, szgy74, that option did actually occur to me. but it seems to me to be a bit of a kludge (no disrespect intended, i assure you!). i was hoping that there might be an elegant solution similar to builtin IsTesting().
 
WindowExpertName maybe ?
 
hi ydrol, that might just work! thanks. i will give it a try and let you know!
 
collierab:
hi ydrol, that might just work! thanks. i will give it a try and let you know!
No, WindowExpertName() can't be used for that. Read the documentation :

Returns name of the executed expert, script, custom indicator, or library, depending on the MQL4 program, from which this function has been called.

 
thanks whroeder, that would do the trick very nicely but only if the indicator were in its own subwindow. in this case the indicator draws on the main window (indicator_chart_window). i would have thought that this would be a common issue: if you have an indicator that draws objects onto a chart (in addition to the information from the indicator buffers) then you would not want this to happen if the indicator were, for instance, being called by an attached EA through iCustom(). yes the behaviour in this case is that the indicator still draws the objects (but, of course, not the information for the indicator buffers). so i am wanting to disable the drawing of these additional objects in the case that the indicator is being used by an EA. any more ideas?
 

just following up, because my response was incomplete: if i run WindowFind() within the start() function of my indicator i get -1 regardless of whether the indicator is attached to a chart or if it is called through iCustom().

#property indicator_chart_window

int init() {
   IndicatorShortName("EP");

   return (0);
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
int start() {
   int win_idx = WindowFind("EP");

   Print("ON WINDOW ", win_idx);
}
 
I think this WindowFind solution will fail when both the original indicator and the one that calls it with iCustom are attached to the same chart.
 

hi szgy74,

thanks for the response. however, i am not sure that i understand you.

for the bare-bones indicator code below:

#property indicator_chart_window

int init()
  {
   IndicatorShortName("EP");
   return(0);
  }
int start()
  {
   Print("on window ", WindowFind("EP"));
   return(0);
  }

if i attach this to a chart then it outputs "on window -1" in the Experts tab of the terminal. this is not what i would have expected. the indicator is attached to the main chart, so i would have thought that WindowFind() would return 0. i naively thought that in the case that the indicator were not actually attached to anything [for example, if it were called through iCustom()] only then would it return -1.

have i got the wrong end of the stick here?

thanks, andrew.

Reason: