Can anyone correct this bit of code... I NEED to get the Time that the high and low happened on each day.

 

Can anyone correct this bit of code... I NEED to get the Time that the high and low happened on each day.

int D1_bar = iBarShift(NULL, PERIOD_D1, Time[i]);

      double High_i=iHigh(NULL, PERIOD_D1, D1_bar);
      double Low_i=iLow(NULL, PERIOD_D1, D1_bar);
      
      datetime val=Time[iTime(NULL,0,High_i)];
      datetime val2=Time[iTime(NULL,0,Low_i)];
      
       datetime Time_High_i=iTime(NULL, TF, High_i);
       datetime Time_Low_i=iTime(NULL, TF, Low_i);
 
iTime return the time of bar open like every 0.00 o'clock of the day
 
yijomza:
iTime return the time of bar open like every 0.00 o'clock of the day

Ok, well can to put my right if you know the the way the code should read..
 


int D1_bar = iBarShift(NULL, PERIOD_D1, Time[i]);

double High_i = iHigh(NULL, PERIOD_D1, D1_bar);
double Low_i = iLow(NULL, PERIOD_D1, D1_bar);

datetime time = iTime(NULL,0,D1_bar);

// your code makes Time[i] == time, cause you first take the time on i-th bar, take data and search for same time again.

There you go. You dont need the datetime time = ... part.

 
iTime(iLowest()) and iTime(iHighest()) on the M1 chart for the last day...
 

Doesnt that take a lot more time and cycles to compute?

The H1 chart would compensate for any timezone disrepancies and it would take 60x less time to check the hourly array.

 

Well, i don't know how exactly the OP needs the time. Of course you can optimize the algorithm, by going down the timeframes.

You can get it down to: 8 (H4)+4(H1)+4(M15)+3(M5)+5(M1) = 24 '==' Operations.and of course a few iBarsShifts.. But the result will be i high performant algorithm on the maximal possible time resolution. Don't know if it's worth the effort since the cpu power of today can easy handle those 1440 operations, especially since the values change only once a day.

 

Wow awesome i love it :))) damn why didnt i think of that :PPP

Why 8(H4) though?

EDIT: and while it's true that today's cpu horsepower borders on the pure-awesomeness, if one's planning on doing a lot of stuff with the same cpu, he/she should still code efficient algorithms.

 
forexCoder:

Wow awesome i love it :))) damn why didnt i think of that :PPP

Why 8(H4) though?

EDIT: and while it's true that today's cpu horsepower borders on the pure-awesomeness, if one's planning on doing a lot of stuff with the same cpu, he/she should still code efficient algorithms.

Ah your are right, it is 6 H4 candles..

Sure, but 1440 iterations once every day should not be a problem, here on GTM+1 timezone there is near to no action in the markets at this time, i don't worry about missing some ticks, but i with the 1440 iterations method i get an easy to read and easy to change algorithm. Optimization can be done after the EA is completed. This is a general advice, first make the program work, implement all features, log the execution time for each function, and then (if you are not happy with the execution time) you can going to optimize the worst functions.

Non optimized code is way easier to read/change and modify.

 
THanks :)
 
zzuegg:

Ah your are right, it is 6 H4 candles..

Sure, but 1440 iterations once every day should not be a problem, here on GTM+1 timezone there is near to no action in the markets at this time, i don't worry about missing some ticks, but i with the 1440 iterations method i get an easy to read and easy to change algorithm. Optimization can be done after the EA is completed. This is a general advice, first make the program work, implement all features, log the execution time for each function, and then (if you are not happy with the execution time) you can going to optimize the worst functions.

Non optimized code is way easier to read/change and modify.


will this give me what i need. The hourly time of the daily low and daily high??

int D1_bar = iBarShift(NULL, PERIOD_D1, Time[i]);

      double High_i=iHigh(NULL, PERIOD_D1, D1_bar);
      double Low_i=iLow(NULL, PERIOD_D1, D1_bar);
      
       datetime Time_High_i=Time[iHighest(NULL,PERIOD_H1,D1_bar)];
       datetime Time_Low_i=Time[iLowest(NULL,PERIOD_H1,D1_bar)];