Percent R formula

HI can anyone correct my afl, why it cant work properly, it shows variable ''r'' has invalid type.

i just want to make william's % R with overbought and oversold. i have done well with RSI.
Please someone help me for guidances

r = PercentR( 3 );

OverBought = r > -80;
OverSold = r < -20;

// Explore //
Filter = 1;
AddColumn( r, "PercentR" );
AddColumn( OverBought, "OverBought", 1.0);
AddColumn( OverSold, "OverSold", 1.0);

// Chart //
Plot( r, "PercentR", colorWhite );

@de.yudi.dy, glad to see you posting your code. It would help if you used the Code button ("</>") in the editor for posting code.

Looks to me like you have to define your PercentR function above your code. Then you can call it. I don't see PercentR listed as a built in function. There is an example in the list of Indicators. Note that the example defined the function first. Here is the code:

function PercentR( periods )
 return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods ) ); 

Hope this helps.