Hello all
I am new to programming with pro-real code, so I need your help with the below.
I try to create an indicator of the buy/sell climax. In theory a buy climax occurs if a stock has a new 52 week high but then closes below previous week’s close. In my first approach to the code I tried to compile only the first part – meaning to check if a stock has a new 52 week high (then I will think the rest). I put the following code.
My result is that bclimax is always 0, although I would expect to have 1 also in many days that had high. What am I missing here?
IF DHigh(0) > Highest[365] THEN
bclimax = 1
ELSE
bclimax = 0
ENDIF
return bclimax AS "Buy Climax"
Because you are trying to check a condition that can’t exist. The current High cannot be superior to the Highest high, it is the Highest high 🙂 So you’ll have to check is the current High is above the highest one, 1 bar ago, like in this code:
IF DHigh(0) > Highest[365][1] THEN
bclimax = 1
ELSE
bclimax = 0
ENDIF
return bclimax AS "Buy Climax"
EDIT: there is no 365 trading days in year. You should adapt this lookback period to get something near the real value.
Thank you!!! Also for noticing the 365 – I am so used from calculating interest rates and didn’t even think of it :/
It worked (i think it works at least for now) amending the code as follows – from some sample data looks like it works as expected
Again appreciated
IF DHigh(0) > Highest[260][1] THEN
IF Dclose(0) < Highest[5][1] THEN
bclimax = 1
ELSE
bclimax = 0
ENDIF
ELSE
bclimax=0
ENDIF
return bclimax AS "Buy Climax"