indicator of indicator, using series()

Posted By: webradio

indicator of indicator, using series() - 09/23/14 16:05

Intending two build a ten-period EMA of two-period ATR, is the following script an appropriate way?
Code:
var Ema_of_Atr(int Period)
{
	var *emaofatr = series(EMA(series(ATR(2)), 10));
	return *emaofatr;
}

I still have to get used to series()
Posted By: jcl

Re: indicator of indicator, using series() - 09/23/14 17:36

Almost. But you're returning a series, so you need to declare

var *Ema_of_Atr(int Period)

or

vars Ema_of_Atr(int Period)
Posted By: webradio

Re: indicator of indicator, using series() - 09/23/14 20:29

Thanks for explaination, jcl! Shoudn't it be one asterisk less then? Otherwise it attempts to return a double
Code:
return emaofatr;

After reading indicators.c, next question arose. Is there a valid reason at all, to return series when writing an indicator? Like intention of further processing? As far as I can see, all delivered indicators return double. So my script would shrink to
Code:
var Ema_of_Atr_simple()
{
	return EMA(series(ATR(2)), 10);
}

And yet another one, about TSI
Code:
// Trend Strength Index, from Engineering Returns 
var TSI(var* Data,int Period)
{
	var* ratio = series(abs(Data[0]-Data[Period])/ATR(Period),0);
	var* TSI = series(SMA(series(SMA(ratio,Period),0),10*Period),0);
	return *TSI;
}

As far as I can see it returns duble. Wouldn't it be simpler to
Code:
return SMA(series(SMA(ratio,Period),0),10*Period);

Posted By: jcl

Re: indicator of indicator, using series() - 09/29/14 11:59

You're right, I had not seen that you're returning the last value of the series only, so your original definition was correct - and the series is not needed at all when you only return its last element.
© 2024 lite-C Forums