Errors, bugs, questions - page 54

 

It would be nice to give us all an example of an indicator that works well on the chart and in the tester.

I have changed my version, now the indicator values on the chart match the history but the values in the tester do not.

What have I done wrong?

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Label1
#property indicator_label1  "I1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "I2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  Green
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- indicator buffers
double         I1Buffer[];
double         I2Buffer[];
int OnInit()
  {
   SetIndexBuffer(0,I1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,I2Buffer,INDICATOR_DATA);
   return(0);
  }
int OnCalculate (const int rates_total,      // размер входных таймсерий
                 const int prev_calculated,  // обработано баров на предыдущем вызове
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[])        // Spread
  {
   string Symbol_1="EURUSD",Symbol_2="GBPUSD";
   if(rates_total<1) return(0);
   double Arr1[],Arr2[];
   int end,rez0,rez1,rez_0,rez_1;
   datetime ld1[],ld2[];
   end=MathMin((int)SeriesInfoInteger(Symbol_1,0,SERIES_BARS_COUNT)-1,(int)SeriesInfoInteger(Symbol_2,0,SERIES_BARS_COUNT)-1);
   end=MathMin(end,rates_total-prev_calculated+1);
   rez0=CopyClose(Symbol_1,PERIOD_CURRENT, 0,end, Arr1);
   rez_0=CopyTime(Symbol_1,PERIOD_CURRENT, 0,end, ld1);
   if(rez0==-1){Print("Ошибка копирования ",Symbol_1," ",GetLastError()); return(0);}
   if(rez0!=rez_0){Print("Не сходятся цены с временем",Symbol_1," ",GetLastError()); return(0);}
   rez1=CopyClose(Symbol_2,PERIOD_CURRENT, 0,end, Arr2);
   rez_1=CopyTime(Symbol_2,PERIOD_CURRENT, 0,end, ld2);
   if(rez1==-1){Print("Ошибка копирования ",Symbol_2," ",GetLastError()); return(0);}
   if(rez1!=rez_1){Print("Не сходятся цены с временем",Symbol_2," ",GetLastError()); return(0);}
   if(rez1!=rez0){Print("Ошибка Синхронизации"); return(0);}
  
   ArraySetAsSeries(Arr1,true);
   ArraySetAsSeries(Arr2,true);
   ArraySetAsSeries(ld1,true);
   ArraySetAsSeries(ld2,true);
    
   int li=rates_total-1;
   I1Buffer[li]=Arr1[0]+0.26;
   I2Buffer[li]=Arr2[0];
   li--;
  
   int shift1=0,shift2=0;  
   for(int i=1;i<end-MathMax(shift2,shift1);i++)
     {      
      if(time[li]==ld1[i+shift1])I1Buffer[li]=Arr1[i+shift1]+0.26;
      else if(time[li]>ld1[i+shift1]&&i!=0){shift1--;I1Buffer[li]=I1Buffer[li+1];}
      else if(time[li]<ld1[i+shift1]&&i!=0){shift1++;I1Buffer[li]=I1Buffer[li+1];}
            
      if(time[li]==ld2[i+shift2])I2Buffer[li]=Arr2[i+shift2];
      else if(time[li]>ld2[i+shift2]&&i!=0){shift2--;I2Buffer[li]=I2Buffer[li+1];}
      else if(time[li]<ld2[i+shift2]&&i!=0){shift2++;I2Buffer[li]=I2Buffer[li+1];}
      li--;
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

And the Expert Advisor

int Handle;
int bars,i;
void OnInit()
  {
   Handle=iCustom(NULL,0,"proverka");
  }

void OnTick()
  {
   double   buf1[],buf2[];
   datetime time[];
//---
   if(bars==Bars(_Symbol,_Period))return;
   bars=Bars(_Symbol,_Period);
   CopyTime(_Symbol,_Period,0,2,time);
   if(CopyBuffer(Handle,0,0,2,buf1)<0 || CopyBuffer(Handle,1,0,2,buf2)<0) Print("Ошибка копирования значений индикаторных буферов ",GetLastError(),"!!");
   if(i>100)return;
   i++;
   Print("Время "+TimeToString(time[1],TIME_DATE|TIME_MINUTES),"   буф1-",buf1[1],"   буф2-",buf2[1]);
   return;
  }
Files:
proverka.mq5  4 kb
prover__1.mq5  1 kb
 

So I'm back to my old ways)

If you get the indicator values through the tester, they will be different from the indicator values and from the historical data.

To check this, let's run prover.mq5 from 01.07.2010 on EURUSD for M1 period, watch the log and see the real prices.

 

Hello, I cannot understand the SymbolInfoSessionTrade() function, or rather the last two parameters - start of session and end of session. I can read in the help:


Allows to get time of start and time of end of specified trading session for specified symbol and day of week.

It turns out that to find out the start and end time of a trading session, I should already know the start and end time of the trading session (in seconds) - this is not consistent.

Документация по MQL5: Получение рыночной информации / SymbolInfoSessionQuote
Документация по MQL5: Получение рыночной информации / SymbolInfoSessionQuote
  • www.mql5.com
Получение рыночной информации / SymbolInfoSessionQuote - Документация по MQL5
 
kirill190982:

Hello, I can't understand SymbolInfoSessionTrade() function, more specifically the last two parameters - session start and session end. I've read in the help:

In these parameters, theSymbolInfoSessionTrade() function passes variables that will record the start and end time.

void OnTick()
  {
   datetime ld_start, ld_end;
   SymbolInfoSessionTrade(
   _Symbol,    // имя символа
   MONDAY,      // день недели
   0,           // Порядковый номер сессии
   ld_start,    // время начала сессии
   ld_end       // время окончания сессии
   );
   
   Print(ld_start," - ",ld_end);
  }

By the way, there is a mistake in help:

uintsession_index,// symbol name

 
ddd06:

In these parameters of theSymbolInfoSessionTrade() function, variables are passed in which the start and end times will be written.

Thank you I got it
 

I have simplified getting an error.

Here is an Expert Advisor that copies arrays of CLOSE prices

int bars,i;
void OnTick()
  {
   if(bars==Bars(_Symbol,_Period))return;
   bars=Bars(_Symbol,_Period);
   if(i>100)return;
   i++;  
   datetime time[];  
   double Arr1[],Arr2[];
   CopyTime(_Symbol,_Period,0,2,time);
   CopyClose("EURUSD",PERIOD_CURRENT, 0, 2, Arr1);
   CopyClose("GBPUSD",PERIOD_CURRENT, 0, 2, Arr2);
   Print("Время "+TimeToString(time[1],TIME_DATE|TIME_MINUTES),"  mas1(EURUSD)-",Arr1[1],"   mas2(GBPUSD)-",Arr2[1]);
   return;
  }

Let's run prover.mq5 from 01.07.2010 on EURUSD for M1 period, watch the log and see real prices

From time to time we see incorrect values

Moreover, till 01.00 the price of GBPUSD is freezing at 1.49393, after that it starts to run.

I've been suffering for a month and cannot test my multicurrency Expert Advisor

 
ddd06:

I have simplified getting an error.

Here is an Expert Advisor that copies arrays of CLOSE prices

Let's run prover.mq5 from 01.07.2010 on EURUSD for M1 period, watch the log and see real prices

And from time to time we see incorrect values

Moreover, till 01.00 the price of GBPUSD is freezing at 1.49393, after that it starts to run.

I have been suffering from this for a month and cannot test my multicurrency Expert Advisor

You are working with current values on an unfinished bar.

Try this

Print("Время "+TimeToString(time[0],TIME_DATE|TIME_MINUTES),"  mas1(EURUSD)-",Arr1[0],"   mas2(GBPUSD)-",Arr2[0]);

Or set the time series of the arrays.

 
stringo:

You are working with the current values on an unfinished bar.

Try it like this

Or set the time series of the arrays.

Continued
int bars,i;
void OnTick()
  {
   if(bars==Bars(_Symbol,_Period))return;
   bars=Bars(_Symbol,_Period);
   if(i>100)return;
   i++;  
   datetime time[];  
   double Arr1[],Arr2[];
   CopyTime(_Symbol,_Period,0,2,time);
   CopyClose("EURUSD",PERIOD_CURRENT, 0, 2, Arr1);
   CopyClose("GBPUSD",PERIOD_CURRENT, 0, 2, Arr2);
   Print("Время "+TimeToString(time[0],TIME_DATE|TIME_MINUTES),"  mas1(EURUSD)-",Arr1[0],"   mas2(GBPUSD)-",Arr2[0]);
   return;
  }

And you stubbornly refuse to answer why the quotes are at the beginning.

On EURUSD it seems to have started to match)

 

If that's the case, then you should keep 2 time arrays. Some times copy from EURUSD, others from GBPUSD

 
stringo:

If that's the case, then you should keep 2 time arrays. Some times should be copied from EURUSD, others from GBPUSD

Well.

int bars,i;
void OnTick()
  {
   if(bars==Bars(_Symbol,_Period))return;
   bars=Bars(_Symbol,_Period);
   if(i>100)return;
   i++;  
   datetime time1[],time2[];  
   double Arr1[],Arr2[];
   CopyTime("EURUSD",_Period,0,2,time1);
   CopyTime("GBPUSD",_Period,0,2,time2);
   CopyClose("EURUSD",PERIOD_CURRENT, 0, 2, Arr1);
   CopyClose("GBPUSD",PERIOD_CURRENT, 0, 2, Arr2);
   Print("Время EURUSD"+TimeToString(time1[0],TIME_DATE|TIME_MINUTES), "  Время GBPUSD"+TimeToString(time2[0],TIME_DATE|TIME_MINUTES),"    mas1(EURUSD)-",Arr1[0],"   mas2(GBPUSD)-",Arr2[0]);
   return;
  }

I don't think it should be like that, do you?

Reason: