Indicators: ATR

 

ATR:

Average true range

ATR

Author: Mladen Rakic

 
Nowadays I don't use any indicator. But ATR was one of my Favs. I had to customize it according to my way of working. The interest zone + "ATR" --> if checked on the daily chart could give you a strong idea of what the market tend to do next. 

 
Mr Rakic, could I ask you what reason is for using a template (for high[], low[] and close[]) in the function "calculate". Is there any possibility to be something else than double? Thank you for your answer in advance.
 
Petr Nosek:
Mr Rakic, could I ask you what reason is for using a template (for high[], low[] and close[]) in the function "calculate". Is there any possibility to be something else than double? Thank you for your answer in advance.

Those are "const double" used there, not "double"

And yes, it will work with "double" too the way it was written and it would not work if it was "hard-coded" to either "double" or "const double" without a code change

 
Mladen Rakic:

Those are "const double" used there, not "double"

And yes, it will work with "double" too the way it was written and it would not work if it was "hard-coded" to either "double" or "const double" without a code change

Thank you for your response.

Maybe I've missed something but IMHO this piece of code:

double calculate(const double& high[], const double& low[],const double& close[], int i, int bars)

will work in the same way as your piece of code:

template <typename T>         
double calculate(T& high[], T& low[],T& close[], int i, int bars)

It will work both with "const double" and with "double". And I was just curious if is there a reason for using a template.

Reason: