the value for the RSI calculated regarding the bar T[0] is wrong
How did you understand this? How did you check this?
I just attached the RSI to the chart. The RSI value for the current bar changes when a new tick arrives. This proves that your statement, which I am quoting, is incorrect (if your statement were true, the RSI value for the current bar would not change, since PRICE_OPEN does not change with the arrival of a new tick).
I have checked. iRSI for the current bar returns the correct value
#property strict void OnTick() { Comment("#0 = " + DoubleToString(iRSI(_Symbol, _Period, 14, PRICE_CLOSE, 0), 4)); } void OnDeinit(const int reason) { Comment(""); }
I still have the same problem. I have tried with two different MT4.
2024.02.20 00:00:00 WAT-TDI EURUSD,M15: Heure actuelle: 2024.02.20 00:00:00
2024.02.20 00:00:00 WAT-TDI EURUSD,M15: Prix de clôture actuel (T[0]): 1.07785 (Wrong Value)
2024.02.20 00:00:00 WAT-TDI EURUSD,M15: Prix de clôture précédent (T[1]): 1.07782
2024.02.20 00:15:00 WAT-TDI EURUSD,M15: Heure actuelle: 2024.02.20 00:15:00
2024.02.20 00:15:00 WAT-TDI EURUSD,M15: Prix de clôture actuel (T[0]): 1.07767 (Wrong Value)
2024.02.20 00:15:00 WAT-TDI EURUSD,M15: Prix de clôture précédent (T[1]): 1.07773
DATA
DATE / TIME / OPEN PRICE / CLOSE PRICE
2024.02.20 00:00 1.07785 / 1.07773
2024.02.20 00:15 1.07767 / 1.07777
The value of the RSI on the graph is correct. However the one on the journal shows a different number.
Following is the OnTick I used to check the values :
#property strict void OnTick() { Print("Current Time: ", TimeToStr(TimeCurrent(), TIME_DATE | TIME_SECONDS)); Print("Cuurent Price Close (T[0]): ", Close[0]); Print("Previous Price Close (T[1]): ", Close[1]); }
The value of the RSI is correct. However the one on the journal shows a different number.
Following is the OnTick I used to check the values :
Why do you copy indicator values into arrays? In MT4 this is not necessary. For the current symbol and timeframe, calling iRSI again will not lead to the indicator being recalculated. Calling iRSI again will return a ready-made value
Following the OnTick. Assure declaring before datetime lastCandleTime = 0;
void OnTick() { datetime currentCandleTime = iTime(_Symbol, _Period, 0); datetime previousCandleTime = iTime(_Symbol, _Period, 1); Print("Current time: ", TimeToStr(TimeCurrent(), TIME_DATE | TIME_SECONDS)); Print("Heure de la dernière bougie (T[0]): ", TimeToStr(currentCandleTime, TIME_DATE | TIME_SECONDS)); Print("Heure de la bougie précédente (T[1]): ", TimeToStr(previousCandleTime, TIME_DATE | TIME_SECONDS)); Print("Price Close of T[0]: ", Close[0]); Print("Price Close of T[1]: ", Close[1]); if (currentCandleTime != lastCandleTime) { lastCandleTime = currentCandleTime; Print("Procéder avec les calculs pour la nouvelle bougie."); CalculateRSIValues(); Print("RSI Values Calculated"); if (ArraySize(GlobalRSIValues) > 0) { Print("Tous les tableaux sont correctement remplis. Exécution de la logique de trading."); ExecuteTradingLogic( GlobalRSIValues[0], ); } else { Print("Un ou plusieurs tableaux nécessaires sont vides. Aucune action de trading prise."); } } }
After debugging, I found that the T[0] RSI is determined with the Open Price instead of the Close Price.
You only call iRSI when a new bar opens. At the moment the bar opens, its opening price is equal to its closing price (and also equal to the high and low). Do you understand what the problem is?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How can I correct this ?
Thank you for your help.
Alain