How i get automatically n(Number of periods) in a exponential moving average

hi, i need help, can you help me ?
I make this code:

ema <- EMA(dataset$um, n = 10, wilder = FALSE, ratio = NULL)

But i want the better n, How can I get the best value automatically?

n = 10

is the EMA default argument. See


The best n depends on what you want to do. In EMA, it is used to calculate the number of periods in the moving average, and the help page indicates possible instability for small values.

If your number of rows is, say, 1000, I'd try n= 25, 250, and 500 to see how your result changes.