How to call zigzag inidcator in ea?

 

I  have used  iCustom() to call ZigZag indicator but get some problem, 

 In OnInit() function the code like this:  

   if(m_handle_indicator==INVALID_HANDLE)
      if((m_handle_indicator=iCustom(NULL,PERIOD_CURRENT,"Examples\\ZigZag",InpDepth,InpDeviation,InpBackstep))==INVALID_HANDLE)
        {
         printf("Error creating iCustom indicator");
         return(false);
        }

the m_handle_indicator get 0, means it is created successful...

 

but when I try to read the buffer:

 In OnTick() function 

   if(BarsCalculated(m_handle_indicator)<110) 
      {
         printf("error BarCalculate = %d ",BarsCalculated(m_handle_indicator));
         return(false);
      }  

 

it return error message:"error BarCalculate = -1"


Something wrong in my code??? 

 
xhxiang:

I  have used  iCustom() to call ZigZag indicator but get some problem, 

 In OnInit() function the code like this:  

the m_handle_indicator get 0, means it is created successful...

 

but when I try to read the buffer:

 In OnTick() function 

 

it return error message:"error BarCalculate = -1"


Something wrong in my code??? 

You have to let some times to the indicator to be calculated, see the example in the documentation :

      for(i=0;i<100;i++)
        {
         if(BarsCalculated(m_handle_indicator)>0)
            break;
         Sleep(50);
        }


 
angevoyageur:

You have to let some times to the indicator to be calculated, see the example in the documentation :


I have add the code as you said ...but nothing change. It still return -1 by BarCalculated()
 
xhxiang:
I have add the code as you said ...but nothing change. It still return -1 by BarCalculated()

It works for me :

   int m_handle_indicator=INVALID_HANDLE;
   if(m_handle_indicator==INVALID_HANDLE)
      if((m_handle_indicator=iCustom(NULL,PERIOD_CURRENT,"Examples\\ZigZag",12,5,3))==INVALID_HANDLE)
        {
         printf("Error creating iCustom indicator");
         return;
        }
   Print("Handle :",m_handle_indicator);
   for(int i=0;i<100;i++)
     {
      if(BarsCalculated(m_handle_indicator)>0)
         break;
      Sleep(50);
     }
   printf("BarCalculate = %d ",BarsCalculated(m_handle_indicator));

results :

2013.07.03 13:50:40    test (EURUSD,H1)    BarCalculate = 10183
2013.07.03 13:50:40    test (EURUSD,H1)    Handle :10

 
angevoyageur:

It works for me :

results :

2013.07.03 13:50:40    test (EURUSD,H1)    BarCalculate = 10183
2013.07.03 13:50:40    test (EURUSD,H1)    Handle :10

i think something wrong in this line:

 

if((m_handle_indicator=iCustom(NULL,PERIOD_CURRENT,"Examples\\ZigZag",InpDepth,InpDeviation,InpBackstep))==INVALID_HANDLE)

 

if i change"Examples\\ZigZag" to anything else(i means even to give a wrong name) ,it also return 0 .

 

I have found the bug finally :

Init the m_handle_indicator first ,and all the things works properly.

 

   m_handle_indicator=INVALID_HANDLE;

thanks all. 

Get in touch with developers using Service Desk!
Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.
 
xhxiang:

I have found the bug finally :

Init the m_handle_indicator first ,and all the things works properly.

 

thanks all. 

This is exactly what I showed you in the code I provided
Reason: