Bar shifting and iLow/iLowest only work on full hours? (10pm, 11pm ...)
Okay... I think, I found my error... But nothing is wring in the code!
E.g.: If I type from 12-17, the EA marks a diffrent/wrong area... - 17 shifts for the 17 o'clock is right, but not 37 for 12 o'clock...
Does anybody know the solution?
The time outputs are right... So iBarShift is wrong or I just don't use it right... - Can that be?
- FrazeColder: E.g.: If I type from 12-17, the EA marks a diffrent/wrong area... - 17 shifts for the 17 o'clock is right, but not 37 for 12 o'clock...12-17 is 5 hours. 5 hours on the M15 is 20 bars. 17 + 20 = 37. Exactly correct.
string fromH = IntegerToString((fromHour)); string fromM = IntegerToString(fromMinute); string toH = IntegerToString((toHour)); string toM = IntegerToString(fromMinute); : string point = "."; string spacer = " "; string doublepoint = ":"; string year = IntegerToString(Year()); string month = IntegerToString(Month()); string day = IntegerToString(Day()); StringAdd(year, point); StringAdd(month, point); StringAdd(day, spacer); StringAdd(fromH, doublepoint); StringAdd(toH, doublepoint); string fromFinal = year+month+day+fromH+fromM; string toFinal = year+month+day+toH+toM; : datetime lowest = StrToTime(fromFinal); datetime highest = StrToTime(toFinal);
Simplify your date handlingdatetime lowest = StrToTime(StringFormat("%i:%i", fromHour, fromMinute) ); datetime highest = StrToTime(StringFormat("%i:%i", toHour, toMinute) );
Or simplify your date handling by not using strings.#define HR2400 86400 int time(datetime when=0){ return int(when == 0 ? TimeCurrent() : when) % HR2400; } datetime date(datetime when=0){ return datetime( (when == 0 ? TimeCurrent() : when) - time(when) ); } datetime tomorrow(datetime when=0){ // Weekends not accounted return date(when) + HR2400; } /// Returns previous trading day. datetime yesterday(datetime when=0) /**< Previous relative to * when. */{ if(when==0) when = TimeCurrent(); int iD1 = iBarShift(NULL, PERIOD_D1, when); // Find today. return iTime(NULL, PERIOD_D1, iD1 + 1); // Return yesterday. } ////////////////////////////////// datetime now = date(); datetime lowest = now + fromHour * 3600 + fromMinute * 60; datetime highest = now + toHour * 3600 + toMinute * 60;
Okay, then another example...
This time I typed from 12 to 16 o'clock.
The EA says that I need to shift 8 bars, to get to the 16 o'clock bar and 24 shifts to 12 o'clock. That's correct!
-> So the range for the lowest and highest price in this time should be between 8 till 24 bar shifts. Correct?
But why the hell is the EA saying, that the highest bar is at 25 bar shifts and the lowest by 31? - That's totally wrong!!!
And to you code: So I don't need 4 input variables for the time, just two. Right
For example: 12:15 and 16:30 - Right? - Because the "command" %i:%i splits the string at ":".
But why I need 4 variables then in the code?
datetime lowest = StrToTime(StringFormat("%i:%i", fromHour, fromMinute) ); datetime highest = StrToTime(StringFormat("%i:%i", toHour, toMinute) );
Ohhh... so I thought, that I start stands for the beginning of the shifting... :/
Any idea, how I can fix this problem? - I only want to check a specified area... So if we have 17:45 and I type fron 10-17 o'clock, I don't want, that oLowest/iHighest checks also the time area between 17 o'clock and now (17:45)...
int lowestShifts = iLowest(NULL, 0, 1, leftToShiftLowest, leftToShiftHighest); int highestShifts = iHighest(NULL, 0, 2, leftToShiftLowest, leftToShiftHighest);
- You code it properly. As eddie already said, there is only count and start no from and to. When in doubt, think!
int lowestShifts = iLowest(NULL, 0, MODE_LOW, leftToShiftLowest - leftToShiftHighest + 1, leftToShiftHighest); int highestShifts = iHighest(NULL, 0, MODE_HIGH, leftToShiftLowest - leftToShiftHighest + 1, leftToShiftHighest);
- Don't hard code numbers, use the symbolic constants Series Array Identifiers - Indicator Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
Thank you a Lot WHRoeder!
But if it is possible could you help me by two more questions?
1. I already wrote:
"And to you code: So I don't need 4 input variables for the time, just two. Right
But why I need 4 variables then in the code?"
datetime lowest = StrToTime(StringFormat("%i:%i", fromHour, fromMinute) ); datetime highest = StrToTime(StringFormat("%i:%i", toHour, toMinute) );
2. I wanna try to change my system to a fully automatic system, so I don't need to input the times anymore...
But my problem is to "program the future". For example:
I have some fix times when I'am using my EA. We say, let's use 10am-12am. How can I programm the EA so, that the EA is looking every day, between 10am to 12am for the highest and lowest price at the market?
The specified range which I must enter in the EA at the moment!

- Free trading apps
- Free Forex VPS for 24 hours
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey Guys,
I have one problem... My EA only works on full hours. Like from 10pm to 11pm and so on. But if I input 10:15 or 10:54 to 11 it doesn't work...
The EA should operation so that he can give me the highest and lowest price between a specified timespan. But I don't know why it only works with full hours... I also testet it on the right Chart!
E.g. for 10:54-11:12 the M1 chart, for 10:05-11:00 the M5 chart, for 10:15-10:45 the M15 Chart and so on...
This is my code:
Greetings and thank you!