Problem with Parameter and ATR function

I am not able to pass a paramter to the ATR function. When I use the parameter's default value, everything works. Do you know why this happens?

ATRPeriod = Param("ATRPeriod", 20, 1, 50, 5 );
xATR = atr(ATRPeriod);
// Produces Error 52: Invalid argument value for ATR() function: range must be greater than zero (and not Null)


ATRPeriod = 20;
xATR = atr(ATRPeriod);
// Works

Moderator comment: You need to read How to use this site and USE CODE TAGS.

I'm not receiving any error message in AmiBRoker 6.20.

Yes, sometimes it gives the error and sometimes it doesn't, but I figured out why: For some reason, Amibroker has a problem when the variable ATRPeriod and parameter name are the same "ATRPeriod". Once I changed the parameter name to "ATR Period", everything worked. Keep all names separate.

I don't think so. I'm guessing that at first you had set a zero in Param function but then you changed it to a value larger than zero but without clicking Apply button.


The parameter name and variable name are completely independent and there is no dependency nor interference of any kind. @codejunkie guess is most probably the right one.

1 Like