Download MetaTrader 5
To add comments, please log in or register
Publish your article and get a reward!
Peter Williams
342
Peter Williams 2014.10.18 14:06 

I believe I have used these 2 routines on several occasions and never had a warning / problem.

When I compile my EA I get the warning "macro redefinition" with line # for line in second routine.  Obviously not critical but would like to understand why the warning is occurring and what to do to overcome / prevent this happening again

//                                                                                         |
//                                                                                         | 
//=================================Draw_my_VLine -- START==================================+                                                                                      |
void Draw_my_VLine(long time_value, string ObjName, color colour)
{  #define WINDOW_MAIN 0    //   NO warning generated for this line 
   if ( ObjectFind(ObjName) == 0 ) ObjectDelete(ObjName);
   ObjectCreate(ObjName, OBJ_VLINE, WINDOW_MAIN,  time_value,0);
   ObjectSetText(ObjName, ObjName, 10, "Times New Roman", colour);   
   ObjectSet(ObjName, OBJPROP_COLOR,colour);
   ObjectSet(ObjName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ObjName, OBJPROP_WIDTH, 2);
   ObjectSet(ObjName, OBJPROP_RAY, False);
   return;
}
//=================================Draw_my_VLine -- END====================================+ 
//                                                                                         |
//                                                                                         |
//================================Draw_my_HLine -- START===================================+
void Draw_my_HLine(double line_value, string ObjName, color colour)
{  #define WINDOW_MAIN 0    //   warning generated for this line "macro redefinition"
   if ( ObjectFind(ObjName) == 0 ) ObjectDelete(ObjName); 
   ObjectCreate(ObjName, OBJ_HLINE, WINDOW_MAIN, Time[0], line_value);
   ObjectSetText(ObjName, ObjName, 10, "Times New Roman", colour);   
   ObjectSet(ObjName, OBJPROP_COLOR,colour);
   ObjectSet(ObjName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ObjName, OBJPROP_WIDTH, 1);
   ObjectSet(ObjName, OBJPROP_RAY, False);
   return;
}
//===================================Draw_my_HLine -- END==================================+

Carl Schreiber
5954
Carl Schreiber 2014.10.18 16:21  
try to define it only once at the head of your EA and not within a function.
Peter Williams
342
Peter Williams 2014.10.18 16:40  
gooly:
try to define it only once at the head of your EA and not within a function.

that's working fine - many thanks

whroeder1
13630
whroeder1 2014.10.18 20:04  
gooly: try to define it only once at the head of your EA and not within a function.
Macro's are global from the place defined. They are not within any function.
Carl Schreiber
5954
Carl Schreiber 2014.10.19 07:43  
WHRoeder:
gooly: try to define it only once at the head of your EA and not within a function.
Macro's are global from the place defined. They are not within any function.

I know!

But it is my experience that in case of teaching or advising it is better to give a person some room for 'experiments'.

A try-to-do-formulation causes a different approach to solve the problem than a you-must do. The later might increases the dependency on looking for a next advice. Try-to-do increases the feeling I can do it myself - I hope.

Halley
198
Halley 2014.10.19 13:11  
Global or local - they are precompiler directives, with no relation to the code structure. 
Peter Williams
342
Peter Williams 2014.10.20 09:12  
DeepThought:
Global or local - they are precompiler directives, with no relation to the code structure. 

Thanks all very much - not even sure I understand all the replies ... now working fine.


As always thanks to all for replies

/
To add comments, please log in or register