Counter of higher highs and lower lows

Posted By: Neb

Counter of higher highs and lower lows - 01/03/21 17:06

Hi,

Not sure if this a right place for this question.
I suppose there is no function which could tell me how many higher highs I have in n period (did not find it) ?
Similar I would need for lower lows.

So, what is in my current level of knowledge is to do with function and loop through series of prices inside.

Is there some faster and more efficient way ?

Thanks,

Neb
Posted By: AndrewAMD

Re: Counter of higher highs and lower lows - 01/03/21 19:54

If you're only using one price series, your custom indicator can be quite efficient. Why not give it a shot?
https://zorro-trader.com/manual/en/tutorial_lowpass.htm
https://zorro-trader.com/manual/en/series.htm
https://zorro-trader.com/manual/en/price.htm
Posted By: Neb

Re: Counter of higher highs and lower lows - 01/03/21 22:41

I created something like this:


int countHH(vars Highs, int days)
{
int i=0;
int counter=0;
for(i=0; i<days-1; i++)
{
if (Highs[i]>Highs[i+1])
counter++;
}
// printf("\nHigher highs : %i ",counter );
return counter;
}

int countLL(vars Lows, int days)
{
int i=0;
int counter=0;
for(i=0; i<days-1; i++)
{
if (Lows[i]>Lows[i+1])
counter++;
}
// printf("\nLower lows: %i ",counter );
return counter;
}


And Highs is defined as series inside run() as:

vars Highs = series(priceHigh());


Does it make sense ?

Neb
Posted By: AndrewAMD

Re: Counter of higher highs and lower lows - 01/04/21 00:56

So far so good. At least your code is clear.

First, you have an error in the countLL function - you'll want to change ">" to "<".

Next, what is your definition of highest-highs in a period? Is it when the high is higher than the previous high, or is it when a new record is set? It seems you are doing the former and not the latter.
Posted By: Neb

Re: Counter of higher highs and lower lows - 01/04/21 10:52

Originally Posted by AndrewAMD
So far so good. At least your code is clear.


Thanks !

Originally Posted by AndrewAMD

First, you have an error in the countLL function - you'll want to change ">" to "<".


You are so right laugh Not sure how I missed that.

Originally Posted by AndrewAMD

Next, what is your definition of highest-highs in a period? Is it when the high is higher than the previous high, or is it when a new record is set? It seems you are doing the former and not the latter.


Strategy is comparing highs and lows as momentum condition, so don't need record, but just number of higher highs and lower lows in the same period.

if(countHH(Highs,WindowPeriod)>countLL(Lows,WindowPeriod) and ...) enterLong and opposite for short.



Thanks one more time, you are helping me very much !

Best regards,

Neb
© 2024 lite-C Forums