Problems to use ObjectSet when parameters are defined as variables

 

Hello experts

I am trying to built an EA and on it I want to draw vertical and horizontal line. For easiness to change line characteristics in future, I am defining lines characteristics as variables at the begining of my code like this

// Variables to handle order previous opened by EA
string timeopened_linecolor="Yellow"; // color of line to be drawn when position is being opened
string timeopened_linestyle="STYLE_SOLID"; // style of line to be drawn when position is being opened
int timeopened_linewidth=2; // width of line to be drawn when position is being opened

but when executing ObjectSet using those variables (follows code)

ObjectCreate("open_pos", OBJ_VLINE, 0, Time[MA_shift+0], 0)// Creating obj.
ObjectSet("open_pos",OBJPROP_COLOR,timeopened_linecolor); //defining line color
ObjectSet("open_pos",OBJPROP_WIDTH,timeopened_linewidth); //defining line width
ObjectSet("open_pos",OBJPROP_STYLE,timeopened_linestyle); //defining line style
ObjectSet("open_pos",OBJPROP_BACK, true); //defining line as background

... I am getting following error message on MT4 Expert Tab: "Invalid double number as parameter 3 for ObjectSet function"

I try replacing actual value (e.g. Yellow) on ObjectSet function and it worked.

Does any one has an idea why I am facing this problem? Is it allow to manage ObjectSet function as I am pretending?

Thank you

 

Hi rafo05,

1. Use SRC button to post your code

2. You don't have serious problem, you just did not read the documentation carefully https://docs.mql4.com/constants/objects/properties

for example: for ObjectSet()'s OBJPROP_COLOR the type of variable should be color, not string like yours, so it should be like this

color timeopened_linecolor = Yellow; // color of line to be drawn when position is being opened

I think you can check and solve the rest of the err, don't you think ?

 

Style is not a string . . .

string timeopened_linestyle = "STYLE_SOLID";

. . it's an int

As you can see from the documentation . . .

OBJPROP_STYLE7intValue is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.

STYLE_SOLID is actually one of the many predefined standard constants, most uppercase words you see in the Documentation are constants.

 

Thank you "onewithzachy" and "RaptorUK" for highlight this my mistake. I realized how it is, corrected it and it works!

Thank you very much! :-)

Reason: