Problem in using iCustom (Problem Solved)

 

*****Problem Solved : Answer in #7 comment).*****

---------------------------------------------------------------------------

Hey. I want to use iCustom to take ZigZag data for my variables. But after applying it to metatrader, it hangs up (not responding mode) and I have to close it.


Mentioned part of my code is here. I need Zig, HZig, and LZig for making an custom indicator and I will use them in other parts of the program. 

What is the problem? why client terminal hangs up? how should i correct it? I need 0, 1 and 2 mode of ZigZag indicator. Is there a way to capture it?


Thanks.

void start()                         // Special function start()
  {
     int i,                           // Bar index
       Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Number of counted bars
   i=Bars-Counted_bars-1;           // Index of the first uncounted
//---------------------------------------------------------------------

   while(i>=0)                      // Loop for uncounted bars
     {
//+------------------------------------------------------------------+
//| Local Variables                                                  |
//+------------------------------------------------------------------+    
double Zig = iCustom(NULL,0,"ZigZag",12,5,3,0,i);
double HZig = iCustom(NULL,0,"ZigZag",12,5,3,1,i);
double LZig = iCustom(NULL,0,"ZigZag",12,5,3,2,i);

//+------------------------------------------------------------------+
//| Main Part of Program                                             |
//+------------------------------------------------------------------+    


}
   return;
}
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
 
s115rz:

Hey. I want to use iCustom to take ZigZag data for my variables. But after applying it to metatrader, it hangs up (not responding mode) and I have to close it.


Mentioned part of my code is here. I need Zig, HZig, and LZig for making an custom indicator and I will use them in other parts of the program. 

What is the problem? why client terminal hangs up? how should i correct it? I need 0, 1 and 2 mode of ZigZag indicator. Is there a way to capture it?


Thanks.

While(I>=0) 
Looks infinite to me.  Nothing there to change i
 
That plus the fact that ZigZag only has one buffer.
 
Paul Anscombe:
While(I>=0) 
Looks infinite to me.  Nothing there to change i

I've used this code from official mql4 book. I've used it before without any problem.

 
Always post all relevant code.
 
William Roeder:
That plus the fact that ZigZag only has one buffer.

Original ZigZag code have 3 buffer but shows 1. with some modification on ZigZag code, I printed its information on the chart and I found it really has 3 buffer.

Also I have this problem with its first buffer. and even other indicators (For example iMA) while I've used this method before without any problem.

 

lippmaje:
Always post all relevant code.

#property copyright "Sam"
#property link      
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red


//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
double Buf_Buy[],Buf_sell[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init()                          // Special function init() 
  {
   SetIndexBuffer(0,Buf_Buy);         // Assigning an array to a buffer
   SetIndexStyle (0,DRAW_HISTOGRAM,STYLE_SOLID,2);// Line style
   SetIndexBuffer(1,Buf_sell);
   SetIndexStyle (1,DRAW_HISTOGRAM,STYLE_SOLID,2);// Line style
   return;                          // Exit the special funct. init()
  }

  
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
  
//---------------------------------------------------------------------
void start()                         // Special function start()
  {
     int i,                           // Bar index
       Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Number of counted bars
   i=Bars-Counted_bars-1;           // Index of the first uncounted
//---------------------------------------------------------------------

   while(i>=0)                      // Loop for uncounted bars
     {
//+------------------------------------------------------------------+
//| Local Variables                                                  |
//+------------------------------------------------------------------+    
double Zig = iCustom(NULL,0,"ZigZag",12,5,3,0,i);
double HZig = iCustom(NULL,0,"ZigZag",12,5,3,1,i);
double LZig = iCustom(NULL,0,"ZigZag",12,5,3,2,i);

//+------------------------------------------------------------------+
//| Main Part of the Program                                         |
//+------------------------------------------------------------------+    

Buf_Buy[i] = Zig;
Buf_sell[i] = HZig;
}
   return;
}

May be it can clarify.

 
s115rz:

May be it can clarify.

WOW. I just forgot to add an i--; in the end.

The problem solved.

Thanks you for your hints. guided me to the right point.

 

What happens if Counted_bars equals Bars? Your indicator would not update the current bar until it's been closed.

Also I'd drop start() in favor of OnCalculate().

 
lippmaje:

What happens if Counted_bars equals Bars? Your indicator would not update the current bar until it's been closed.

Also I'd drop start() in favor of OnCalculate().

I will Check the first issue.

But what is the differences between start() and OnCalculate()?

What is the advantages of OnCalculate()?

 
s115rz:

What is the advantages of OnCalculate()?

start() is deprecated and only supported for legacy code, like extern inputs.

You should adopt to the new handlers, use prev_calculated instead of IndicatorCounted() etc pp. It's all in the documentation.