Hello,
Im trying to get the time of high and low points in my day to determined which one happend first.
How can I do it?
I know I can get the high and low rates of let's say yesterday by this code:
But how do I know which one happend first?
thank you!
Keep track of high and low files in the OnTick() event. That gives the finest granularity.
Reset the high/low values each period, which you say is each day.
Hello,
Im trying to get the time of high and low points in my day to determined which one happend first.
How can I do it?
I know I can get the high and low rates of let's say yesterday by this code:
But how do I know which one happend first?
thank you!
void OnStart() { //---' ' datetime high = HighOfDayTime(), low = LowOfDayTime(); Print("High of day = ",high," - Low of day = ",low); Print(high>low?"Low happened first":"High happened first"); } //+------------------------------------------------------------------+ datetime HighOfDayTime() { MqlRates r[]; //ArraySetAsSeries(r,true); MqlDateTime time_struct; TimeCurrent(time_struct); time_struct.hour=0; time_struct.min=0; time_struct.sec=0; int total = CopyRates(_Symbol,PERIOD_M1,TimeCurrent(),StructToTime(time_struct),r); datetime time = 0; double highest = DBL_MIN; for(int i=0;i<total;i++) { if(r[i].high > highest) { highest = r[i].high; time = r[i].time; } } return time; } datetime LowOfDayTime() { MqlRates r[]; //ArraySetAsSeries(r,true); MqlDateTime time_struct; TimeCurrent(time_struct); time_struct.hour=0; time_struct.min=0; time_struct.sec=0; int total = CopyRates(_Symbol,PERIOD_M1,StructToTime(time_struct),TimeCurrent(),r); datetime time = 0; double lowest = DBL_MAX; for(int i=0;i<total;i++) { if(r[i].low < lowest) { lowest = r[i].low; time = r[i].time; } } return time; }
yuv98:
// Pseudo code in OnTick() static double highest = 0.0; static double lowest = 9999999999.99; // ridiculously large # static datetime highestTime; static datetime lowestTime; double curHigh = . . . double curLow = . . . if ( curHigh > highest ) { highest = curHigh; highestTime = TimeCurrent(); } if ( curLow < lowest ) { lowest = curLow; lowestTime = TimeCurrent(); } if ( TimeCurrent() % 86400 == 0 ) // 86400 = # seconds in a day { highest = 0.0; lowest = 9999999999.99; }
yuv98:
My method would give you a way to store highs / lows over time. You could store these in an array; store them in a file; however you want to use it.
If you need to pull from historical data that you didn't create yourself, you probably want to use something like @nicholishen suggested, but your granularity is limited by the data you pull.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
Im trying to get the time of high and low points in my day to determined which one happend first.
How can I do it?
I know I can get the high and low rates of let's say yesterday by this code:
But how do I know which one happend first?
thank you!