RefreshRates...

 
Hello

I read in doc Mql4 that RefreshRates() updates the data of the current symbol. I understand: the data of the symbol of the card to which is attached the EA. (?)
In this case, for a multi-pair EA, how to refresh the data of other pairs?

Or I'm wrong?

Thank you for your answers
 
stanislass:
Hello

I read in doc Mql4 that RefreshRates() updates the data of the current symbol. I understand: the data of the symbol of the card to which is attached the EA. (?)
In this case, for a multi-pair EA, how to refresh the data of other pairs?

Or I'm wrong?

Thank you for your answers

All the while I've been using functions like iClose("EURUSD",PERIOD_H1,0) to retrieve the latest bid price of EURUSD (or any other pairs)... no need to refresh. What I suspect is that RefreshRates only matter if you're using variables like Ask or Bid... but if you use function calls like iClose, it's automatically get and return you the latest value.

 
stanislass: I read in doc Mql4 that RefreshRates() updates the data of the current symbol. I understand: the data of the symbol of the card to which is attached the EA. (?)
In this case, for a multi-pair EA, how to refresh the data of other pairs?

Or I'm wrong?
Wrong.
  1. After Sleep and between server calls the market will have changed. You must update your variables. To use any pre-defined variables and series arrays you must call RefreshRates
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference RefreshRates updates:
    Predefined variables: Ask, Bars, Bid, Close[], High[], Low[], Open[], Point, Time[], Volume[]
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference
              Predefined Variables - MQL4 Reference
    Also updates: Hour, Minute, and Seconds
              Minute() returns wrong values - or am I wrong? - MQL4 and MetaTrader 4 - MQL4 programming forum
    And updates: OrderClosePrice() on the next order select call.

  2. "Symbol of the card" makes no sense. Perhaps you meant chart.
  3. There are no pre-defined variables for other symbols. Re-read point 1
 
William Roeder:
Wrong.
  1. After Sleep and between server calls the market will have changed. You must update your variables. To use any pre-defined variables and series arrays you must call RefreshRates
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference RefreshRates updates:

  2. "Symbol of the card" makes no sense. Perhaps you meant chart.
  3. There are no pre-defined variables for other symbols. Re-read point 1

2. Yes, that's it. English is not my language.

I will consult the links that you propose to me.

But I'm not sure to find my answer, how to update the data of another chart

 
stanislass:

2. Yes, that's it. English is not my language.

I will consult the links that you propose to me.

But I'm not sure to find my answer, how to update the data of another chart

Refresh rates? Do you know why you need to refresh? and what are the cons for trading?

Now look here :

function run()
{
  set(PARAMETERS);  // generate and use optimized parameters
  StartDate = 20160801;
  TickTime = 100;
  BarPeriod = 5;  // 5 minutes bars
  LookBack = 500;   // maximum time period
 
// calculate the buy/sell signal with optimized parameters
  vars Price = series(price());
  vars Filtered = series(BandPass(Price,optimize(5,1,240,1),0.5));
  vars Signal = series(FisherN(Filtered,500));
  var Threshold = optimize(1,0.5,1.5,0.1);
 
// buy and sell
  Stop  = optimize(100,1,200) * ATR(optimize(100,1,200));
  Trail = optimize(100,1,200) * ATR(optimize(100,1,200));
  if(crossUnder(Signal,-Threshold))
    enterLong();
  else if(crossOver(Signal,Threshold))
    enterShort();
}
 
 
stanislass: But I'm not sure to find my answer, how to update the data of another chart

What part of "1) To use any pre-defined variables … you must call RefreshRates"

What part of "there are no pre-defined variables for other symbols. Re-read point 1" is unclear?

 

Hello,


I wrote an EA that scans the market. The 28 main pairs. It determines the pair with the highest volatility of the 28 over 3 time horizons.


Once found, it is analyzed by means of conventional methods available to us, ie among other things, the rhythm of tics arriving on the chart that hosts the EA. It could be timed with the timer, but it would not change anything.

From time to time, as the market fluctuates, the selected pair changes. That's the point.

And unfortunately, in these cases, the first analysis of the new selected pair is wrong. This causes, rarely but still, mistaken decision making.

I think, I even think, that this is due to the fact that during the first analyzes, the data obtained by the EA are not good because the analysis is done on the temporal basis of the tics received on the chart which hosts the EA, which is obviously not syncronized with the tics received on the analyzed pair.

It would be necessary to refresh this data before any use. But, from what I read on the doc, RefresheRates () refreshes only the data of the graph on which is the EA. I am wrong?

If not, Metaquote offers us things like iOpen (Symbol S, ...) iClose (), iLow () etc but does not offer us anything like iRefreshRates (Symbol S, ...) that would allow us to use them effective way. The, it's a little Russian roulette. Not reassuring at all.

Well, rest assured, in practice I bypassed the problem by not taking into account the first analyzes as they give identical data. But it's a lame solution, do not you think?

My English is aproximative, but I hope you understand it.
 

LOL, I guess I was too vague in my earlier post, and you missed my answer to your question completely.

Basically RefreshRates() is for you to update "predefined variables" for the current symbol - we all know this. Predefined variables are not changed during the execution of our code (so for each OnTick, the values remain constant). Also, predefined variables only exist for current symbol, so RefreshRates() do not have any effect on other symbols.

To retrieve up-to-tick values, we can make calls to MarketInfo() or iClose/iHigh/iLow/iOpen/iTime/iBar suite of functions:

double  MarketInfo(
   string           symbol,     // symbol
   int              type        // information type
   );

So instead of using Ask, Bid, etc. we can do MarketInfo(Symbol(),MODE_ASK) and MarketInfo(Symbol(),MODE_BID), or iClose iHigh iLow, etc. This way we get the latest tick information without using RefreshRates().

The MarketInfo and iClose suite of functions also allow us to retrieve information of other pairs - there you have your answer. So there is no need for any RefreshRates() function for other symbols/pairs, because when you use MarketInfo() etc functions, you automatically get the latest values.

Now, to go further, if you want to make sure that the latest tick from other pair is at the start of that pair's new bar (i.e. first value of a new candle), you'll probably have to also check the times of those ticks, so that your computation only starts when every pair is in sync - I do that all the time, so I make use of global variables to keep track of times.

I hope I'm clear enough this time round.

 


Yes, you were pretty clear.


Your way of looking at the time is interesting, and I would try it.

For my part I compare the value obtained with the previous, and take it into account only if it is different, de facto excluding the first.


However, I find that there is one weakness of MQL4. It took me some time, my EA not being backtestable, to understand why from time to time, rarely certe, there was this unpredictable behavior.

Thank you
 
stanislass: If not, Metaquote offers us things like iOpen (Symbol S, ...) iClose (), iLow () etc but does not offer us anything like iRefreshRates (Symbol S, ...) that would allow us to use them effective way.

Of course they do, just not synchronously.

On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing prices.
          Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
          Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
          Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum