Basically your jscript doing the same thing but embedded into amibroker. Thank you for your help and Hope this method work well.
Why don't you try it out and see for yourself.
There is one small error that I discovered. Year(), Month() etc do not return latest year month but return year and month of whichever candle you've clicked. (Vertical blue line)
Remedy is to replace Year() month() and Day() with appropriate Now() functions.
Of course, if you could figure out how to pass full date format string, it
would be slightly simpler.