@am2013 I am very much the least qualified to answer your questions compared to everyone else here. Mike has done an amazing job and his contributions are greatly appreciated as are everyone else's. I have been using some of the tools Mike has put together for some time now and a few of them I have made minor modifications too so that they work for me. Take what I say as a grain of salt compared to anyone else that might respond.
That said, I suppose there are a couple of ways to answer your question , unfortunately with more questions. What exactly are you trying to accomplish when you say,
How do I use this code and is there a way to incorporate this into TOS?
Are you wanting to actually use it while charting in TOS or do you do your charting with AmiBroker? Or have you automated with Amibroker that you run through TOS and you some how want to use this as part of a larger strategy?
So if you want to do something similar in TOS, I would imagine that you could, using thinkScript. In the past, I have put together a few simple strategies using that in TOS but nothing like like this or other tools I have found and tried in AmiBroker. Beyond that I know very little of the capabilities of thinkScript. As to the other possibilities I mentioned, such as an automated strategy in Amibroker run through the TOS, I have not yet gone down that path. For me, I use Amibroker for ALL of my charting, analysis, screening, and recording. I do not trade from Amibroker. Instead, I use it to do my homework and then place trades directly with my broker on a daily basis. This may or may not be what you are looking for but it has worked well for me.
I know that this still probably leaves you with more questions and hopefully one of the other guys with much more experience than I can be more helpful. My point is that if you could maybe be a little more specific with your question, and how you use AmiBroker and TOS together, it may make it easier for someone to give you the correct advice.
Also, I will direct you to this link as it is helpful to most new users on the forum:
https://forum.amibroker.com/t/how-to-ask-a-good-question/10247
It would also be helpful if you would verify your account which you can find more information about here:
https://forum.amibroker.com/t/license-verified-badge/13353
If you do those couple of things you will be welcomed to the community and many of the people here will be very helpful. Good luck!