Higher for at least N days in a row

Posted By: strimp099

Higher for at least N days in a row - 02/22/21 07:53

How might I test if a price series is higher for at least N days in a row?

This gives my a price series higher for five days in a row starting yesterday...

Code

bool risingFiveDays = (Prices[1] > Prices[2]) && 
				    (Prices[2] > Prices[3]) && 
				    (Prices[3] > Prices[4]) && 
				    (Prices[4] > Prices[5]) &&
				    (Prices[5] > Prices[6]);


How to generalize this to _at least_ five days starting yesterday?
Posted By: ZorroTradeAA

Re: Higher for at least N days in a row - 03/11/21 18:50

Hi,

I would say you can use a for-loop.
Something like that:

Code
int dayLookBackStart = 1;
int lookBackPeriod = 5;
int i;

bool risingXDays = true;

for(i=dayLookBackStart ; i<lookBackPeriod-1; i++){
 if(Prices[i]<Prices[i+1]){
  risingXDays = false;
  break;
 }
}


risingXDays is true if during the lookBackPeriod you have continues higher Prices or false if the series is broken in one of the days.
Try it out it should work.

Cheers
© 2024 lite-C Forums