It would have been bad for us all if the margin were not working, but I do not understand the problem from your code. If you think something is not working, you can just calculate it yourself and compare it with the statistics. The max open margin is not identical with the "Margin" variable. It is the max open lots multiplied with the margin cost per lot. The margin cost is provided by your broker and must be entered in the asset list. The open lots can be summed up in a trade enumeration loop.