Writing technical analysis code in T-SQL is not a good idea. If you really want to execute it on the database server; then I would recommend writing your code in any .NET language and uploading the code to SQL Server. You can then call this code from T-SQL using the "Custom Functions". See Link.
I did similar things in Oracle for another purpose.
If possible, try checking if you can execute the code on the client side or on the web server, if applicable in your case.
source
share