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)
I've used this code from official mql4 book. I've used it before without any problem.
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.
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().
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()?
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
*****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.