Help coding EMA of ATR to use in my EA

 
Hello, I am currently having an issue programming an EMA of my ATR in my EA. I want to create a 3 EMA of a 14 period ATR that I can use in my parameters of my EA to determine if it should trade or not. Any help would be appreciated.
 
  1. Jordan Olsen having an issue programming an EMA of my ATR … Any help would be appreciated.
    An issue you don't state.
  2. Help you with what? You haven't stated a problem, you haven't even stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

  3. Do you really want EMA( SMA(TR,14), L) as that is what iATR returns? Consider EMA(TR)?
       #define  TR(I) ( MathMax(High[I], Close[I+1])                              \
                      - MathMin( Low[I], Close[I+1])                              \
                      )
    
  4. Not compiled, not tested, just typed. (MT4 assumed)
    bool isFirstTick;
    int OnInit(){ isFirstTick=true; …}
    void OnTick(){
       bool isNewBar = …;
       static double ema[3]={0};
       if(isNewBar){ 
          for(int iBar = isFirstTick ? Bars-1 : 1; iBar > 0; --iBar){ // Can't run on bar zero.
             double atr = iATR(…, iBar);
             #define EMA(P,C,L) EMAa(P,C,2./(L+1))
             #define EMAa(P,C,A) ((P) + ((C)-(P))*A)
             ema[0] = EMA(ema[0], atr, length1);
             ema[1] = EMA(ema[1], atr, length2);
             ema[2] = EMA(ema[2], atr, length3);
          }
          isFirstTick=false;
       }
       ⋮
    }
    
    Not compiled, not tested, just typed.
 
Jordan Olsen :
Hello, I am currently having an issue programming an EMA of my ATR in my EA. I want to create a 3 EMA of a 14 period ATR that I can use in my parameters of my EA to determine if it should trade or not. Any help would be appreciated.

Maybe the codes here might work for you.

https://www.mql5.com/en/code/11166

MA-ATR
MA-ATR
  • www.mql5.com
This indicator combines Moving Average (MA) and Average True Range (ATR) to visualize potential trade signals. Black solid line indicates MA, Red solid line indicates MA+2*ATR, Red dash line indicates MA+1.5*ATR, Green solid line indicates MA-2*ATR, Green dash line indicates MA-1.5*ATR. 1. The price must cross over the moving average line and...
Reason: