How to compare 2 value in different time ?

 

Yo,


I wanna know if it's possible to compare 2 values in different time.

I mean, I want to know if In current time the close price is higther (or not) than the close price 5 minutes before, for exemple.


I try it but it seems it doesn't work

(iClose(Symbol(),PERIOD_M1,0) > (iClose(Symbol(),PERIOD_M1,5)))

Thanks in advance

 
Bad_Bond:
I try it but it seems it doesn't work

How do you know it doesn't work?

String PriceToStr(double p){ return( DoubleToStr(p, Digits) ); }
:
double C5min = iClose(Symbol(),PERIOD_M1,5); 
Print("C5min = ", PriceToStr(C5min));
if (C5min == 0) return; // History will be updated
if (Bid > C5min) ... // iClose(Symbol(), ANY_TF, 0) == Close[0] == Bid

if you are not running on the M1 chart:

  1. The first time, the call will fail with ERR_HISTORY_WILL_UPDATED After that it will work.
  2. In the tester it will work only if you have M1 history.
 
WHRoeder:

How do you know it doesn't work?

if you are not running on the M1 chart:

  1. The first time, the call will fail with ERR_HISTORY_WILL_UPDATED After that it will work.
  2. In the tester it will work only if you have M1 history.

Cause it doesn't compare with 5 minutes before.

Maybe i've make a mistake with my calculator...

Your code use the same iClose with Period_M1, there's no another way to make 5minutes before ?

 
Bad_Bond:

Yo,

I wanna know if it's possible to compare 2 values in different time.

I mean, I want to know if In current time the close price is higther (or not) than the close price 5 minutes before, for exemple.

I try it but it seems it doesn't work

Thanks in advance

Hi Bad_Bond,

if (iClose(Symbol(),PERIOD_M1,0) > iClose(Symbol(),PERIOD_M1,5))
  {
  Print ("Bigger than 5 minute ago");
  }
  else
  {
  Print ("Smaller or even equal with 5 minutes ago);
  }

:D

 

re,


If I make this :

iClose(Symbol(),PERIOD_M1,0)-iClose(Symbol(),PERIOD_M1,7) = ??

What could it be the result ? a number (double) ? or another iClose ?

 
Bad_Bond:

re,


If I make this :

What could it be the result ? a number (double) ? or another iClose ?


Did you look at the documentation for iClose ? do you see what iClose returns ? iClose() is a function, it cannot be returned, it returns something . . . this might help you understand about return values: What are Function return values ? How do I use them ?
 

ok

so if my code is :

double Test;
Test=iClose(Symbol(),PERIOD_M1,0)-iClose(Symbol(),PERIOD_M1,7);

Test will return a number in type double

Am I right ?

 
read more about working with doubles
 

It is not clear from your questions how much you understand number representation within a computer.

In a program a number of bytes are reserved to hold the representation of a number. so

double Test;
Test=iClose(Symbol(),PERIOD_M1,0)-iClose(Symbol(),PERIOD_M1,7);

the command double means create a box labled in this example Test to contain numbers with a decimal point in them. (That is use binary floating point number representation)

iClose() is a function which has three parameteres and returns the bar price close value specified by the parameteres. A price value is also one with a decimal point in it and therefore of type double.

In your origional post you use '>' which is a logical comparason operator which essentially does the subtraction and if the result is positive return the logical value TRUE and FALSE if negative. NB 0 is a positive number but in some languages I've seen the error of a negative 0 which I find confusing.

Finally the question of 5 minutes before, if I am being pedantic, that would be 5*60 seconds from the current second. However if we say before the last completed minute then that would be shift 6 if using the minute being construted now that would be shift 5. (although english language is not too clear on this being exactly true as far as I am concerned! and why I don't program for other people)

 

So i'm right


for exemple :

At 12:51 Close was 1.2251

At 12:52 Close was 1.2254

At 12:53 Close was 1.2247

At 12:54 Close was 1.2248

At 12:55 Close was 1.2255

At 12:56 Close was 1.2260

At 12:57 Close was 1.2258

At 12:58 Close was 1.2247

At 12:58 the result of Test will be : 1.2247 - 1.2251 = -0.0004


Isn't it ?

 
Bad_Bond:

Test will return a number in type double

Am I right ?


Is wrong in the way you use the terminology - the code is correct.

Test is a variable of type double, that means Test is a floating decimal point number - but you also have to remember that there are some small inaccuracies when doing binary floating point arithmatic.