How is trima calculated

Posted By: swingtraderkk

How is trima calculated - 04/10/14 12:09

Hi jcl,

How is zorro's trima calculated?

I've been reading a lot on other forums about TMAs, and specifically how some peek into the future. i.e. using your example of the trima from the manual,
Quote:
the weights for a 7 period Triangular Moving Average would be 1, 2, 3, 4, 3, 2, 1. This gives more weight to the middle of the time series. It causes better smoothing, but greater lag.

the result given in those TMAs is not assigned to barindex 0, but to barindex 3 i.e. the center of the triangle.

1) Can you confirm that zorro's trima calculates the averages with the triangular weights but assigns the result to the most recent bar.

2) Clearly the other tmas cannot actually see the future, so their calculation at bar 0 is simply a linear weighted moving average of half the length of the trima, and all values at period +1 back are fine as they can access both sides of the triangle to get their values, but as the barindex goes from the period to zero, the triangular trima moves from being triangular to being linear. This is the claimed benefit of the TMAs as this process is a form of prediction of where the TMA is going next, and users of the TMA claim that it is the slope of the TMA that is useful. Can zorro replicate this type of recalculation of past indicator values using its series()?

3) If the past values are recalculated what will show on zorro's plots? I suspect that only the first calculated value will show.

4) If it is simply the slope of the TMA that is important, is the following easy way to program this in zorro correct?

Code:
var TMAslope(vars input, int period)

{
	var tma0		= WMA(input,period/2);
	int denom;
	var num;
	var tma1;
	int i;
	
	i=0;
	denom=0;
	num=0;
	tma1=0;
	
	for (i=1; i<=period/2; i++)
	{
		denom	+= i;
		int k	=  (period/2+1)-i;
		num	+= (input[k]*i);
		
		
	} 
	
	denom = denom+1;
	num	= num+input[0];
	
	var tma1	= num/denom;
	
	
	return (tma0 - tma1)/ATR(100);
}

Posted By: jcl

Re: How is trima calculated - 04/14/14 06:53

Yes, the triangular sum of the last 7 bars is assigned to the recent bar. What you describe in 2) sounds like a "repainting" indicator. You could program this of course, but it makes no sense for automated trading. None of Zorro's included indicators repaints or peeks into the future.
© 2024 lite-C Forums