Compare indicator value to the highest value n bars ago

Posted By: DonDiego

Compare indicator value to the highest value n bars ago - 03/06/23 18:26

Hi

I do want to compare the current value of a MovingAverage to a the highest value within the last 9 bars, excluding the current one, as a condition in an IF-statement.

something like if MA > Highest(MA,9)[1] then do this and that

I've found HH() but seems only to be useable for priceData and not an indicator.
MaxVal() expect to use series. So I did try:
Code
 if(MA>MaxVal(MA[1],9)

but that throws an error (pointer expected).

I probably could find out what I need with a loop, but that seems to be an overkill and somehow inefficient for my little task.
Posted By: nsg

Re: Compare indicator value to the highest value n bars ago - 03/06/23 18:57

Assuming MA is a series, you can't use MA[1] within a function that takes a series as an imput. By using MA[1] you're sending a float to it.
The correct syntax is if(MA[0]>MaxVal(MA,9)). This way, you compare float (MA[0]) with another float resulting from evaluation of MaxVal(MA,9).
Posted By: DonDiego

Re: Compare indicator value to the highest value n bars ago - 03/06/23 19:42

Alright, so your version of the code runs without error, but when I play with the lookback period it doesn't make a difference whether I put in 3, 9, 50 or 100. The result is always the same.

On the Financial Hacker website Petra uses some code in the detecting volume breakout article, which I tried to translate to my needs. The result is:
Code
MA[0] > MaxVal(series(MA[1],10),9)


This kind of works, but I don't know how to verify if the code calculates what I had in mind.
Posted By: Grant

Re: Compare indicator value to the highest value n bars ago - 03/06/23 21:46

Maybe there are no trades made during the first 100 days? Use 'set(LOGFILE);' to find out.
© 2024 lite-C Forums