Errors, bugs, questions - page 1343

 
StrategyTester:

Hello.

Question about MT5 and its Tester.

I have a self-written multicurrency Expert Advisor, which calls a self-written multicurrency indicator that calculates some ratios between two currency pairs. During testing and debugging I found a problem: in the Terminal at some moment line "A" is higher than line "B", while in the Strategy Tester at the same moment and with the same indicator settings with visualization turned on, line "A" is lower than line "B". And in general: the appearance of the indicator lines in the Terminal is fundamentally different from that in the Strategy Tester. Question: Is this a glitch of the MT5 Tester or an error in the code?


Let me clarify: I am seeing a redrawing of the indicator.

 
Karputov Vladimir:
Always the indicator is drawn the way it is in the terminal. Maybe in the tester you need to try several modes (all ticks, mathematical prices and so on).
I tried "All ticks", "OHLC on M1", "Opening prices only". The result is the same - the indicator is re-drawn. The option"Mathematical Calculations" is not active, not available.
 
StrategyTester:
Tried "All ticks", "OHLC on M1", "Opening prices only". The result is the same - the indicator redraws. The option"Mathematical Calculations" is not active, not available.
In that case, please provide me with the code.
 

Question to developers: Under what conditions is the symbol's history considered unsynchronized, i.e. SeriesInfoInteger(symbol, period, SERIES_SYNCHRONIZED) returns false?

The point is that I occasionally encounter a situation when false values are returned for a certain symbol in all timeframes, even though there is a history for this symbol (Bars and other functions return non-zero values). What can be the reason?

 

There is also such a problem. When reading the history for several symbols / timeframes in the indicator through CopyTime, CopyClose, etc. the indicator often blinks.This is not the result of rendering (there is no recalculation of bars), but just the entire image disappears for a fraction of second, and then appears again. And sometimes not for fractions, but for whole seconds. Usually it is observed during chart scrolling. If the requested timeseries is small, the problem does not occur.

I would like to hear the developers comment on how this may be related.

 
Karputov Vladimir:
In that case, please provide the code.

I enclose an illustration of the differences in the terminal and the tester and the code of the indicator.

//+------------------------------------------------------------------+
//|                                             Indicator1_6test.mq5 |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.6"
#property indicator_separate_window
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
#property  indicator_color1 SkyBlue
#property  indicator_color2 Yellow
#property  indicator_type1 DRAW_LINE
#property  indicator_type2 DRAW_LINE
//---
enum TT{_close=0,_open=1,_high=2,_low=3};
//---
input string activ1="GBPUSD",activ2="EURUSD";
input TT PriceType=_close;
input int Len=100;
//---
double ratio[],avr[];string NN[]={"rr1","rr2","aa1","aa2"};
//---
void setv(int i,double v){ObjectSetDouble(0,NN[i],OBJPROP_PRICE,v);}
//---
int OnInit()
{
   SetIndexBuffer(0,ratio);
   PlotIndexSetString(0,PLOT_LABEL,"Ratio");
   SetIndexBuffer(1,avr);
   PlotIndexSetString(1,PLOT_LABEL,"Avr");
   ArraySetAsSeries(ratio,1);
   ArraySetAsSeries(avr,1);
   for(int i=0;i<4;i++)ObjectCreate(0,NN[i],22,0,0,0);
return(INIT_SUCCEEDED);
}
//---
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
int limit=0;double zz[4];

  if(prev_calculated==0){limit=MathMin(Bars(activ1,0),Bars(activ2,0));limit--;}
  else limit=rates_total-prev_calculated;
  if(limit==0)limit=1;
  double Price1[],Price2[]; ArraySetAsSeries(Price1,1); ArraySetAsSeries(Price2,1);
  getV(Price1,Price2,limit);
  for(int i=0;i<limit;i++){if(Price1[i]>0&&Price2[i]>0)ratio[i]=Price1[i]/Price2[i];else ratio[i]=ratio[i+1];}
  
  double sred=0,sum=0; 
  for(int i=0;i<limit;i++)
      {
      sred=0;
      avr[i]=SimpleMA(i,Len,ratio);
      
      for(int j=i;j<i+Len;j++)
        {
        if(j>=ArraySize(ratio))break;
      if(ratio[j]==0||ratio[j]==EMPTY_VALUE){sred=0;break;}
      sred=1;
        }
      }
      
  if(prev_calculated!=0)for(int i=0;i<10;i++)if(ratio[i]==0)ratio[i]=ratio[i+1];
  
zz[0]=ratio[1];zz[1]=ratio[2]; zz[2]=avr[1];zz[3]=avr[2];
for(int i=0;i<4;i++)setv(i,zz[i]);
return(rates_total);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void getV(double&Price1[],double&Price2[],int limit)
{
if(PriceType==_close){CopyClose(activ1,PERIOD_CURRENT,0,limit,Price1);CopyClose(activ2,PERIOD_CURRENT,0,limit,Price2);}
if(PriceType==_open){CopyOpen(activ1,PERIOD_CURRENT,0,limit,Price1);CopyOpen(activ2,PERIOD_CURRENT,0,limit,Price2);}
if(PriceType==_high){CopyHigh(activ1,PERIOD_CURRENT,0,limit,Price1);CopyHigh(activ2,PERIOD_CURRENT,0,limit,Price2);}
if(PriceType==_low){CopyLow(activ1,PERIOD_CURRENT,0,limit,Price1);CopyLow(activ2,PERIOD_CURRENT,0,limit,Price2);}
}
//---
double SimpleMA(const int position,const int period,const double &price[])
  {
//---
   double result=0.0;
//--- check position
      //--- calculate value
      if(position+period+1>ArraySize(price))return(0);
      for(int i=0; i<period; i++) result+=price[position+i];
      result/=period;
   return(result);
  }
//---
 

In general, with functions

Copy

have other problems,

I came across the fact that when this function is called it can "freeze" the EA, I wrote a program using a large number of symbols and did calculations on the history for literally the last 3 days on each symbol,

I used to have moments when everything hung for a few minutes, I hardly figured out that it was the Copy function. The function would safely handle 150-200 symbols, then hung up, hangs on different symbols ...

hang time ranged from 5 seconds to 2-3 minutes...

 
Copy functions in EAs are synchronous and expect paging of data if not available.
 
StrategyTester:

I am attaching an illustration of the differences in the terminal and the tester and the code of the indicator.

There is an error in the function:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void getV(double&Price1[],double&Price2[],int limit)
  {
   if(PriceType==_close)
     {
      CopyClose(activ1,PERIOD_CURRENT,0,limit,Price1);
      CopyClose(activ2,PERIOD_CURRENT,0,limit,Price2);
     }
   if(PriceType==_open)
     {
      CopyOpen(activ1,PERIOD_CURRENT,0,limit,Price1);
      CopyOpen(activ2,PERIOD_CURRENT,0,limit,Price2);
     }
   if(PriceType==_high)
     {
      CopyHigh(activ1,PERIOD_CURRENT,0,limit,Price1);
      CopyHigh(activ2,PERIOD_CURRENT,0,limit,Price2);
     }
   if(PriceType==_low)
     {
      CopyLow(activ1,PERIOD_CURRENT,0,limit,Price1);
      CopyLow(activ2,PERIOD_CURRENT,0,limit,Price2);
     }
  }

You are trying to copy the data of another symbol in haste. You should not do this. The data must first be downloaded, prepared and checked... Here is the description:Organisation of dataaccess

 
Karputov Vladimir:

There is an error in the function:

You are trying to copy another character's data in a hurry. This is not the way to do it. The data must first be loaded, prepared, made sure... Here is the description:Organising dataaccess

Thanks for the tip. I will have a look.
Reason: