adjust this indicator

 
help with this indicator to make

1- make it work on last closed bar not the current bar

2- control of choose time frame from outside



thank you very much
Files: