updating min and max atr value

 

hi whroeder1 and all,

a while back as per this thread https://www.mql5.com/en/forum/108481 

u have suggested some code for finding min and max atr value but as price keep moving on, the min atr value does not update its value eg. if when first launched ea let's say min atr is at 0.25 but after iVisible bars passed and the new min atr in that portion of the displayed is at 0.45 but the ea still keeps its first found min atr at 0.25 

this is the code i used from your suggestion

for(int iBar = 1; iBar < ATRLookback; iBar++){
    double atr  = iATR(NULL,0, ATRLength, iBar);
    if (atr > atrMax)   atrMax = atr;
    if (atr < atrMin)   atrMin = atr; 
}

i couldn't figure out your second part of the code guessing it's updating the new min and max value but how it works with the 1st part and what does a and b stand for, please help

and here's your original suggested codes

  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);