Create object from parameters of another from a different timeframe

 

Hello mql4 experts,

I am trying to put a rectangle on a 5 min chart based on the start and end times of a 15min chart trend line. The code used is shown below. The active chart when the indicator is inserted is the 5min. Based on my understanding that object names are unique, I try to get the time parameters of the 15 min object with the ObjectGet() functions, but this fails. The date and time returned are always Jan 1, 1970 at 0:00:00 (i.e. the metatrader time origin).

I suspect this is because when I use ObjectGet, the 15 min chart is not the active chart. I have researched importing user32.dll GetParent() and SendMessageA() to make the 15min chart active. Apparently, I am not getting it right. Can you put me through please.

int start()
{
datetime myStart, myEnd;
myStart=ObjectGet("Old Trend",OBJPROP_TIME1);
myEnd=ObjectGet("Old Trend",OBJPROP_TIME2);
if(!ObjectCreate("New Trend",OBJ_RECTANGLE,0,myStart,134.00,myEnd,134.05))
{
return(0);
}
else
{
ObjectSet("New Trend",6,Yellow); //6 represents colour property
ObjectSetText("New Trend","New",10,"Arial",Ivory);
}
return(0);
 

you can only get objects from the same chart where expert is working.

 
irusoh1:

you can only get objects from the same chart where expert is working.

thank you, irusoh1.

besides using ObjectGet(), isn't there another way to get this done? the task looks so basic. it would surprise me if there is no mql4 work-around.

 

See object visibility;  Also need to consider the property when using ObjectSet & ObjectGet. 

  OBJPROP_TIMEFRAMES  
  15  int  Value can be one or combination (bitwise addition) of object visibility constants to set/get timeframe object property.

 
workaround : when you draw/redraw the object(s) save the latest parameter to GlobalVariable & have the EA/Indicator read from that. Good luck.  

 
cameofx:

See object visibility; Also need to consider the property when using ObjectSet & ObjectGet.

OBJPROP_TIMEFRAMES
15 int Value can be one or combination (bitwise addition) of object visibility constants to set/get timeframe object property.


workaround : when you draw/redraw the object(s) save the latest parameter to GlobalVariable & have the EA/Indicator read from that. Good luck.

thanks cameofx. i read that GlobalVariables can only be of type "double". it happens that the object parameter i am interested in is of type "datetime" as you may notice in the code above.
 
maceo:
thanks cameofx. i read that GlobalVariables can only be of type "double". it happens that the object parameter i am interested in is of type "datetime" as you may notice in the code above.
well, datetime is an integer of seconds elapsed since 01.01.70. Doesn't matter if we store it to double-type variable. It will be cast back to integer again when you put it on integer-type variable. But you can always write & update it to a file with File functions. Hope this helps.
Reason: