Why won't anything draw? Sometimes this indicator has crashed MT4

 

I'm trying to plot pivot points, their resistances, and supports as graphs (similar to that of moving averages) for any period (based off a bar's predecessor), so I can find such for any bar, at any given time. Basically the purpose is to find what supports and resistances based off pivot points would have been in the past for any given bar. Below is my code; why won't it draw the lines? Sometimes when I choose it as an indicator, nothing happens and MT4 freezes. What is wrong with my code? Surely this isn't so complex MT4 can't handle it!

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 DarkBlue
#property indicator_color2 Blue
#property indicator_color3 DodgerBlue
#property indicator_color4 White
#property indicator_color5 DarkOrange
#property indicator_color6 OrangeRed
#property indicator_color7 Red

double Resistance3[];
double Resistance2[];
double Resistance1[];
double PivotPoint[];
double Support1[];
double Support2[];
double Support3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(7);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Resistance3);
SetIndexDrawBegin(0,0);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Resistance2);
SetIndexDrawBegin(1,0);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,Resistance1);
SetIndexDrawBegin(2,0);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,PivotPoint);
SetIndexDrawBegin(3,0);
SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(4,Support1);
SetIndexDrawBegin(4,0);
SetIndexStyle(5,DRAW_LINE);
SetIndexBuffer(5,Support2);
SetIndexDrawBegin(5,0);
SetIndexStyle(6,DRAW_LINE);
SetIndexBuffer(6,Support3);
SetIndexDrawBegin(6,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(int i=0;i<limit;i++)
PivotPoint[i] = (High[i+1]+Low[i+1]+Close[i+1])/3;
Resistance3[i] = PivotPoint[i]+PivotPoint[i]-Low[i+1]-Low[i+1]+High[i+1];
Resistance2[i] = PivotPoint[i]+High[i+1]-Low[i+1];
Resistance1[i] = PivotPoint[i]+PivotPoint[i]-Low[i+1];
Support1[i] = PivotPoint[i]+PivotPoint[i]-High[i+1];
Support2[i] = PivotPoint[i]-High[i+1]+Low[i+1];
Support3[i] = PivotPoint[i]+PivotPoint[i]-High[i+1]-High[i+1]+Low[i+1];
//----
return(0);
}
//+------------------------------------------------------------------+

 
limit=Bars-counted_bars;


where is "Bars" declared and which value has it ? zero ?

as far as i can see, the script wouldnt even compile...

 

"Bars" is not a problem, but you need brackets around the for-loop block:


for(int i=0;i<limit;i++)

{ // open bracket here
PivotPoint[i] = (High[i+1]+Low[i+1]+Close[i+1])/3;
Resistance3[i] = PivotPoint[i]+PivotPoint[i]-Low[i+1]-Low[i+1]+High[i+1];
Resistance2[i] = PivotPoint[i]+High[i+1]-Low[i+1];
Resistance1[i] = PivotPoint[i]+PivotPoint[i]-Low[i+1];
Support1[i] = PivotPoint[i]+PivotPoint[i]-High[i+1];
Support2[i] = PivotPoint[i]-High[i+1]+Low[i+1];
Support3[i] = PivotPoint[i]+PivotPoint[i]-High[i+1]-High[i+1]+Low[i+1];
} // close bracket here

 
blogzr3:

"Bars" is not a problem, but you need brackets around the for-loop block:

Actually, That needs to be changed so you don't reference the non-existent High[Bars]

limit=Bars -1 -counted_bars;
 
meikel:


where is "Bars" declared and which value has it ? zero ?

as far as i can see, the script wouldnt even compile...

Predefined variables, Bars, Digits, High[], etc

 
WHRoeder:

Predefined variables, Bars, Digits, High[], etc

yes. i missed that because he dont uses the SRC function to embed the code.

 
meikel wrote >>

yes. i missed that because he dont uses the SRC function to embed the code.

Thanks to you all; fortunately, I may have found a simpler system to construct than all of this. I'm learning so much!