Sounds messy. You can use iHighest to get the bar number on M5 (for example) but prior to that you need to find the bar number of midnight in order to know how far back to look with iHighest. That means using iBarShift.
You got me thinking, and it wasn't so messy...
But a strange problem came up.
//Running this on EURUSD 1H //OK!! //-------------For Yesterday:------------- int Ystart = TimeHour(TimeCurrent()); int Yshift = iHighest("EURUSD", PERIOD_H1, MODE_HIGH, Ystart + 24, Ystart); int Yhr = 24 - Yshift + TimeHour(TimeCurrent());//OUT double Yprice = iHigh("EURUSD", PERIOD_H1, Yshift);//OUT //---------------------------------------- //-------------For Today:------------- int Tstart = TimeHour(TimeCurrent()); int Tshift = iHighest("EURUSD", PERIOD_H1, MODE_HIGH, Tstart , 0); int Thr = TimeHour(TimeCurrent()) - Tshift;//OUT double Tprice = iHigh("EURUSD", PERIOD_H1, Tshift);//OUT //---------------------------------------- Comment( Tshift );//iHighest returns 852 on the midnight bar (!)iHighest (Tshift) returns 852 on the midnight bar (!). Once on the next bar 01:00 - 01:59 it gives the correct value. Is this a bug ??
As usual I find the answer after posting a question. iHighest cant handle start=0 and length=0.
DayTrader:
As usual I find the answer after posting a question. iHighest cant handle start=0 and length=0.
It's not a question of can't handle . . . it's not a logical thing to do, "what is the bar number with the highest value in these 0 bars" ?
As usual I find the answer after posting a question. iHighest cant handle start=0 and length=0.
DayTrader:
Working on TF 5M I want to know a little of whats going on higher TF, like 1H and 1D.
Eg. I want to know the day's high, and previous day's high.. simple:
int ToDaysHighestPrice = iHigh(NULL, PERIOD_D1, 0); int YesterDaysHighestPrice = iHigh(NULL, PERIOD_D1, 1);
But how can I figure out the time for the two, eg on which hour of the day (hours after midnight) did the price peak?
// int ToDaysHighestPrice = iHigh(NULL, PERIOD_D1, 0); // int YesterDaysHighestPrice = iHigh(NULL, PERIOD_D1, 1); datetime today = iTime(NULL, PERIOD_D1, 0), yesterday = iTime(NULL, PERIOD_D1, 1); int iToday = iBarShift(NULL, 0, today), iYesterday= iBarShift(NULL, 0, yesterday), iTodayHigh= Highest(NULL,0,MODE_HIGH, iToday+1, 0), // or not incl. 0 bar: ..iToday, 1) iYestHigh = Highest(NULL,0,MODE_HIGH, iYesterday-iToday, iToday+1); Print("yesterday's high of ", PriceToStr(High[iYestHigh])," occured on ", TimeToStr(Time[iYestHigh]));
DayTrader:
This assumes that there are 24 H1 bars. Does not account for the weekend or holidays. There may be no bar corresponding 24 hours ago. It also doesn't account for Sunday being a short day for all brokers not running UTC+2.
int Yshift = iHighest("EURUSD", PERIOD_H1, MODE_HIGH, Ystart + 24, Ystart); int Yhr = 24 - Yshift + TimeHour(TimeCurrent());//OUT
WHRoeder:
This assumes that there are 24 H1 bars. Does not account for the weekend or holidays. There may be no bar corresponding 24 hours ago. It also doesn't account for Sunday being a short day for all brokers not running UTC+2.
This assumes that there are 24 H1 bars. Does not account for the weekend or holidays. There may be no bar corresponding 24 hours ago. It also doesn't account for Sunday being a short day for all brokers not running UTC+2.
Yes had some 'strange' results at times...where the result pointed 2-3 days back even though I was searching only inside yesterday.
Your solution works perfect in those cases, and also over weekends. Thanks alot for that one !
One other little thing : datetime appears to be an integer... is it safe to use "int" instead of "datetime" ?
Safe until 19 Jan 2038 when the int becomes negative and the datetime won't be. But why not document exactly what your code is doing.
WHRoeder:
Safe until 19 Jan 2038 when the int becomes negative and the datetime won't be.
Safe until 19 Jan 2038 when the int becomes negative and the datetime won't be.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
Working on TF 5M I want to know a little of whats going on higher TF, like 1H and 1D.
Eg. I want to know the day's high, and previous day's high.. simple:
But how can I figure out the time for the two, eg on which hour of the day (hours after midnight) did the price peak?
I can do it in a for-next loop, but it must be possible to do this (really fast) without looping 48 times trough a loop?