Yes, very straight forward, use iOpen : https://docs.mql4.com/series/iOpen with iBarShift : https://docs.mql4.com/series/iBarShift for example . . .
iOpen(NULL, 0, iBarShift(NULL, 0, TimeCurrent()-(TimeCurrent()&3600)-Hour()-1) ) iBarShift(NULL, 0, TimeCurrent()-(TimeCurrent()&3600)-Hour()-1) // gives the bar number for 23:00 hour the previous day TimeCurrent()-(TimeCurrent()%3600)-Hour()-1 // gives the datetime for the 23:00 hour the previous day
Edit: code above is incorrect, should be . . . iOpen(NULL, 0, iBarShift(NULL, 0, TimeCurrent()-(TimeCurrent()&3600)-(60 * 60 * (Hour()+1) ) ) ); iBarShift(NULL, 0, TimeCurrent()-(TimeCurrent()&3600)-(60 * 60 * (Hour()+1) ) ) // gives the bar number for 23:00 hour the previous day TimeCurrent()-(TimeCurrent()&3600)-(60 * 60 * (Hour()+1) ) // gives the datetime for the 23:00 hour the previous day
for example, i want to get the Open Price from the bar that open at 23.00 everyday
Your question is ambiguous.
- If you want the last bar hourly for yesterday:
On H1 or smaller chart
Any chart period
#define HR24 86400 // 24 * 3600 datetime now = Time[0]; int TOD = now % HR24; // Time of day (date+time) datetime BOD = now - TOD; // Beginning of day+0000z datetime y2300 = BOD - 3600; // Yesterday+2300 int i2300 = iBarShift(NULL,0, y2300); Print("Yesterday's open at ", TimeToStr(Time[yesterday2300]), " was ", Open[i2300]);
#define HR24 86400 // 24*3600 datetime now = TimeCurrent(); int TOD = now % HR24; // Time of day (date+time) datetime BOD = now - TOD; // Beginning of day+0000z datetime y2300 = BOD - 3600; // Yesterday+2300z int i2300H1 = iBarShift(NULL, PERIOD_H1, y2300); datetime t2300 = iTime(0, PERIOD_H1, i2300H1); double o2300 = iOpen(0, PERIOD_H1, i2300H1); Print("Yesterday's open at ",TimeToStr(t2300), " was ", o2300);
But on Sunday's open that will not be 2300 it will be Friday's 2100z open (market closes at 2159z.) Over market Holidays it will be the last open before the holiday. - If you really meant the last 2300 the market was open, you need to use:
On H1 or smaller chart Any chart period #define HR2300 82800 // 23*3600 #define HR24 86400 // 24*3600 for(int i2300=0; i2300 < Bars; i2300++){ datetime t2300 = Time[i2300]; int TOD = t2300 % HR24; if (TOD == HR2300) break; } Print("Yesterday's open at ",TimeToStr(t2300), " was ", Open[i2300]);
#define HR2300 82800 // 23*3600 #define HR24 86400 // 24*3600 int iLimit = iBars(0, PERIOD_H1); for(int i2300H1=0; i2300H1 < iLimit; i2300H1++){ datetime t2300 = iTime(0, PERIOD_H1, i2300H1); int TOD = t2300 % HR24; // Time of day if (TOD == HR2300) break; } int o2300 = iOpen(0, PERIOD_H1, i2300H1); Print("Yesterday's open at ",TimeToStr(t2300), " was ", o2300);
You don't have to normally use the iTime/iOpen when you have the simpler Time[]/Open[]- If your broker doesn't run using UTC time then you must adjust 2300 to your brokers time zone.
Yes, very straight forward, use iOpen : https://docs.mql4.com/series/iOpen with iBarShift : https://docs.mql4.com/series/iBarShift for example . . .
hi raptor, thanks for your time replying my question. really appreciate it.
how if i use this kind of code?
datetime some_time=D'23:00'; // define the hour (23.00)
int shift=iBarShift("GBPOUSD",PERIOD_H1,some_time); // define the number of the bar that open 23.00
double hargaopen=Open[shift]; // get the open price from the 23.00 bar
can this work?
can this work?
It might, I'm not sure if datetime some_time=D'23:00'; will give you the correct value, but it might . . try it and see what happens ;-)
Edit: just tried it, it gives an warning: '23:00' - date literal string is incomplete
OK, my code above is not quite correct . . . try this instead . . .
int shift=iBarShift("GBPUSD", PERIOD_H1, TimeCurrent()-(TimeCurrent()&3600)-(PERIOD_H1 * 60 * (Hour()+1) ),exact );
if the value for shift is -1 then the 23:00 bar is missing, i.e. during a weekend or holiday . . .
It might, I'm not sure if datetime some_time=D'23:00'; will give you the correct value, but it might . . try it and see what happens ;-)
Edit: just tried it, it gives an warning: '23:00' - date literal string is incomplete
- I would have thought that D'23:00' would compile but it might take the seconds D'23:00:00'
- D'23:00' is 2300 on the date you COMPILED the EA. not today+2300 if you want today+2300 either use StringToTime("23:00") or the code I posted BOD + 23*3600;
Your question is ambiguous.
- If you want the last bar hourly for yesterday:
On H1 or smaller chart
Any chart period
But on Sunday's open that will not be 2300 it will be Friday's 2100z open (market closes at 2159z.) Over market Holidays it will be the last open before the holiday. - If you really meant the last 2300 the market was open, you need to use:
On H1 or smaller chart Any chart period
You don't have to normally use the iTime/iOpen when you have the simpler Time[]/Open[]- If your broker doesn't run using UTC time then you must adjust 2300 to your brokers time zone.
hi everyone,
thanks too for your time.
actually the logic of my EA later will just be simple,
my EA will automatically open position with condition
"buy" if the current price is 20points under the open price of 23.00 bar and "sell" if the current price is 20points above the open price of 23.00 bar
but if either one of the condition is hit, then the other one will be ignored.
ex. today 23.00 open bar is 1.6000, then it goes up 1.620, the EA will open sell, and when the price go down 20 points from open price, it will not open buy anymore cause one condition has been hit. and it will open another position tomorrow with the exact condition though the previous position hasn't closed yet.
Edit : sorry, just read your comment, my connection is really slow here..
I'll get into this topic
My question:
I'm looking for the High from the 10:00 hour candle from yesterday
and the Low from the 10:00 hour candle from the day before yesterday
Can someone help me there ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, does anyone know how to get an Open Price for specific bar everyday?
for example, i want to get the Open Price from the bar that open at 23.00 everyday
can anybody help me?
since i'm still very new to this mql4
thanks before.