# An other Use of close[ ]

11

Hi to all! I have a simple question. I need in my ea to enter buy, for example, if ALL the last 3 candles are Above a moving average.

Example:

If ((Close[1]&&Close[2]&&Close[3])>ima(......))

Is there another method instead of out all this close&&..?

Like Close[1+2+3]?

Manu Hanks to you
20105

1. ```If ((Close[1]&&Close[2]&&Close[3])>ima(......))
```

Bogus. True = non-zero and false = zero so you get true && true && Close[3]>ima

 ```if( 3 < 2 < 1 ) if( false < 1 ) if(     0 < 1 ) if(     true  )``` ```if( 3 > 2 > 1 ) if(  true > 1 ) if(     1 > 1 ) if(     false ) ```

2. Like Close[1+2+3]?
Equivalent to Close[6]

3. There are no short cuts. Try one of these:
```if (Close[1])>iMA(…)
&&  Close[2])>iMA(…)
&&  Close[3])>ima(…)) …
```
```double ma=iMA(…);
if (Close[1])>ma
&&  Close[2])>ma
&&  Close[3])>ma) …
```
```template<typename T>
T MathMax(T a, T b, T c){ return MathMax(a, MathMax(b, c)); }
⋮
if (MathMAx(Close[1], Close[2], Close[3]) > iMA(…)) …```

910

William Roeder:
1. Bogus. True = non-zero and false = zero so you get true && true && Close[3]>ima

2. Equivalent to Close[6]

3. There are no short cuts. Try one of these:

3. This won't catch it. Actually you need:

```template<typename T>
T MathMin(T a, T b, T c){ return MathMin(a, MathMin(b, c)); }
⋮
if (MathMin(Close[1], Close[2], Close[3]) > iMA(…)) …```
20105

correct