# Max drop in pips on a specific bar duration

24

Hello,

I am trying to create an indicator which can calculate the max drop in pips over the last 200 bars.  I am attaching an example.

I have code this, but unfortunately the indicator is a stable price at 0. Could anyone help me please?

```int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

for(i=limit-1; i>=0; i--) {
k=0;
for (j=i+199; j>=i; j--) {
AH[k]=iHigh(NULL,0,j);
AL[k]=iLow(NULL,0,j);
k=k+1; }
differ=0;
for (m=0; m>=199; m++) {
for (n=m; n>=199; n++) {

diff=(AH[m] - AL[n]);
if (diff>differ) differ=diff; } }
ExtMapBuffer3[i]=differ;

}

return(0);

}```

Files:
17954

algohnv: I am trying to create an indicator which can calculate the max drop in pips over the last 200 bars
1. That isn't what your code is doing. It is finding the largest single bar.
2. ```int iLow  =  iLowest(_Symbol, PERIOD_CURRENT, MODE_LOW, 200, 0);
int iHigh = iHighest(_Symbol, PERIOD_CURRENT, MODE_High, 200-iLow+1, iLow);
ExtMapBuffer3[i]=High[iHigh] - Low[iLow];```
24

whroeder1:
1. That isn't what your code is doing. It is finding the largest single bar.

Thank for your help. I tried your code but it seems that it doesnt work.

```int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

for(i=limit-1; i>=0; i--) {
int iLow  =  iLowest(NULL, 0, MODE_LOW, 100, i);
int iHigh = iHighest(NULL, 0, MODE_HIGH, 100-iLow+1, iLow);

ExtMapBuffer3[i]=High[iHigh] - Low[iLow]; }
```

* I set the last 100 bars because I am attaching an example that shows that it doesnt work

Files:
17954

1.  Play video Please edit your post. For large amounts of code, attach it

2. Don't post a link to or attach a image, just insert the image
3. ```for(i=limit-1; i>=0; i--)
int iLow  =  iLowest(NULL, 0, MODE_LOW, 100, i);
int iHigh = iHighest(NULL, 0, MODE_HIGH, 100-iLow+1, iLow);
ExtMapBuffer3[i]=High[iHigh] - Low[iLow];```
Where are your braces for the loop?
4. Try
```    for(i=limit-1; i>=0; i--){
int iHigh = iHighest(_Symbol, PERIOD_CURRENT, MODE_HIGH, 100, i);
ExtMapBuffer3[i]=High[iHigh] - Low[i];
}
```
24

whroeder1:
1.  Please edit your post. For large amounts of code, attach it

2. Don't post a link to or attach a image, just insert the image
3. Where are your braces for the loop?
4. Try

Thanks for your reply. I edit the code on my previous posts and I add the braces to the loop of my last post. I tried your code and the compiler returns me the error; " 'max_extreama' - function not defined "

17954

 algohnv: compiler returns me the error; " 'max_extreama' - function not defined " I was still typing.
24

whroeder1:
1.  Please edit your post. For large amounts of code, attach it

2. Don't post a link to or attach a image, just insert the image
3. Where are your braces for the loop?
4. Try

The new code that you have on step 4, calculates only the highest price of the last 100 bars minus the low of the current bar. It doesnt calculate the max drop on the last 100 bars
17954

 algohnv:  It doesnt calculate the max drop on the last 100 bars That is the max drop for that bar. Add another buffer and compute the maximum of the maximum.
24

whroeder1:
 That is the max drop for that bar. Add another buffer and compute the maximum of the maximum.

I am not sure what do you mean. On my first post I had 2 matrixes and I tried that, but I cannot understand why it doesnt work. Could you explain me please what you mean?
24

Could anyone help, please? In my first post that I have the code, the result is a flat line. It seems that mt4 cannot do calculations between 2 tables (subtractions)