Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 43

 

Help me write a function that returns the maximum ATR value among the bars visible in the window. I searched all over internet, couldn't find anything similar.

Thank you,

 
dr.Vasgenich :

Help me write a function that gets the maximum ATR value among the bars visible in the window. I searched all over internet, couldn't find anything similar.

Thank you,

/

extern int p = 4; // ATR period

//------

int start()

{

int i;

double m;

while( i < WindowBarsPerChart() - p )

{

double a = iATR( NULL, 0, p, i );

if ( m < a )

{

m = a;

}

i++;

}

Alert( " The maximum ATR value in pips for the visible number of bars is ", m / Point ); //

/////

return(0);

}

 

Boeing747 Thank you. I should have written here right away.

So the final variant of the function in my version looks as follows

double ATR_Max() {
int i;
double m;
while( i < WindowBarsPerChart() - p ) {
double a = iATR( NULL, 0, p, i );
if ( m < a ) {
m = a;
}
i++;
}
Alert( " The maximum ATR value for the visible number of bars is - ", m );
return(m);
}

 
dr.Vasgenich :

Boeing747 Thank you. I should have written it here right away.

So, the final variant of the function in my version looks like this

double ATR_Max() {
int i;
double m;
while( i < WindowBarsPerChart() - p ) {
double a = iATR( NULL, 0, p, i );
if ( m < a ) {
m = a;
}
i++;
}
Alert( " The maximum ATR value for the visible number of bars is - ", m );
return(m);
}

I must have made a mistake in while( i < WindowBarsChart() - p )

most likely the iATR( NULL, 0, p, i ); function calculates values for all the bars on the chart and you can, or perhaps should

corrected to while( i < WindowBarsChart() ). I've never worked with the iATR() function; I should try it sometime.

Actually you may write your function without using iATR() function so to say in its pure form.

 
Boeing747 :

I must have made a mistake in while( i < WindowBarsChart() - p )

Most likely, the iATR( NULL, 0, p, i ); function calculates values for all the bars on the chart.

corrected to while( i < WindowBarsChart() ). I've never worked with iATR(); I should try it sometime.

Basically, I can write your function without using iATR(), so to say in its pure form.


I also thought now that the period has nothing to do with it. It would probably be better to remove it.

Can't you do it through an array? Collect in an array the values of all APR in the window and then find the maximum using this function - ArrayMaximum I'm afraid my knowledge is not enough.




 
dr.Vasgenich :

I've been thinking now that the period has nothing to do with it. It's probably better to remove it.

Can't this be done through an array? Collect in an array the values of all APR in the window and then find the maximum using this function - ArrayMaximum I'm afraid my knowledge is not enough for this.




Yes, you can scroll through iATR(); in the loop to score arrays and then using ArrayMaximum to extract the maximum value of ATR. But still get buttery as it is still necessary to use the cycle to score arrays as in the first option . but in the first version of the maximum was calculated in the process of scrolling the loop that is much more economical than with the option ArrayMaximum. You don't need to know much about it. You can get detailed information about ArrayMaximum in a textbook or in a reference book.
 
Boeing747 :
Yes it is possible to scroll iATR(); in a loop to score arrays with it and then using ArrayMaximum to extract maximum value ATR. but all the same it turns out oil as specially for this purpose it is necessary to use a loop to score arrays as in the first variant . but in the first variant the maximum was calculated during scrolling a loop that is much more economical than with a variant ArrayMaximum. You don't need any special knowledge. You can find detailed descriptions about ArrayMaximum in a textbook or reference book.

Thank you, I will try to check tomorrow. One more question, how can I save tester resources in this function, so that the maximal value is calculated after a new bar appears and not with every tick?
 
dr.Vasgenich :

Thank you, I will try to check the operation tomorrow. One more question, how can I save tester's resources in this function, so that the maximum value is calculated after a new bar appears and not with each tick?

You can try this way to begin with

on a global level declare t

and over the loop write

if ( t != Time[0] )

{

t = Time[0];

// loop where ATRmax is calculated

}

this way the calculation in the loop will be done once at the opening of a new bar. perhaps there are other more clever variants...

 

Boeing747, dr.Vasgenich, guys, can't you use the "SRC" button or are you ok with that?

 
Zhunko :

Boeing747, dr.Vasgenich, guys, can't you use the "SRC" button or are you ok with that?

I keep forgetting to use the "SRC" button. It must be a habit. At 60, it's hard to change your mind. I'll try to use your button tomorrow
Reason: