How to check for the existence of an external indicator

 

Is there a way to check for the existence of an external indicator in MT4?


I would like my indicator to make sure the external indicator is there so iCustom works properly.

 
TheRumpledOne wrote >>

Is there a way to check for the existence of an external indicator in MT4?


I would like my indicator to make sure the external indicator is there so iCustom works properly.


Did you check your I/O return code with GetLastError() ?

 
Jacques366:

Did you check your I/O return code with GetLastError() ?


No, I didn't know about that. Will look it up. Thanks.



I tried but it does NOT return an error code when I misspell the name.





#property indicator_chart_window

extern string  CustomName     = "BullAndBear_v1" ;
extern int     Length         = 20;  // Period of BullAndBear
extern int     Smooth         = 5;   // Period of Smoothing MA  
extern int     Signal         = 5;   // Period of Signal MA 


//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }
  
//+------------------------------------------------------------------+
int deinit()
  {  
   return(0);
  }  
 
//+------------------------------------------------------------------+

int start()
{


  
int error = 98765 ;

double cBBval;

cBBval  = iCustom(Symbol(),  Period(), CustomName, Length,Smooth,Signal,  0,0);  

error = GetLastError() ;

Comment(   

"CustomName = ", CustomName, "\n", 
"error = ", error, "\n",
"cBBval = ", DoubleToStr(cBBval , 4), "\n",  
 
"" );



   return(0);
}
 

//+------------------------------------------------------------------+  
 
TheRumpledOne:

No, I didn't know about that. Will look it up. Thanks.



I tried but it does NOT return an error code when I misspell the name.





Any other ideas?

 
TheRumpledOne:

Any other ideas?


Howdy TRO,


Personally, I don't like the iCustom routine.. way too limiting for me. So the "brains" of an indicator I'd put in a library as a function, which the indicator calls to process. The data can be passed to the function and "back" via arrays and array reference. This not only makes its possibilities endless, but also allows for error codes to be passed back or at least expected.


This method is also lighter on the cpu as the whole indicator does not need to be run for each data variable sent back... whew ... just to grab a couple pieces of information.


However, if you REALLY MUST use iCustom, and the indicator iCustom is calling was written by you, I'd suggest using global variables. Each time the indicator is called via iCustom, it sets a global variable "flag", which the EA or other indicator reads and clears. When the EA or main indi reads a zero, (assuming a reasonable tick timeout delay) it could be assumed that the indicator is not there. Now that build 223 has fixed the init problems, this could probably be taken care of before the main indicator runs.


All that being said, if it's not your indicator that you are calling (somehow I highly doubt that... ;-) ), I know of no way to determine via MT4 commands if it exists. Maybe try sending it an invalid symbol or shift value and see what it returns. Then check for that known value assuming it doesn't crash MT of course ... hehe.


Mark

 

Thanks for your input, Mark.


The problem is sending code out to others... If they don't load something or delete it then I get an email saying my indicator is not working.


If I could test for the existence of the called indicator then I could have the calling indicator display an error message.


Sometimes, the indicator is written by me and sometimes it is not.


In either case, I still need to test.


Thanks again.

 
TheRumpledOne wrote >>

Thanks for your input, Mark.

The problem is sending code out to others... If they don't load something or delete it then I get an email saying my indicator is not working.

If I could test for the existence of the called indicator then I could have the calling indicator display an error message.

Sometimes, the indicator is written by me and sometimes it is not.

In either case, I still need to test.

Thanks again.

file open the indicator ; if it can open ie exists, no error ; for accessing files outside the folders specified by metatrader see this article

'File Operations via WinAPI'