# calculating lowest/highest indicator values over a certain period

29

Hi,

I'm trying to create a custom indicator that calculates the lowest highs and highest lows over a certain period and shows it on the chart as a line.

It's based on an arrow indicator I've created myself that shows dots as support and resistance until a new high/low is formed. (you can replace it by iFractals() with a few changes beceause fractals aren't always seen on the chart)

The idea is to show two lines: line 1 at 50period lowest high and line 2 at 50period highest low. I just couldn't get it right. And I know it should be EASY...

Thanks!

```//+------------------------------------------------------------------+
//|                                                                  |
//|        1BRKR                                                     |
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
input int PER     =50;                 //period
input int history =3000;

double high[]; 				//indicator value of arrow indicator
double low[];
double LowestHigh;
double HighestLow;
double HighLine[];			//array for LowestHigh and HighestLow
double LowLine[];
int i;

void init()
{

SetIndexBuffer(0,HighLine);
SetIndexStyle(0,DRAW_LINE,2,2);
SetIndexEmptyValue(0,0.0);

SetIndexBuffer(1,LowLine);
SetIndexStyle(1,DRAW_LINE,2,2);
SetIndexEmptyValue(1,0.0);

return;
}

int start()
{
LowestHigh=iCustom(NULL,0,"MS_SR",0,0);            //assigning latest high and low as highesthigh and lowestlow
HighestLow=iCustom(NULL,0,"MS_SR",1,0);
i=history;
while(i>=0)
{
for (int cnt=0;cnt<PER;cnt++)                      //loop for determining lowesthigh and highestlow
{  high[cnt]=iCustom(NULL,0,"MS_SR",0,cnt);
low[cnt]=iCustom(NULL,0,"MS_SR",1,cnt);
if (LowestHigh>high[cnt])LowestHigh=high[cnt];
if (HighestLow<low[cnt])HighestLow=low[cnt];
}
HighLine[cnt]=LowestHigh;                         //assigning 50period highs and lows to indicator array
LowLine[cnt]=HighestLow;
i--;
}
return(0);
}

//+------------------------------------------------------------------+
```
Moderator
12229

```double STH[];
double STL[];
double LBRKR;
double SBRKR;
double BRKR_L[];
double BRKR_S[];```

Use descriptive variable names so that others can easier understand what you are trying to do.

You are more likely to get help then.

29

Keith Watford:

Use descriptive variable names so that others can easier understand what you are trying to do.

You are more likely to get help then.

Thanks! I think it should be more readable now.
253

I do not know exactly what you are trying to do, but I think that this may be good.

```int start()
{
int cnt, i=history-PER;
double price_high, price_low;
//LowestHigh=iCustom(NULL,0,"MS_SR",0,0);            //assigning latest high and low as highesthigh and lowestlow
//HighestLow=iCustom(NULL,0,"MS_SR",1,0);
//i=history;

while(i>=0)
{
LowestHigh=iCustom(NULL,0,"MS_SR",0,i);
HighestLow=iCustom(NULL,0,"MS_SR",1,i);

//for(int cnt=0;cnt<PER;cnt++) //loop for determining lowesthigh and highestlow
for(cnt=1;cnt<PER;cnt++)
{
//high[cnt]=iCustom(NULL,0,"MS_SR",0,cnt);
//low[cnt]=iCustom(NULL,0,"MS_SR",1,cnt);
price_high=iCustom(NULL,0,"MS_SR",0,i+cnt);
price_low =iCustom(NULL,0,"MS_SR",1,i+cnt);

//if(LowestHigh>high[cnt])LowestHigh=high[cnt];
//if(HighestLow<low[cnt])HighestLow=low[cnt];
if(LowestHigh>price_high)
LowestHigh=price_high;

if(HighestLow<price_low)
HighestLow=price_low;
}

//HighLine[cnt]=LowestHigh;                         //assigning 50period highs and lows to indicator array
//LowLine[cnt]=HighestLow;
HighLine[i]=LowestHigh;
LowLine[i] =HighestLow;

i--;
}

return(0);
}```
29

I do not know exactly what you are trying to do, but I think that this may be good.

Thank you! This is what I've been trying to accomplish.

I've tried another solution yesterday...

```int start()
{
i=history;
for (int cnt=history-1;cnt>=0;cnt--)                      //loop for determining lowesthigh and highestlow
{  high[cnt]=iCustom(NULL,0,"MS_SR",0,cnt);
low[cnt]=iCustom(NULL,0,"MS_SR",1,cnt);
HighLine[cnt]=high[ArrayMinimum(high,PER,cnt)];
LowLine[cnt]=low[ArrayMaximum(low,PER,cnt)];
}
return(0);
}
```

but this is giving me problems when I implement the indicator into an EA

"incorrect start position for ArrayMaximum function"

253

but this is giving me problems when I implement the indicator into an EA

"incorrect start position for ArrayMaximum function"

Maybe buffers are not prepared.

29

Maybe buffers are not prepared.

what do you mean with that? can you explain?
253

what do you mean with that? can you explain?

You defined 4 arrays in the 1st post, but only 2 buffers were prepared.

29

You defined 4 arrays in the 1st post, but only 2 buffers were prepared.

they were all prepared... but the error still occurs...

```//+------------------------------------------------------------------+
//|                                                                  |
//|        1BRKR                                                     |
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
input int PER     =50;                 //period
input int history =3000;

double high[];
double low[];
double HighLine[3000];
double LowLine[];
int i;

void init()
{

SetIndexBuffer(0,HighLine);
SetIndexStyle(0,DRAW_LINE,2,2);
SetIndexEmptyValue(0,0.0);

SetIndexBuffer(1,LowLine);
SetIndexStyle(1,DRAW_LINE,2,2);
SetIndexEmptyValue(1,0.0);

SetIndexBuffer(2,high);
SetIndexStyle(2,EMPTY,EMPTY,EMPTY,clrNONE);
SetIndexBuffer(3,low);
SetIndexStyle(3,EMPTY,EMPTY,EMPTY,clrNONE);
return;
}

int start()
{
i=history;
for (int cnt=history-1;cnt>=0;cnt--)                      //loop for determining lowesthigh and highestlow
{  high[cnt]=iCustom(NULL,0,"MS_SR",0,cnt);
low[cnt]=iCustom(NULL,0,"MS_SR",1,cnt);
HighLine[cnt]=high[ArrayMinimum(high,PER,cnt)];
LowLine[cnt]=low[ArrayMaximum(low,PER,cnt)];
}
return(0);
}

//+------------------------------------------------------------------+
```
Moderator
103886