I can't imagining there is no function like iBarShfit in MT5.
For those ones who only use linear indicators to construct their trading system, the bar position function like iBarShift will seldom be used, even the chart drawing tools is not necessary.
But for other ones, it's important to analysis the trend structure, to measure the Highest, Lowest point, and the price/ time distance between them.
ray, I created that code, but you have the older version.
The
issue with loading data before chart is open is definitely annoying. I
made a fix for that one to. It's a hack, but it works.
Only thing is that with indicators, the fix is not possible becasue indicators do not allow the Sleep function for good reason.
So, on the first tick your indicator would not have the data from the other periods, but likely by the second tick the data would probably be available.
The fix is perfect for EA's and Scripts where you need that first tick to be what you expected.
Here's the latest mt4timeseries.mqh I had posted on the old site:
ray, I created that code, but you have the older version.
The
issue with loading data before chart is open is definitely annoying. I
made a fix for that one to. It's a hack, but it works.
Only thing is that with indicators, the fix is not possible becasue indicators do not allow the Sleep function for good reason.
So, on the first tick your indicator would not have the data from the other periods, but likely by the second tick the data would probably be available.
The fix is perfect for EA's and Scripts where you need that first tick to be what you expected.
Here's the latest mt4timeseries.mqh I had posted on the old site:
ray, I created that code, but you have the older version.
The
issue with loading data before chart is open is definitely annoying. I
made a fix for that one to. It's a hack, but it works.
Only thing is that with indicators, the fix is not possible becasue indicators do not allow the Sleep function for good reason.
So, on the first tick your indicator would not have the data from the other periods, but likely by the second tick the data would probably be available.
The fix is perfect for EA's and Scripts where you need that first tick to be what you expected.
Here's the latest mt4timeseries.mqh I had posted on the old site:
Thank you!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Application:
I use a rectangle to cover a range of a certion trend segment, and want to get the bars count between rectangle's time1 and time2,
evaluate the bars count under Period M1,M5,M15...H1, .. etc, so I can know which period is the best meet for the trend scale.
Solution:
This is no iBarShift function in mq5 anymore, so I use the convert function somebody share the code:
datetime iTime(string symbol,int tf,int index)
{
if(index < 0) return(-1);
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
datetime Time[];
if(CopyTime(symbol, timeframe, index, 1, Time)>0) return(Time[0]);
else return(-1);
}
int iBarShift(string symbol, int tf, datetime time, bool exact=true)
{
if(time<0) return(-1);
//sorry, exact will always =true in this code of mines. no exact=false yet.
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
datetime Time[];
ArraySetAsSeries(Time,true);
if(CopyTime(symbol, timeframe,iTime(symbol,timeframe,0), time, Time)>0) return(ArraySize(Time)-1);
else return(-1);
}
Problem:
I try to use the iBarShift to get shift postion on specify period for a certain time value,
but I got a return value -1 when I specify a period param which without a corresponding chart opened.
It seems that CopyXxxx function couldnot load data before a chart open to load it.
So I had to open all period chart before I call the function?
On the contrary, it will return the right value for the function iBarShift even before any relate chart opened.
Suggestion
Experts in MQ5 had became globle exceed one single chart. so some globle control shoud be set,
such as receive specify currency's data in background automatically without relate chart open?