An other Use of close[ ]

To add comments, please log in or register
luke913
11
luke913  
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
William Roeder
20105
William Roeder  
  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 )
    iftrue > 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(…)) …

lippmaje
910
lippmaje  
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(…)) …
William Roeder
20105
William Roeder  
correct
To add comments, please log in or register