N day high

Posted By: strimp099

N day high - 02/15/21 07:59

Greetings,

How can I determine if yesterday's close price is the rolling 50 day high? This is what I tried so far

Code

vars Prices = series(priceClose())
var Max50Day = MaxVal(series(priceClose()+1),50);

if (equalF(Max50Day, Prices[1]))
{
    // do stuff
    printf("\n%f %f %f",Max50Day, Prices[1], equalF(Max50Day, Prices[1]));
}


When I run this, I'm entering the IF statement on every iteration even though equalF(Max50Day, Prices[1]) evaluates to 0.000.

I've also tried the following in the IF expression

Code
if (Prices[1] >= Max50Day)


Which only matches once in 16 years worth of SPY daily close history (?).
Posted By: jcl

Re: N day high - 02/17/21 13:17

The "+1" is wrong - you're this way adding 1 to all prices. But the second if expression is ok.
© 2024 lite-C Forums