possible loss of data due to type conversion

 

if I need simple math operation:

datetime dt1, dt2;
int Dist;
double Scale;

dt2= dt1+(Dist*Scale);  

how to adjust datatypes to avoid the warning ? & to get the result of calculation in datetime datatype...

how to adjust correctly all variables to long or to datetime ? (I suppose adjustment should be to some of these datatypes because of their biggest size 8 byte)... 

am I right & how to do it?

p.s. Actually, I also should care if Dist is negative, then dt2 should jump back over the date_holes on the chart (week_end or holiday), but still show the correct size of line to be drawn ... supposing dt1 something like D'YYYY/MM/DD 00:00:00'

 
JeeyCi:

if I need simple math operation:

how to adjust datatypes to avoid the warning ? & to get the result of calculation in datetime datatype...

how to adjust correctly all variables to long or to datetime ? (I suppose adjustment should be to some of these datatypes because of their biggest size 8 byte)... 

am I right & how to do it?

p.s. Actually, I also should care if Dist is negative, then dt2 should jump back over the date_holes on the chart (week_end or holiday), but still show the correct size of line to be drawn ... supposing dt1 something like D'YYYY/MM/DD 00:00:00'

dt1, dt2 are datetime, dist is int & scale is double ... at first sight, i would say that scale shouldn't be a double but an int 

 
Icham Aidibe #:

 i would say that scale shouldn't be a double but an int 

but it is double in fact - as so as it was calculated in proportion

 
JeeyCi:

if I need simple math operation:

how to adjust datatypes to avoid the warning ? & to get the result of calculation in datetime datatype...

how to adjust correctly all variables to long or to datetime ? (I suppose adjustment should be to some of these datatypes because of their biggest size 8 byte)... 

am I right & how to do it?

p.s. Actually, I also should care if Dist is negative, then dt2 should jump back over the date_holes on the chart (week_end or holiday), but still show the correct size of line to be drawn ... supposing dt1 something like D'YYYY/MM/DD 00:00:00'

your calculations make no sense with the information you have provided.

IF scale is the chart scale - then that has nothing to do with date and time so why would it be part of the calculation?

Dist is what?

you need to clarify to get any meaningful answers, we could resolve your error message but your result will still be meaningless.

 
Paul Anscombe #:

IF scale is the chart scale - .

no it isn't... well, in real code this variable has name ScaleM0 (perhaps I shortened the code in the misleading manner- sorry) - but the name doesn't matter - it is just a coefficient taken from some proportion (its meaning is half-of-a-day=86400/2=43200 as FOR maximum value of Dist & all the rest of Dist values in the array are calculated in a proportion to this max & half-of-a-day)...

Paul Anscombe #:
 we could resolve your error message but your result will still be meaningless.

I don't think so if we speak about datatype-casting & drawing the result correctly from dt1 to dt2 (aka date), not speaking about the sence of my calculations...

Dist is int attribute of myClass & no other way.

Well, I casted in such a manner:

double temp= NormalizeDouble(Dist*ScaleM0,0);
dt2=  (datetime)((double)dt1+temp);

& warnings disappeared, (let consider so),

BUT I still cannot draw huge lines to the negative side: temp=-350 - OK finding dt2-point on time-scale, but temp=-35000 is being continued till the left side of the whole chart-window (not stopping at dt2=dt1-35000)... testing now at H1 chart

p.s.

I thought the problem was warning... but after it disappeared still not correct drawing... ?? 

 

really strange, the problem (like this & as I described above) starts back from 2021/06/01,

but such levels, drawn with CChartObjectTrend to negative side in periods later - behaves normally (with normal adjustment according to the proportion coefficient) -

(I mean levels with huge values - that are comparable to those that are not being drawn normallly before 2021/06/01)

this gives me belief that the algorithm of calculation of dt2 is probably OK, but the problem still appears sometimes in dates before the date I marked here... really strange & yet unexpectedly for me  ??

Draw trend line with end
Draw trend line with end
  • 2020.01.07
  • www.mql5.com
Hi, from x y point in a bar a line starts and goes to the right if it touches a bar make it stop if not let it continue...
 
JeeyCi #   

but temp=-35000 is being continued till the left side of the whole chart-window (not stopping at dt2=dt1-35000)...

oh, such mysterious reason appeared to cause such behavior - this.RayRight(false); for somewhat reason is becoming true & getting the default color )) ... now I know where to find the error (in class myDraw probably)... -- & really it was too long myTxtMark passed as parameter to Constructor of Line that makes this.Create(..) - FOUND!

Anyway, if somebody consider my typecast in #4 can be simplified - please, let me know

& thanks for not being indifferent to my problem...

How to draw a trend line that joins the highest point of every candle after first hour of day
How to draw a trend line that joins the highest point of every candle after first hour of day
  • 2018.11.21
  • TenOutOfTen
  • stackoverflow.com
I want to write an EA that joins the highest points of each candle using a trend line (after the first hour of a day). I saw the documentation for the trend line. This is what I've done: I know I am suppose to iterate through the highest value for each candle...