Title: Pine Script v5 - "Cannot use 'plot' in local scope" error in a seemingly correct script
Hello,I am facing a persistent "Cannot use 'plot' in local scope" error in Pine Script v5, and I am unable to find the cause. The plotting and alertcondition functions are in the global scope, but the compiler seems to think they are in a local scope.
The error seems to be triggered by the combination of `request.security` calls and the `if` statements used for the state machine logic. The `bgcolor` function before the state machine works fine, but all `plot` functions after it fail. I have tried many different architectural patterns without success.
Could someone please review my code and explain why this error is occurring?
Here is the complete code:
// PASTE THE CODE FROM THE BLOCK BELOW HERE
Thank you fo
r your help!