Problem with ICustom and ZigZag

 

Некоторое время назад я написал роботов. Это сработало. Но сейчас не работает. Я добавил индикатор ZigZag, но в буфере всегда получается 0. Почему это произошло?

 int    handle_iCustom;
 double Buffer1[];
 input int InpDepth = 12 ;
 input int InpDeviation = 5 ;
 input int InptBackstep = 3 ;
 input int InpCandlesCheck = 100 ;
 handle_iCustom= iCustom ( _Symbol , _Period , "Examples\ZigZag\ZigZag" ,InpDepth,InpDeviation,InptBackstep);
   if (handle_iCustom== INVALID_HANDLE )
     {
       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 );
     } 
int copy = CopyBuffer (handle_iCustom, 0 , 0 ,InpCandlesCheck,Buffer1);
 for ( int i= 0 ;i<InpCandlesCheck;i++){
       Print ( IntegerToString (Buffer1[i])); # there always zero
       if (Buffer1[i]!= 0.0 ){
         # there nothing because 0 
      }
    }
 
Сергей Шишка:

Некоторое время назад я написал роботов. Это сработало. Но сейчас не работает. Я добавил индикатор ZigZag, но в буфере всегда получается 0. Почему это произошло?

Индикатор ZigZag в своих буерах содержит много пустых значений (это как правило или '0.0' или 'EMPTY_VALUE').

Пример получения данных с индикатора ZigZag:

Forum on trading, automated trading systems and testing trading strategies

How to start with MQL5

Vladimir Karputov, 2018.12.27 11:32

An example of working with the ZigZag indicator

Code: ZigZag Example.mq5

Pay attention to the extremum search algorithm: if the value in the indicator buffer is not equal to "0.0" and not equal to "PLOT_EMPTY_VALUE" - it means that We have detected an extremum.


The extremum search goes to " ZigZag: how many candles to check back " bars.


Algorithm of work standard: ONCE in OnInit () we create an indicator.

//---
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(),"Examples\\ZigZag",InpDepth,InpDeviation,InptBackstep);
//--- 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);
  }


Next in OnTick (), we make a copy of the indicator data, while using the indicator handle.

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   static long counter=0;
   counter++;
   if(counter>=15)
      counter=0;
   else
      return;
//---
   double ZigzagBuffer[];
   ArraySetAsSeries(ZigzagBuffer,true);
   int start_pos=0,count=InpCandlesCheck+1;
   if(!iGetArray(handle_iCustom,0,start_pos,count,ZigzagBuffer))
      return;

   string text="";
   for(int i=0;i<count;i++)
     {
      if(ZigzagBuffer[i]!=PLOT_EMPTY_VALUE && ZigzagBuffer[i]!=0.0)
         text=text+"\n"+IntegerToString(i)+": "+DoubleToString(ZigzagBuffer[i],Digits());
     }
   Comment(text);
  }


The function by which the data is copied indicator:

//+------------------------------------------------------------------+
//| 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);
  }


Result of work:

An example of working with the ZigZag indicator


 
Сергей Шишка:

Некоторое время назад я написал роботов. Это сработало. Но сейчас не работает. Я добавил индикатор ZigZag, но в буфере всегда получается 0. Почему это произошло?

Если совет не сработал или другие причины - есть вариант зигзага как процедуры для вставки.

 
Vladimir Karputov:

Индикатор ZigZag в своих буерах содержит много пустых значений (это как правило или '0.0' или 'EMPTY_VALUE').

Пример получения данных с индикатора ZigZag:




 


Я пробовал большее количество свечей,но результат тот же. Хотя с загрузкой самого индикатора проблем нет.


тут же скрипт проверяет,что если не равен нулю


if (Buffer1[i]!= 0.0 ){
         # there nothing because 0 
 

странный путь к зигзагу, если это стандартный в мт5. то он по другому пути. Ну ладно. 

далее

if (Buffer1[i]!= 0.0 ){

Указывайте 

if (Buffer1[i]>0 ){

путь к папке через \\


в общем так все ок:

#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
int    handle_iCustom;
double Buffer1[];
input int InpDepth = 12;
input int InpDeviation = 5;
input int InptBackstep = 3;
input int InpCandlesCheck = 100;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
 handle_iCustom= iCustom(_Symbol, _Period, "Examples\\ZigZag",InpDepth,InpDeviation,InptBackstep);
   if(handle_iCustom== INVALID_HANDLE)
     {
      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()
  {

  
   int copy = CopyBuffer(handle_iCustom, 0, 0,InpCandlesCheck,Buffer1);
   for(int i= 0 ; i<InpCandlesCheck; i++)
     {
      if(Buffer1[i]>0)
        {
      Print("i="+i+" "+DoubleToString(Buffer1[i]));    //# there always zero
        }
     }
  }
//+------------------------------------------------------------------+
Причина обращения: