Date Conversions

To add comments, please log in or register
Eaglehawk
218
Eaglehawk  

i've been away from metrader 4 for a while, so my coding is a little rusty, while creating an indicator, reason has arisen to convert a distance between two datetime variable into a number of bars, i think i may have it, but i'm not so sure about subtraction of datetimes, will these expressions do the trick?

datetime center_time = ObjectGet(line,OBJPROP_TIME1);//horizontal refrence to center, or left point of line

double center_height = ObjectGet(line,OBJPROP_PRICE1);//vertical refrence to center, or left point of line

datetime radius_time = ObjectGet(line,OBJPROP_TIME2);//horizontal refrence to outer, or right point of line

double radius_height = ObjectGet(line,OBJPROP_PRICE2);//vertical refrence to outer, or right point of line

double Distance_g = (radius_time - center_time)/Period();

line is a variable that represents a line already drawn.

thanks in advance for any and all help.

Michel
476
Michel  
Eaglehawk:
while creating an indicator, reason has arisen to convert a distance between two datetime variable into a number of bars

Try this:

int NumBars = MathRound((EndTime - StartTime)) / (Period*60));

[/PHP]

Or maybe more precise in some cases:

[PHP]

int StartShift = iBarShift(NULL,0,StartTime,false);

int EndShift = iBarShift(NULL,0,EndTime,false);

int NumBars = StartShift - EndShift;

Eaglehawk
218
Eaglehawk  
Michel:
Try this:

int StartShift = iBarShift(NULL,0,StartTime,false);

int EndShift = iBarShift(NULL,0,EndTime,false);

int NumBars = StartShift - EndShift;

this looks precise, and it makes sense,

thanks again for the help!

To add comments, please log in or register