how to find maximum value of an indicator in Limited number of Bars

 

hello, i know how to return the value of an indicator in a Bar that we know the shift number of it.

but what if we dont have the shift number.

for example: i want to find the highest amount of  Standard Deviation in the last 20 bars. how do i do that?

if it was an indicator like Moving Average we could say i can use iHighest for finding the highest bar in the last 20 bars and than i would have the shift number to find the value of Moving Average in that bar. but Standard Deviation dose not go up and down with the price. so it is different.

does anyone has an idea how i can return the highest amount of  Standard Deviation in the last 20 bars ?

 
kriss.ro: hello, i know how to return the value of an indicator in a Bar that we know the shift number of it. but what if we dont have the shift number. for example: i want to find the highest amount of  Standard Deviation in the last 20 bars. how do i do that? if it was an indicator like Moving Average we could say i can use iHighest for finding the highest bar in the last 20 bars and than i would have the shift number to find the value of Moving Average in that bar. but Standard Deviation dose not go up and down with the price. so it is different. does anyone has an idea how i can return the highest amount of  Standard Deviation in the last 20 bars ?

Loop through 20 bar shifts and read the Standard Deviation at each one, and detect which is the highest.

On each iteration compare the current value to highest saved in a variable and if the current value is higher, update the variable.

 
kriss.ro: but what if we dont have the shift number.

for example: i want to find the highest amount of  Standard Deviation in the last 20 bars. how do i do that?

When in doubt, think! Don't have the shift, find it.
double max=DBL_MIN;
for(int shift=0; shift < 20; ++shift){
    double std = iStdDev(…, shift);
    if(max < std) max = std;
}
 
Alternatively, on each new bar, keep saving the values into an array and then use the function ArrayMaximum to get the highest.
 

thank you .

i think useing ArrayMaximum is the right way for it.

thank you for your help.

Reason: