You should read more about virtual functions.
It actually calls the overloaded by descendant of CSeries method
Noted. Thanks very much. ;)
Hi, I would like to ask about the Refresh method on the mql4 platform instead of mql5. I think on the mql4 is empty. (correct me if i am wrong)
So, what is the correct way to implement the mql4's virtual Refresh method.
Thanks !
Hi, I would like to ask about the Refresh method on the mql4 platform instead of mql5. I think on the mql4 is empty. (correct me if i am wrong)
So, what is the correct way to implement the mql4's virtual Refresh method.
Thanks !
You are correct. There is no need to refresh MQL4 since it doesn't have to copy buffers. It's instead a wrapper of the built-in indicator functions, which also don't need to be refreshed.
Thank you for your response. All i want is to handle the bad situation with the wrong data from a different timeframe. If i use some of the native function to get indicator data and set the timeframe different than the one which the indicator is loaded then i get wrong data. In order to replicate the same issue you need to not have open that chart with the requested timeframe. I saw some implementation from the forum but i don't use loops or sleep function. In mql5 the problem solves very easily.
Do you have any good implementation in order to solve that issue ?
Thanks
Thank you for your response. All i want is to handle the bad situation with the wrong data from a different timeframe. If i use some of the native function to get indicator data and set the timeframe different than the one which the indicator is loaded then i get wrong data. In order to replicate the same issue you need to not have open that chart with the requested timeframe. I saw some implementation from the forum but i don't use loops or sleep function. In mql5 the problem solves very easily.
Do you have any good implementation in order to solve that issue ?
Thanks
I'm not sure what you mean by that. The CIndicator descendants are just thin wrappers for the built-in functions, and return the same values.
//+------------------------------------------------------------------+ //| Access to buffer of "Moving Average" | //+------------------------------------------------------------------+ double CiMA::GetData(const int buffer_num,const int index) const { return(iMA(m_symbol,m_period,m_ma_period,m_ma_shift,m_ma_method,m_applied,index)); } //+------------------------------------------------------------------+ //| Access to buffer of "Moving Average" | //+------------------------------------------------------------------+ double CiMA::Main(const int index) const { return(GetData(0,index)); }
Thank you for your response. All i want is to handle the bad situation with the wrong data from a different timeframe. If i use some of the native function to get indicator data and set the timeframe different than the one which the indicator is loaded then i get wrong data. In order to replicate the same issue you need to not have open that chart with the requested timeframe. I saw some implementation from the forum but i don't use loops or sleep function. In mql5 the problem solves very easily.
Do you have any good implementation in order to solve that issue ?
Thanks
Please demonstrate what you mean with wrong data ?
There are two situations .
1) Situation when the chart has never be loaded. In the following example i request data from the AUDUSD D1 timeframe and the result is 0. If i run second time the script then i get the correct data.
Example of code
// Request Data from AUDUSD Symbol and timeframe D1 double rsiPrice = iRSI("AUDUSD",PERIOD_D1,14,PRICE_CLOSE,1); Print("rsiPrice = "+rsiPrice);
- Here is the result of the requested data of the timeframe D1 which i never loaded in the terminal
- Here is the result when i run the script second time. The requested data is correct.
2) Situation when the chart sometime in past was opened but at the moment you request data from it, is closed. In the following example you see that it returns the data but it is wrong. If i run it second time i get the correct data.
Example of code
//-- request data from AUDUSD symbol and time frame H1 which i have a long time to loaded double rsiPrice = iRSI("AUDUSD",PERIOD_H1,14,PRICE_CLOSE,1); Print("rsiPrice = "+rsiPrice);
- Request data from a chart which is not loaded for a while. In this example is AUDUSD H1 timeframe.
the result is 64.9094
- Open the chart to see the RSI indicator actual data
the result is 50.774
- Run the script second time. Now you have the correct data.
the result is 50.774
These are the issues which i am facing.
Thank you for your time.
There are two situations .
1) If the value is 0 (and 0 is not a normal value), that means there is an error, you need to use GetLastError() and process it (error 4066 or 4073). There are several solution to manage it, mine is to wait next tick, but you can also use a loop until you get good data is you want (I don't recommend it).
2) You are right this happens when using a different timeframe. To avoid this your need to use iRSI (or iCustom or any iXYZ function) to get the data on every tick, even if you don't need the value every tick.
If you need only 1 value like in your script you should find a way to detect if the value is right, as far as I remember there is no error returned. The problem being that index 1 in iRSI mean the last closed candle according to (possibly) not updated data. So you need to check the time of candle for the timeframe you want iRSI.
Anyway there is no way to avoid these issues, you need to deal with them.
Thank you for the advice and the clarifications.
- 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 Guys,
Method Refresh() is called in CIndicators::Refresh(). but the method Refresh() in file Series.mqh is empty, why? please advise.
//+------------------------------------------------------------------+
//| Indicators.mqh |
//| Copyright 2010, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//| Revision 2010.10.17 |
//+------------------------------------------------------------------+
//| Refreshing of the data of all indicators in the collection. |
//| INPUT: no. |
//| OUTPUT: flags of updating timeframes. |
//| REMARK: flags are similar to "flags of visibility of objects". |
//+------------------------------------------------------------------+
int CIndicators::Refresh()
{
int flags=TimeframesFlags();
//---
for(int i=0;i<Total();i++)
{
CSeries *indicator=At(i);
if(indicator!=NULL) indicator.Refresh(flags);
}
//---
return(flags);
}
---------------------------------------------------------------------------------------------------------
//+------------------------------------------------------------------+
//| Series.mqh |
//| Copyright 2010, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//| Revision 2010.10.17 |
//+------------------------------------------------------------------+
virtual void Refresh(int flags) { }