Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1101

 

I can't get indicator data from the high timeframe from the EA.

2019.07.22 07:23:02.556 Core 1  2017.10.05 07:00:00   Не удалось скопировать значения индикатора. Error =4806,  copied =-1

And during optimization it works. When I start to run it in the visualizer I get this error.

What is wrong with the indicator?

Files:
ind.mq5  11 kb
 
EgorKim:

I can't get indicator data from the high timeframe from the EA.

And during optimization it works. When I start to run it in the visualizer I get this error.

What is wrong with the indicator?

Where is the EA code?

The likely cause - in the path where indicator is located (written path to indicator in advisor through iCustom). Also, the indicator mq5 and ex5 file should be in the same folder.

 
EgorKim:

I can't get indicator data from the high timeframe from the EA.

And during optimization it works. When I start to run it in the visualizer I get this error.

What is wrong with the indicator?

So, your indicator is located in [date folder]\MQL5\Indicators\ind.mq5 , there is compiled file as well.

An example of an Expert Advisor that accesses the indicator buffer "0" - "Means":

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
//--- input parameters
input int      Input1=9;
//---
int    handle_iCustom;              // variable for storing the handle of the iCustom indicator /*
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create handle of the indicator iCustom
   handle_iCustom=iCustom(Symbol(),Period(),"ind");
//--- if the handle is not created 
   if(handle_iCustom==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code 
      PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early 
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double means[];
   ArraySetAsSeries(means,true);
   int start_pos=0,count=3;
   if(!iGetArray(handle_iCustom,0,start_pos,count,means))
      return;

   string text="Means:"+"\n";
   for(int i=count-1;i>=0;i--)
     {
      text=text+"#"+IntegerToString(i)+": "+DoubleToString(means[i],Digits())+"\n";
     }
   Comment(text);
  }
//+------------------------------------------------------------------+
//| Get value of buffers                                             |
//+------------------------------------------------------------------+
double iGetArray(const int handle,const int buffer,const int start_pos,const int count,double &arr_buffer[])
  {
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer))
     {
      Print("This a no dynamic array!");
      return(false);
     }
   ArrayFree(arr_buffer);
//--- reset error code 
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
   int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
   if(copied!=count)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(false);
     }
   return(result);
  }
//+------------------------------------------------------------------+

And the result in the tester:


and online:


Files:
Test.mq5  7 kb
 
Vladimir Karputov:

So, your indicator is located in [date folder]\MQL5\Indicators\ind.mq5 , there is compiled file as well.

An example of an Expert Advisor that accesses the indicator buffer "0" - "Means":

And the result in the tester:


And online:


I have no error in current timeframe .

The problem appears if I receive data from a higher timeframe.

Clearly the problem is in the indicator and not in my EA)

And there is no error in optimization mode. When you enable single pass and visualization - there is an error. The error...

Here is the topic of the same subject, as I understand it

https://www.mql5.com/ru/forum/190003

Не получается брать данные индикатора со старшего ТФ
Не получается брать данные индикатора со старшего ТФ
  • 2017.04.14
  • www.mql5.com
Уже четвёртый день в индикаторе пытаюсь получить данные стандартного индикатора АО со старшего таймфрейма, и всё никак...
 
EgorKim:

I have no errors on the current timeframe.

The problem appears if I get data from a higher timeframe.

The problem is clearly in the indicator, not in my EA)

And there is no error in optimization mode. When you enable single pass and visualization - there is an error. The error...

Here is the topic of the same subject, as I understand it

https://www.mql5.com/ru/forum/190003

You have no reference to the senior timeframe - its data is not kept up to date:
Проблема перевода с МТ4 на МТ5. Или, точнее, невозможность без'ошибочного исполнения некоторых алгоритмов в МТ5.
Проблема перевода с МТ4 на МТ5. Или, точнее, невозможность без'ошибочного исполнения некоторых алгоритмов в МТ5.
  • 2019.07.21
  • www.mql5.com
Сначала цитата из справочника языка MQL5. Рубрика Организация доступа к данным...
 

Put the indicator like this on the H1 chart with default parameters.

There is an error

Artyom Trishkin

I am asking for help what to fix in the indicator

Files:
ind2.mq5  22 kb
 
EgorKim:

I have no errors on the current timeframe.

The problem appears if I get data from a higher timeframe.

The problem is clearly in the indicator, not in my EA)

And there is no error in optimization mode. When you enable single pass and visualization - there is an error. The error...

Here is the topic of the same subject, as I understand it

https://www.mql5.com/ru/forum/190003

Here is a modification of COUNTER - you can set timeframe of indicator in parameters. Works both in tester and online.

//--- create handle of the indicator iCustom
   handle_iCustom=iCustom(Symbol(),Inp_period,"ind",
                          bars_IN,
                          SP,
                          N_Shift1,
                          Forecast,
                          kstd,
                          Oscilator,
                          N_Buff,
                          Ka,
                          La,
                          Za,
                          Oe,
                          Me,
                          DIGf);
Files:
Test.mq5  10 kb
 
Vladimir Karputov:

Here is a modification of the COUNTER - you can set the timeframe of the indicator in the parameters. It works in the tester and online.

How then can we explain that the Expert Advisor trades during optimization? And in the visualization there is not a single trade?

 
EgorKim:

How then can it be explained that during optimization the Expert Advisor trades. And during visualization there are no trades?

What is the condition for opening a position (indicator buffer number and bar number)?

 
Vladimir Karputov:

What is the condition for opening a position (indicator buffer number and bar number)?

Like this.

And some optimizer passes coincide in the visualizer.

And some passes have not a single trade at all

double price1=0.0;
price1=iCustomGet(handle_ind,1,0)
double price2=0.0;
price2=iCustomGet(handle_ind,2,0)
double open=0.0;   
double open          = iOpen(Symbol(),Period(),0);

   if(price1!=0.0 && price2!=0.0 && open!=0.0)
     {
      if(open<price1)
        {
         buy
        }
      if(open>price2)
        {
         sell
        }
      }
//+------------------------------------------------------------------+
//| Get value of buffers for the iCustom                             |
//|  the buffer numbers are the following:                           |
//+------------------------------------------------------------------+
double iCustomGet(int handle,const int buffer,const int index)
  {
   double Custom[1];
//--- reset error code 
   ResetLastError();
//--- fill a part of the iCustom array with values from the indicator buffer that has 0 index 
   if(CopyBuffer(handle,buffer,index,1,Custom)<0)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the iCustom indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(0.0);
     }
   return(Custom[0]);
  }
//+------------------------------------------------------------------+

I think the problem is in the indicator.

And as Artem has rightly pointed out, the problem is in the actual data.

It just does not want to tell me how to do it)