Count Bars

 

How to count the bars of which Close > Open within 20 period ?

thanks regards
Kang

 
int uppity()
{
    int sum = 0;
    for ( int bar = 1; bar <= 20; bar++ ) {
        if ( Close[ bar ] > Open[ bar ] ) {
            sum += 1;
        }
    }
    return( sum );
}
The function uppity() above tells you how many of the prior 20 bars, not including the one currently being formed, have their close price above their open price.
 
richplank wrote:
int uppity()
{
    int sum = 0;
    for ( int bar = 1; bar <= 20; bar++ ) {
        if ( Close[ bar ] > Open[ bar ] ) {
            sum += 1;
        }
    }
    return( sum );
}
The function uppity() above tells you how many of the prior 20 bars, not including the one currently being formed, have their close price above their open price.
Thank you ,richplank. That's all ok.

Kang
 
I see. thanks.
 
Hello, Folks,
can I use this also for an indicator, who count, how many of the last bars are potove to the former bar?

T. Bopp
Germany