problem with ObjectCreate()

 

Hi Guys

I'm having a problem drawing an Horizontal line on the chart (this is my first mq4 script ever...)

while searching the forum, i saw a related bug fixed using an Object identifier inside the CreateObject function call (the "counter" bellow). I tried to add it to my code by it didn't help, let alone that i still don't understand why it's necessary.

Can anyone tell me what's wrong with the way i'm trying to draw a line, and also explain what is the "+counter" for and if i really need it in my case?

the code is:

int counter = 0;

ObjectCreate("grean_hline"+counter,OBJ_HLINE,0,0,PRICE_OPEN);

ObjectSet("green_hline"+counter,OBJPROP_COLOR,Green);

ObjectSet("green_hline"+counter,OBJPROP_STYLE,STYLE_SOLID);

ObjectSet("green_hline"+counter,OBJPROP_WIDTH,2);

counter++;

Thanks a lot in advanced

Wasseem

 
wasseem:

Hi Guys

I'm having a problem drawing an Horizontal line on the chart (this is my first mq4 script ever...)

while searching the forum, i saw a related bug fixed using an Object identifier inside the CreateObject function call (the "counter" bellow). I tried to add it to my code by it didn't help, let alone that i still don't understand why it's necessary.

Can anyone tell me what's wrong with the way i'm trying to draw a line, and also explain what is the "+counter" for and if i really need it in my case?

for a single line no need

the code is:

int counter = 0;

ObjectCreate("grean_hline"+counter,OBJ_HLINE,0,0,PRICE_OPEN);

read what that means PRICE_OPEN

ObjectSet("green_hline"+counter,OBJPROP_COLOR,Green);

ObjectSet("green_hline"+counter,OBJPROP_STYLE,STYLE_SOLID);

ObjectSet("green_hline"+counter,OBJPROP_WIDTH,2);

counter++;

Thanks a lot in advanced

Wasseem


 

gjol,

thanks for your reply.

i'm sorry, i didn't understand your answer.

i want to draw one line only. but can you please still explain what the +counter mean and why i need it in case of multiple objects?

and, as i understand from mq4 documentation, PRICE_OPEN is a constant parameter holding the last bar's open price value. isn't that true?

note that i also tried PRICE_CLOSE and also tried a fixed number (price) from the current price range (133.32 in GBPJPY). still nothing worked.

i didn't state that earlier, but the problem is that i do not get anything on chart.

in order to see that i'm getting all other stuff right in the code, i added the following line before calling ObjectCreate() and it did show me an alert...

test = iCustom(NULL, 0, "ATR Levels", 10, 0, 1);

Alert("test = ", test);

PS: i also tried it with arrows, didn't work neither.

there must be something basic i'm getting all wrong...

should i include a special library for graphic maybe? or something else i dono..

please help i'm confused :s

 

I think that this script does what you want:

//+------------------------------------------------------------------+
//|                                                   GREEN LINE.mq4 |
//|                                         Copyright © 2010, Oneday |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Oneday"
#property link      ""

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start(){

ObjectCreate   ("GREEN_LINE",OBJ_HLINE,0,0,Open[0]);
ObjectSet      ("GREEN_LINE",OBJPROP_COLOR,Green);
ObjectSet      ("GREEN_LINE",OBJPROP_WIDTH,1);
ObjectSet      ("GREEN_LINE",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetText  ("GREEN_LINE","GREEN_LINE",10,"Arial",Red);
return(0);
}
//+------------------------------------------------------------------+

If you have a look at it, you figure out how it works - then try changing some variables and see what happens. With regard to the counter in your script, I tend to only use that when creating multiple objects with a loop. That way, the counter value increases with each iteration of the loop and each object has a unique name.

Hope this helps?

Cheers

 

much appreciated oneday,

still doesn't work though.

is it possible the reason is that i'm trying to do that in an EA rather than a custom indicator? is there any restrictions on where i can use the Objects functions?

 
wasseem:

much appreciated oneday,

still doesn't work though.

is it possible the reason is that i'm trying to do that in an EA rather than a custom indicator? is there any restrictions on where i can use the Objects functions?

It works as a script, I don't have any experience with EA'S though. Without seeing how you are using it in your code I can't really help further.
Reason: