rsiBuffer should be two-dimensional
double rsiBuffer[][MAX_TIME_FRAMES];
and you need a barshift array
int shift[MAX_TIME_FRAMES]=iBarshift(Symbol(),timeframes[i],...
= iRSI(Symbol(), timeFrames[i], 14, PRICE_CLOSE, shift[i]);
openingTimes[i] = iTime(Symbol(), timeFrames[i], 0);
Tester limitation, you can NOT get bar zero data for other TF/pairs// openingTimes[i] = Time[0];
rsiBuffer should be two-dimensional
double rsiBuffer[][MAX_TIME_FRAMES];
and you need a barshift array
int shift[MAX_TIME_FRAMES]=iBarshift(Symbol(),timeframes[i],...
= iRSI(Symbol(), timeFrames[i], 14, PRICE_CLOSE, shift[i]);
Many thanks for both of the replies. As I am a beginner I appreciate your answers.
Why should rsiBuffer be two-dimensional. iRSI returns an int and I assume I need to keep one RSI value or each timeframe which will take last 14 bars into calculation from each TF.
I used iBarShift as below but shift values are always zero so I cannot determine whether there's a new bar?
for(i = 0; i < MAX_TIME_FRAMES; i++) { //According the opening times find the bar shift. Give the current time. We need to do this at every tick as Time[0] may change. shift[i] = iBarShift(Symbol(),timeFrames[i], Time[0], true); Print("Tick=", tickCount, " i=", i, " timeFramesStr= ", timeFramesStr[i], " shift: ", shift[i], " Time[0]:", TimeToStr(Time[0],TIME_DATE|TIME_SECONDS), " TimeCurrent:", TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)); }
Also if I can not get bar zero data for other TF/pairs how can I see whether a new bar opened for other TFs. I am running EA on M1 chart so at everytick I check whether it's a new bar for M1 chart if so that I want to check the others so at every tick I'll call iRSI for all TFs which have a new bar(so RSI has changed). E.g. at 05:00 I would have 5 new M1 bars and 1 new M5 bar I believe.
And does MQL5 has limitations like this? As I am a beginner I think I can go with MQL5 too but Alpari and most of the other brokers doesn't use it for real time trading so that discourages me..
I am trying to set up the logic below:
datetime openingTime; .... .... int start() { if(openingTime < Time[0]) { //There is a new M1 bar. openingTime = Time[0]; for(i = 0; i < MAX_TIME_FRAMES; i++) { if("IF THERE IS A NEW BAR FOR timeFrames[i]") { rsiBuffer[i] = iRSI(Symbol(), timeFrames[i], 14, PRICE_CLOSE, 1); } } } }
you were on the right track. only suggested barshift for error handling so that you don't get 1970.01.01 00:00 when no bar is found.
you can get bar zero data for higher tf's, but in the tester it approximates the values as it only knows OHLC and open/close times.
- Zero bar of another timeframe for the same symbol under test is modeled approximately
Open = correct Open, Close = correct Close, Low = min (Open,Close), High = max (Open,Close), Volume = final Volume (false)
rsibuffer is a double which should be normalized to 0 decimal places as it is percentage.
think this one should work.
#define MAX_TIME_FRAMES 7 datetime openingTimes[MAX_TIME_FRAMES]; int timeFrames[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1}; string timeFramesStr[] = {"M1", "M5", "M15", "M30", "H1", "H4", "D1"}; double rsiBuffer[MAX_TIME_FRAMES]; //datetime currentTime; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, rsiBuffer); SetIndexLabel(0, "RSI"); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int i; Print("Start\n"); for(i = 0; i < MAX_TIME_FRAMES; i++) { openingTimes[i] = iTime(Symbol(), timeFrames[i], 0); Print("openingTime = ", TimeToStr(openingTimes[i])); } for(i = 0; i < MAX_TIME_FRAMES; i++) { if(openingTimes[i] == Time[0]) { Print("New bar i=", i); Print("at: ", TimeToStr(openingTimes[i])); Print("TF: ", timeFramesStr[i]); //A new bar opening time for the ith time frame rsiBuffer[i] = iRSI(Symbol(), timeFrames[i], 14, PRICE_CLOSE, 1); Print("RSi ",timeFramesStr[i]," ",DoubleToStr(rsiBuffer[i],0)); } } //---- return(0); }

- 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,
My code below tries to check RSI for all timeframes. I am checking the time and looking into whether it's a barclosing time. So forexample between 12:30-13:15 there should be 45 M1 bars, 9 M5 bars, 1 M30 bar so on.. But at every tick (start runs) it finds new bar from M5 to D1 and I see time outputs like "openingTime = 1970.01.01 00:00" . Any help or hints will be usefull.
thanks in advance.
OUTPUT of start in a range: