PDA

View Full Version : Interesting line of code


scjohn
10-17-2007, 12:03 PM
I found the the following line of code in your TRIX indicator very interesting:

EMA tripleEma = EMA(EMA(EMA(Input, period), period), period);

Could you explain why it is coded like this and what it does. Specifically I am interested in the left hand side of the equation - EMA tripleEma =.

thanks

NinjaTrader_Dierk
10-17-2007, 12:18 PM
This is just an EMA on an EMA on an EMA which is then assigned to the variable (tripleEma).

NinjaTrader_Ray
10-17-2007, 12:22 PM
The reason this was done was to optimize performance of the indicator. Internally NT holds all called indicators in a cache. Since tripleEma is called multiple times in the code, it just saved unnecessary cache look ups.

scjohn
10-18-2007, 07:32 AM
So that's why you coded it as EMA tripleEma = instead of just tripleEma =?

Any rules as to when one should use what is shown? I assume that this type of code code be done on any indicator?

thanks,

NinjaTrader_Ray
10-18-2007, 07:38 AM
When you declare a variable, you need to decalare its type.

For example:

double myDouble = 5.1;

EMA myEma = EMA(20);

myEma is the variable name and its of type EMA

whitmark
10-19-2007, 07:15 PM
scJohn,

fwiw, this is a great technique for indicator calls with lengthy parameter lists as it eliminates the need to restate the list of parameters with each call.

You might find this thread helpful starting with post #8.

http://www.ninjatrader-support.com/vb/showthread.php?t=2297

Regards,

Whitmark