According to pine script documentation you need to use := for variable reassignment + you can't use the security function inside and if statement. I also tried to use a normal string variable like timeframe = 'W' which gets reassigned through an if statement like var and use it in the security function, but you're appearently not allowed to do that either.
So I used the input function, which works.
UnknownUnicorn1165296
⋅
Great work. One question... what data source are you using to plot BTC price back to 2009?