Help calculating the min and max of the ATR indicator

 

Hello everyone,


How do you figure out the min and max of the ATR indicator? Basically, my plan is to flag if the current atr is closing at the min or max. I can get the atr value by calling the iATR function but I can't figure out how to get the min and max for a certain periods. I try to loop and seek Bars time back but it does not seem right.


Thanks.

 
 

I'm not sure about ArrayMaximum() and ArrayMinimum() but I know it's not Max and Min.



What I need to do is figure out the visible range that's on the ATR indicator window. If I can get that then I can determine where the current ATR value is compare to its low and high. That will tell me how far to the top or bottom. Without this I will have to look at the graph to figure it out.

 

How about this thinking,


1. what see on chart is plot of array element values ie, a series of numbers, an array of numbers calculated by indicator and plotted onto chart by Terminal ie, an indicator index buffer

2. if code 'acquires' these indicator numbers in array[] then code can apply one or more of mentioned builtins to inspecting this array

3. the inspecting of this array can be a window/range ie, a from..to area or total array seen as window

4. the number of elements inspected is of your choice: all mentioned builtins have start and count formals


How you decide to interpret the datums in the array[] in relationship to for instance o,h,l,c price values is up to you.


a. in a loop, iCustom() can load array[] with whatever range of values you require from indicator of your choice

b. loop range can also be controlled to eliminate redundant calculations/iCustom() calls, if only require certain number of indicator values from say within a [dynamic] from..to range

c. array[] can now be processed using builtins (or for that matter any code of your choice)

d. decisions/interpretations made...

 

Hello, I have just written a function that does just that. The following function calculates the average value of the ATR indicator over the desired period, and returns it.

The proper usage would be to compare current ATR value with the average of the previous 14, for example. If current ATR is over average, then scalping is desirable -In my case-.

I am actually building a scalper that uses ATR to determine if there is enough volatility to scalp and the desireable TP and SL.

However, comparing the current ATR with the last average period is not enough, in my case, the best usage is to know the correct TP and SL for the scalp.

This could be mapped on an indicator, oscillating from -1 to +1, being 0 the average.


/**
* Returns the average value of the ATR indicator over the last desired period
* @param    int   shift
* @param    int   period
* @return   double
*/
double getATRAverage(int shift = 1, int period = 14)
{
   // Sum
   double acum = 0;
   
   // Iterate
   for(int i = shift; i < shift + period; i++)
      acum += iATR(Symbol(), 0, period, i);
   
   // Average size
   double average = acum / period;
   
   // Return porcentaje
   return(average); 
}
 
It is useful...
 
  1. holygrailseeker:
    What I need to do is figure out the visible range that's on the ATR indicator window.
    extern int ATR.Length   = 30;
    extern int ATR.lookBack = 30;
    #define INF 0x6FFFFFFF // Not quite infinite, Jul 2029, or 1,879,048,191
    double atrMin = INF, atrMax = 0;
    for(int iBar = 1; iBar < ATR.lookBack; iBar++){
        double atr  = iATR(NULL,0, ATR.Length, iBar);
        if (atr > atrMax)   atrMax = atr;
        if (atr < atrMin)   atrMin = atr;
    }

  2. The number of bars visible depends on the size of the window and it's scale factor. But if you really mean that
    int iVisible    = WindowFirstVisibleBar(),
        iVisEnd     = MathMaxI(iVisible-WindowBarsPerChart(), 0); // Chart Shift
    for(int iBar = iVisEnd; iBar <= iVisible; iBar++){
    :
    int     MathMaxI(int a, int b){
                            if(a>b) return(a);              return(b);             }
    

Reason: