Unless you are expecting no activity during an entire 5mins, there are usually 12 M5 bars in an Hour.
However, you can also use "iBarShift()" to get an index for a start date/time and as well as an index for end date/time. The difference of the two indices will give you the number of bars in between those two dates/times.
May someone help me? I want to find the position of the highest bar in the range of nearest 80 bars. I have tried to code below, however, I do not get the right result. May someone helps me with what wrong with my code and how to correct it to find out how many bars from the current to the highest point?
int y2bar= iHighest(NULL,PERIOD_H1,MODE_HIGH,80,1);// find the highest bar
double y2= iHigh(NULL,PERIOD_H1,y2bar);// value of the highest bar
int x2= Bars(NULL,PERIOD_H1,Time[y2bar],Time[0]);// count how many bars from current to the highest
Or using iBarShift(NULL,0,iTime(NULL,0,y2bar));
Both codes turn wrong result
May someone help me? I want to find the position of the highest bar in the range of nearest 80 bars. I have tried to code below, however, I do not get the right result. May someone helps me with what wrong with my code and how to correct it to find out how many bars from the current to the highest point?
int y2bar= iHighest(NULL,PERIOD_H1,MODE_HIGH,80,1);// find the highest bar
double y2= iHigh(NULL,PERIOD_H1,y2bar);// value of the highest bar
int x2= Bars(NULL,PERIOD_H1,Time[y2bar],Time[0]);// count how many bars from current to the highest
Or using iBarShift(NULL,0,iTime(NULL,0,y2bar));
Both codes turn wrong result
Both codes seem ok on my chart. In what way is the result wrong?
Perhaps you are not on H1? Also...
iBarShift(NULL,0,iTime(NULL,0,y2bar));
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I was trying to find a way of counting bars only after a condition is true. I have coded this so it can recognise any timeframe and adjust to suit.
In this code my condition is meant to count each bar between 8am and 9am each day on the 5m chart.
I am happy with this code as it does the job okay but have i written too much code for such a simple task? I couldnt figure out how i might use predefined Bars variable because it only counts all bars on chart when i wanted to only count when a condition is true?