EMA different timeframe problem

Hello everybody.

I would like to ask you guys for advice.
I coded a simple strategy.I was using MA function but now I need to change the old MA function for EMA function. But I get an error. The error occurs here "EMA(C,WeeklyShortMA) > EMA(C,WeeklyLongMA)". I could just write in a number instead of WeeklyShortMA but I need to have
weekly MA(25)>MA(50) for uptrend confirmation while working in a daily chart.

Original functional code:

TimeFrameSet(inWeekly);
WeeklyShortMA = 25;
WeeklyLongMA = 50;
TimeFrameRestore();

WeeklyShortMA = TimeFrameExpand(WeeklyShortMA,inWeekly);
WeeklyLongMA = TimeFrameExpand(WeeklyLongMA,inWeekly);

ShortMA = 25;
LongMA = 50;

Buy = EMA(C,ShortMA) > EMA(C,LongMA) AND MA(C,WeeklyShortMA) > MA(C,WeeklyLongMA) 
AND RSI(2) < 10 AND Ref(RSI(2),-1) < 10;


BuyPrice = Open;

Sell = C > EMA(C,5);
SellPrice = Open;

Thank you.

The code is incorrect. If you want to calculate EMA in weekly period, you have to put that code inside TimeFrameSet/Restore, like this:

TimeFrameSet(inWeekly);
WeeklyShortMA = EMA( C, 25 ); // do the EMA here !
WeeklyLongMA = EMA( C, 50 );
TimeFrameRestore();

WeeklyShortMA = TimeFrameExpand(WeeklyShortMA,inWeekly);
WeeklyLongMA = TimeFrameExpand(WeeklyLongMA,inWeekly);

Buy = WeeklyShortMA > WeeklyLongMA 
AND RSI(2) < 10 AND Ref(RSI(2),-1) < 10;


BuyPrice = Open;

Sell = C > EMA(C,5);
SellPrice = Open;
1 Like

I can see how it works now. Thank you very much!