# Problem with code-wont work in an EA 118

Hi guys, I'm trying to code the double bottom chart pattern using fractals, and although the compiler says there are no errors, it doesnt seem to work in an EA. can you help me figure out whats wrong?

```bool doublebottom()
{
double val1,val2,v1[],v2[];
double Lows[],Highs[];
double highshift[],lowshift[];
double p1[],p2[]; //these can tell me what the shift value is
int a=1;
int b=1;
for(int i=1;i<100;i++)
{
val1 = iFractals(NULL, 0, MODE_UPPER, i);
//----
if(val1 > 0)
{    //always use brackets with if statements!! it makes things alot easier
v1[i] = High[i];   //so if an upper fractal exists, we assign the high value to the buffer to draw it there.
highshift[i]=i;   // if we have an upperfractal, we are recording the shift.
}
else
{
v1[i] = v1[i+1];    //otherwise, we use the previous fractal level.
highshift[i]=0;   //if fractal doesnt exist, then we assign value 0.
}
val2 = iFractals(NULL, 0, MODE_LOWER, i);  //same as above, except its lower fractals.
//----
if(val2 > 0)
{
v2[i] = Low[i];
lowshift[i]=i;
}
else
{
v2[i] = v2[i+1];
lowshift[i]=0;
}
while (a<=15)
{
if(highshift[i]>0) //so if we know the fractal occured at shift i, then
{              //shift highshift[i] is equal to i, which is greater than 0
Highs[a]=v1[i]; //then we assign the Ath value of Highs to be the fractal value at that shift
p1[a]=i;  // we obtained the shift value of the fractal (so what bar it was at.)
a++;        //we add to the index so that we can get up to the last 15 fractals.
}
}
while (b<=15)
{
if(lowshift[i]>0)  //remember these are lower fractals.
{
Lows[b]=v2[i];
p2[b]=i;
b++;
}
}
}

return(Lows>Lows&&(Highs-Lows)>40*Point&&(p2-p2)>5&&p2<p1<p2);

}   ``` 247

probably you use indicator buffers, which is not possible in an EA. 17374

1mathboy1:

Hi guys, I'm trying to code the double bottom chart pattern using fractals, and although the compiler says there are no errors, it doesnt seem to work in an EA. can you help me figure out whats wrong?

<CODE REMOVED>

Please edit your post . . . please use the SRC button to post code: How to use the SRC button. 24704

```double val1,val2,v1[],v2[];
double Lows[],Highs[];
double highshift[],lowshift[];
double p1[],p2[]; //these can tell me what the shift value is
:
{ //always use brackets with if statements!! it makes things alot easier
v1[i] = High[i]; //so if an upper fractal exists, we assign the high value to the buffer to draw it there.```
How many elements does v1 have when you assign to v1[i]? 118

WHRoeder:
How many elements does v1 have when you assign to v1[i]?

99 since i goes from 1 to 99. but it can be arbitrary. I just need enough bars to have 2 lower fractals and 1 upper fractal in between them. 118

RaptorUK:
Please edit your post . . . please use the SRC button to post code: How to use the SRC button.

Thanks for the tip. I corrected it. 24704

1mathboy1:

99 since i goes from 1 to 99. but it can be arbitrary. I just need enough bars to have 2 lower fractals and 1 upper fractal in between them.
Wrong. v1[] has ZERO. "i" is irrelevant. 118

WHRoeder:
Wrong. v1[] has ZERO. "i" is irrelevant.

why? I thought whenever v[i]=something I am assigning a value to the ith element of the array. I used code from the support and resistance indicator, which runs fine.

```//+------------------------------------------------------------------+
//|                                          Support and Resistance  |
//|                                 Copyright © 2004  Barry Stander  |
//|                          http://myweb.absa.co.za/stander/4meta/  |
//+------------------------------------------------------------------+
#property copyright "Click here: Barry Stander"
#property link      "http://myweb.absa.co.za/stander/4meta/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- buffers
double v1[];
double v2[];
double val1;
double val2;
int i;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexArrow(0, 119);     //first number is the line index, which is from 0 to 7. so we can have up to 8 different things drawn
SetIndexArrow(1, 119);     //from one indicator. the second number is the code for the symbol.
//----
SetIndexStyle(0, DRAW_ARROW, STYLE_DOT, 1);   //describes what and how the line will be drawn
SetIndexDrawBegin(0, i-1);    //2nd number refers to the first bar where it will be drawn.
SetIndexBuffer(0, v1);     //basically assigns the double values from the array v1 to the buffer
SetIndexLabel(0,"Resistance");  //basically labelling our buffer
//----
SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,1);
SetIndexDrawBegin(1,i-1);
SetIndexBuffer(1, v2);
SetIndexLabel(1,"Support");
//----
return(0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
{
i = Bars;     //number of bars in current chart. it means we will apply the indicator to all the bars in chart.
while(i >= 0)
{
val1 = iFractals(NULL, 0, MODE_UPPER, i);
//----
if(val1 > 0)
v1[i] = High[i];   //so if an upper fractal exists, we assign the high value to the buffer to draw it there.
else
v1[i] = v1[i+1];    //otherwise, we use the previous fractal level.
val2 = iFractals(NULL, 0, MODE_LOWER, i);  //same as above, except its lower fractals.
//----
if(val2 > 0)
v2[i] = Low[i];
else
v2[i] = v2[i+1];
i--;
}
return(0); //we basically return an arbitrary value like 0 because thats how the function has to be written.
}
//+------------------------------------------------------------------+``` 24704

1mathboy1:

why? I thought whenever v[i]=something I am assigning a value to the ith element of the array. I used code from the support and resistance indicator, which runs fine.

You are assigning it to the ith element IF the array has i elements. You declared the arrays as zero length. Either the original code resized the array or the array was originally a indicator buffer (autoresizing to Bars) 118

WHRoeder:

You are assigning it to the ith element IF the array has i elements. You declared the arrays as zero length. Either the original code resized the array or the array was originally a indicator buffer (autoresizing to Bars)

Ok got it. so if I wanted an array with 100 elements, I would write

double v1;

right? Ok I did that. I have it in an EA, so that I buy when the pattern shows up. But when I press start for backtesting, nothing seems to happen. I'm not sure if the EA just takes a really really long time to load, or if its something else. I pressed start and waited 20 minutes, but the progress bar is not moving at all. 17374

1mathboy1:

Ok got it. so if I wanted an array with 100 elements, I would write

double v1;

right? Ok I did that. I have it in an EA, so that I buy when the pattern shows up. But when I press start for backtesting, nothing seems to happen. I'm not sure if the EA just takes a really really long time to load, or if its something else. I pressed start and waited 20 minutes, but the progress bar is not moving at all.

Sounds like you have an infinite loop, in the Strategy Tester the speed of your start() function governs the speed at which the Tester runs, if start() never ends you never get the next tick . .