When I try to divide the two doubles in a buffer my indicator blacks out, and the values go extreme in the second window -90000000 and 90000000
#property indicator_separate_window // Îòîáðàæåíèå â îòäåëüíîì îêíå
#property indicator_buffers 3 // Êîëè÷åñòâî áóôåðîâ
#property indicator_color1 Red // Öâåò ïåðâîé ëèíèè
#property indicator_color2 Blue // Öâåò âòîðîé ëèíèè
#property indicator_color3 Green
double FillBuffer[];
double DBuffer[];
double AverageBuffer[];
double H,L;
double point=Point();
int init() // Ñïåöèàëüíàÿ ôóíêöèÿ init()
{
int period = _Period;
string symbol = Symbol();
int digits = _Digits ;
point = _Point ;
if(digits == 5 || digits == 3) { digits = digits - 1 ; point = point * 10 ; }
SetIndexBuffer(0,DBuffer);
SetIndexBuffer(1,FillBuffer);
SetIndexBuffer(2,AverageBuffer);
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1);
SetIndexLabel(0, "ADR");
return(INIT_SUCCEEDED);
}
int start()
{
int i, limit, counted_bars;
counted_bars = IndicatorCounted();
//---- check for possible errors
if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
if (counted_bars>0) counted_bars--;
limit = Bars - counted_bars;
for (i = limit; i >= 0; i--)
{
double dbuff= iHigh(NULL,0,i)- iLow(NULL,0,i);
double D0 = iHigh(NULL,0,i+1)- iLow(NULL,0,i+1);
double D1 = iHigh(NULL,0,i+2)- iLow(NULL,0,i+2);
double D2 = iHigh(NULL,0,i+3)- iLow(NULL,0,i+3);
double D3 = iHigh(NULL,0,i+4)- iLow(NULL,0,i+4);
double D4 = iHigh(NULL,0,i+5)- iLow(NULL,0,i+5);
double Average = ((D0+D1+D2+D3+D4)/5)/point;
FillBuffer[i]=dbuff/Average;
}
return(0);
When I try to divide the two values in FillBuffer[]
my indicator blacks out. But if I just have either the dbuff
or Average
in the buffer it will show lines but I want the percentage one is of the other to be printed.
There is not much wrong with the code, but it does not paint the line:
Some polishing may help, but the core logic of the MQL4 Custom Indicator is forgotten in the code. If one does not assign a way, how to plot ( paint ) the line on screen, the GUI will remain "blacked-out" even though the values may have gotten calculated.
Performance warning:
Custom Indicators ( all Custom Indicators ) share one common solo-thread (!!), so proper performance tuning is warmly recommended in this type of MQL4-code-execution blocks.
Some further acceleration might be achieved by reducing / avoiding all the repetitive re-averaging via a sliding-window implementation replacement. While this is not so risky at 5-BARs deep re-processing, for deeper TimeSeries convolutions, the effect is significant and impressive in Strategy Tester accelerated mode of computing's run-times ( getting down to minutes instead of hours ). Worth one's time and efforts.