Download MetaTrader 5

MTF Problem with EMAs

To add comments, please log in or register
Track Market top sellers!
mar
1146
mar 2014.09.01 09:15 

Hi Forum,

I want to check if the EMA50 is above the EMA100 in the current displayed timeframe and additionally in the D1 timeframe. The current timeframe is checked correctly but there is a problem with the D1.

I think that I can't use the variable i when checking the D1 timeframe. When I use this code in the H1 timeframe, I first have to check which D1 bar is the corresponding one. Can someone help me? 

double EMA (int tf, int period, int shift)   { return(iMA(NULL, tf, period, 0, MODE_EMA, PRICE_CLOSE, shift)); }
.
.
.
if (EMA(Period(), 50, i) >= EMA(Period(), 100, i) && EMA(PERIOD_D1, 50, i) >= EMA(PERIOD_D1, 100, i))
whroeder1
14504
whroeder1 2014.09.01 12:19  
mar: I think that I can't use the variable i when checking the D1 timeframe. When I use this code in the H1 timeframe, I first have to check which D1 bar is the corresponding one. 
  1. double EMA (int tf, int period, int shift)   { return(iMA(NULL, ... ...
    Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling back and forth trying to read it. Edit your code to ~80 characters max width, so you can read it.
  2. Exactly. You must use an appropriate shift for every call.
    Not compiled, not tested.
    double EMA (int tf, int period, int chart_shift){ 
       datetime when     = Time[chart_shift];
       int      tf_shift = iBarShift(tf, when);
       return iMA(NULL, tf, period, 0, MODE_EMA, PRICE_CLOSE, tf_shift);
    }
    
    Not compiled, not tested.
mar
1146
mar 2014.09.01 14:43  

William, thank you so much! It works perfect! 

To add comments, please log in or register