Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network. Start earning money!
Super Freddy
45
Super Freddy 2014.08.03 00:26 
Just want to draw a line....one horizontal line (will add more after this one works). I drag the indicator (*.mq4) on top of my chart and nothing happens. Why isn't it drawing a horizontal line? What it should be doing is taking the price level "1.68744" and adding variable "hirange" and drawing the line at that price level. When I compile, No errors, no warnings.
#property indicator_chart_window

extern double closeprice    =    1.68744; 
extern int    lowrange      =     25;
extern int    hirange       =     40;
extern color  LineColor     =   Gray;


int start()
  {
      
string   top40;

   

   ObjectCreate(top40, OBJ_HLINE, 0, 0, closeprice+hirange);
   ObjectSet(top40, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(top40, OBJPROP_WIDTH, 2);
   ObjectSet(top40, OBJPROP_COLOR, LineColor);

   return(0);
 }
qjol
3243
qjol 2014.08.03 00:52  

it's very easy to spot what the problem is by using GetLastError

   if(!ObjectCreate(top40, OBJ_HLINE, 0, 0, closeprice+hirange))
      Alert(GetLastError());

the error you get (4204) means

 

4204

ERR_NO_OBJECT_NAME

No object name

 

one more thing

i believe you don't want the HLine to be drawn at 41.68744 (closeprice+hirange) am i right ?

Super Freddy
45
Super Freddy 2014.08.03 02:21  
extern double closeprice    =    1.68744; 
extern double    lowrange   =    0.00025;
extern double    hirange    =    0.00040;
extern color  LineColor     =   Gray;


No, I don't want it to increment to that number. I updated to the intended result.

My line of code is not within an "if" statement, like you have it. Do I need to do it that way?


I'm playing with the code more and no improvement. I established the name of the object by creating a string "top40" (w/o quotations). ObjectCreate takes the first parameter for the name of the object, which I stated as "top40", so why would I get an error 'no object name'?


Thx for your help :-)

Super Freddy
45
Super Freddy 2014.08.03 02:38  
int start()
  {
      
string   a="top40";

   

   ObjectCreate(a, OBJ_HLINE, 0, 0, closeprice+hirange);
   ObjectSet(a, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(a, OBJPROP_WIDTH, 2);
   ObjectSet(a, OBJPROP_COLOR, LineColor);
   Alert(GetLastError());
}
I think I was declaring the string variable incorrectly. I had "string top40;" and now I have "string a=top40;" ...I now get an error 4200?
Super Freddy
45
Super Freddy 2014.08.03 02:41  
int start()
  {
      
string   a="top40";

   
   ObjectDelete(a); // <--new line added to compensate for 4200 error "object already exists"
   ObjectCreate(a, OBJ_HLINE, 0, 0, closeprice+hirange);
   ObjectSet(a, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(a, OBJPROP_WIDTH, 2);
   ObjectSet(a, OBJPROP_COLOR, LineColor);
   Alert(GetLastError());
}


The new line "Object Delete" should delete any previous instances of this. But now after compiling I get error "0", which is not in the documentation https://docs.mql4.com/constants/errorswarnings/errorcodes
Super Freddy
45
Super Freddy 2014.08.03 02:56  

wait--wait---wait!!!  I think I figured it out...I'll post the working code next...WOO-HOO!!!

/
To add comments, please log in or register