EMA of multiple time frames

Posted By: Pipinator

EMA of multiple time frames - 12/16/12 18:56

Hello,

I am trying to create a multi-TF indicator. I would like to have a 38 hr EMA, 8 hr EMA on the 5 minute TF for scalping.

I'm running into the problem not being able to get a Price array

vars Price = series(price()); with a fixed time frame, All I see is offset. Is it possible?

vars Price60min = series(price(0,60));
vars Price5min = series(price(0,5));

plot("EMA60",EMA(Price60min,38),0,0x222222);
plot("EMA5",EMA(Price5min,8),0,0x992222);

Thanks!

T
Posted By: jcl

Re: EMA of multiple time frames - 12/17/12 08:08

For setting a time frame, use the TimeFrame variable. How to use it is described in the manual with an example:

http://manual.zorro-trader.com/barperiod.htm

As to my knowledge, scalping ceased to be profitable around the year 2000, though.
Posted By: SFF

Re: EMA of multiple time frames - 12/24/12 16:30

Could you explain how to use 1 week, 1 month even 1 year chart?
Posted By: jcl

Re: EMA of multiple time frames - 12/27/12 08:47

For week bars, set BarPeriod to 7*24*60.

There are no month bars, because months have a different number of days and can not be expressed with a bar period.
Posted By: SFF

Re: EMA of multiple time frames - 12/31/12 03:54

Thanks. I have made this code but It looks like I had errors about BarPeriod/TimeFrame.

The strategy is simple - I will buy 15min MACD cross over if MACD of 30 and 60 min are in the same direction.( For buy, upside).

Thank you for any advice.

Code:
function run(){
	
	set(LOGFILE);
	
   int FastPeriod = 8;
   int SlowPeriod = 21;
	int SignalPeriod = 9;
	
	BarPeriod = 15;
	vars Close = series(priceClose());
	TimeFrame = 1;
	
	MACD(Close,FastPeriod,SlowPeriod,SignalPeriod);
	vars MainLine = series(rMACD);
	vars SignalLine = series(rMACDSignal);
	vars Hist = series(rMACDHist);
	
	MACD(Close,FastPeriod*2,SlowPeriod*2,SignalPeriod*2);
	vars MainLine30 = series(rMACD);
	vars SignalLine30 = series(rMACDSignal);
	vars Hist30 = series(rMACDHist);
	
	MACD(Close,FastPeriod*4,SlowPeriod*4,SignalPeriod*4);
	vars MainLine60 = series(rMACD);
	vars SignalLine60 = series(rMACDSignal);
	vars Hist60 = series(rMACDHist);
	
	MACD(Close,FastPeriod*16,SlowPeriod*16,SignalPeriod*16);
	vars MainLine240 = series(rMACD);
	vars SignalLine240 = series(rMACDSignal);
	vars Hist240 = series(rMACDHist);
	
	

if(crossOver(MainLine,SignalLine) && MainLine30[0] > SignalLine30[0]
   && MainLine30[0] > SignalLine60[0] && MainLine240[0] > SignalLine240[0]){

    
exitShort();
    enterLong();
    }

if(crossUnder(MainLine,SignalLine) && MainLine30[0] < SignalLine30[0]
   && MainLine30[0] < SignalLine60[0] && MainLine240[0] < SignalLine240[0]){


exitLong();
    enterShort();
    }

            
}

Posted By: jcl

Re: EMA of multiple time frames - 12/31/12 08:25

Timeframe is a) not needed and b) used wrong here.

It's not needed because you can get your 30 and 60 min MACD just by multiplying the MACD timeperiod with 2 and 4.

It's used wrong because your Close series is still from TimeFrame = 1. A 60 min MACD would need a price series with 60 min candles, like this:

TimeFrame = 4;
vars Close60 = series(priceClose());
TimeFrame = 1;

Look in the manual under "TimeFrame", there you can see how it's used for price series with different time frames. However different time frames are needed for very special cases only, for instance a daily ATR.

Also, one suggestion - when you are not sure if your signals do what you want them to do, plot them. Make it a habit to plot all your signals in the chart. Seeing how your signals behave is essential for strategy development.
Posted By: SFF

Re: EMA of multiple time frames - 12/31/12 09:52

Thanks.

I had it working by multiplying timeperiod for each bars.

I have used plot function but the image I have got is very small thus I am not able to see where the signal has been for simple crossover systems and win-loss mark for each trades.

So I make a logfile and go to MT4 to check the signals.
Posted By: SFF

Re: EMA of multiple time frames - 01/03/13 14:09

Code was updated at post #414379.

It is producing signals which I am not expect to see.
Where is wrong?

I only enter 15min MACD cross when 30,60 and 240 MACD are in the same direction.
It enters or closes trades every 15min from the log.

Thanks in advance.
Posted By: jcl

Re: EMA of multiple time frames - 01/03/13 18:09

Originally Posted By: SFF
It is producing signals which I am not expect to see.
Where is wrong?

Well, if your script is producing signals which you are not expect to see, the "where" happens between the first line of your script, and the last line - that's at least what I can tell you without seeing your script. wink
Posted By: jcl

Re: EMA of multiple time frames - 01/04/13 10:50

Your updated code has still a bug: It exits only when the signals match, but it enters trades on every bar with these lines:

if(!NumOpenLong) enterLong();
...
if(!NumOpenShort) enterShort();

I believe you've forgotten the { } brackets.
Posted By: SFF

Re: EMA of multiple time frames - 01/04/13 12:52

>>For week bars, set BarPeriod to 7*24*60.

I am able to produce what I want by setting 1440*5.
By 7*24*60, The signal was not what I expect to see.

Which brackets do you mean?
Anyway I think I had my code corrected.
Thanks for the hint.

The code was updated.
Please look at it and let me know if it is what you think is correct.
Posted By: jcl

Re: EMA of multiple time frames - 01/07/13 10:22

Yes, it looks ok now.

You won't need all the series - only for the MainLine and SignalLine, for the rest you can use normal variables - but they don't harm either.
Posted By: SFF

Re: EMA of multiple time frames - 01/07/13 10:34

Thank you as usual.
© 2024 lite-C Forums