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

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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,
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);
}
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.
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.
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 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?
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?
Boeing747, dr.Vasgenich, guys, can't you use the "SRC" button or are you ok with that?