I recently formatted my computer and lost a script code that did this function. I tried to recreate it but was unsuccessful.
it was like this
datetime now = TimeCurrent();
datetime nowTF = now - now % (60 * time[0]);
datetime period = iBarShift(NULL,0, nowTF);
datetime openprice = iOpen(Symbol(),PERIOD_M5,period);
This will print the open price of the current timeframe Print("Open Price is " + DoubleToString(iOpen(NULL,0,0),Digits())); or put it in a variable double OPrice = iOpen(NULL,0,0);
I recently formatted my computer and lost a script code that did this function. I tried to recreate it but was unsuccessful.
it was like this
datetime now = TimeCurrent();
datetime nowTF = now - now % (60 * time[0]);
datetime period = iBarShift(NULL,0, nowTF);
datetime openprice = iOpen(Symbol(),PERIOD_M5,period);
int period = iBarShift(NULL,0, nowTF);
should be integer
-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor -
int period = iBarShift(NULL,0, nowTF);
A shift is not a datetime, it's an int as Sardion stated.
-
datetime nowTF = now - now % (60 * time[0]);
And that is a very big number; result total garbage. You want:datetime nowTF = now - now % PeriodSeconds(PERIOD_H1);
Find bar of the same time one day ago - MQL4 programming forum 2017.10.06 -
int period = iBarShift(NULL,0, nowTF); datetime openprice = iOpen(Symbol(),PERIOD_M5,period);
You are getting the shift for the current chart but using it on the M5 chart. You are mixing apples and oranges.
-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor - A shift is not a datetime, it's an int as Sardion stated.
- And that is a very big number; result total garbage. You want: Find bar of the same time one day ago - MQL4 programming forum 2017.10.06
- You are getting the shift for the current chart but using it on the M5 chart. You are mixing apples and oranges.
I solved my problem with the code below
datetime tempo = TimeCurrent(); string DataHoraSegundosAtual = TimeToString(tempo,TIME_DATE|TIME_SECONDS); string DataHoraSegundosDia = TimeToString(tempo,TIME_DATE) + " 00:00:00"; int diferenca = Bars(Symbol(),PERIOD_CURRENT,DataHoraSegundosDia,DataHoraSegundosAtual); int BarraDeAbertura = iBarShift(NULL,0, DataHoraSegundosDia); float PrecoDeAbertura = iOpen(Symbol(),PERIOD_CURRENT,BarraDeAbertura); printf(PrecoDeAbertura);
- 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 recently formatted my computer and lost a script code that did this function. I tried to recreate it but was unsuccessful.
it was like this