Just do exactly the same as you did with the test script.

Run your trade script in "Test" mode. Check the logfile and compare the displayed risk with the risk and the parameters from the formula. In the next step trade it on your demo account. Again compare the displayed risk with the risk and the parameters from the formula. You can then see all discrepancies. Your calculation above looks ok to me, but I cannot verify your parameters from here. If you get result A and the computer gets result B and you are sure that you're using the right formula, then obviously one of the parameters must be different.