CS2502
error Functions cannot be declared inside other functions.
#What it means
Functions must be declared at the top level of the script, not inside another function (or inside an if or a loop).
#Typical cause
- A helper function written inside the function that uses it.
#How to fix it
Move the inner function out to the top level. It can still be called from the other function.
#Example
//@chartscript 1
indicator("Helpers")
function outer(x) {
const inner = (y) => y * 2
return inner(x)
}
plot(outer(close))Fixed
//@chartscript 1
indicator("Helpers")
const inner = (y) => y * 2
const outer = (x) => inner(x)
plot(outer(close))