It of course CAN be done easily with custom backtester. But exercise is not worth effort. If you are getting margin calls it means that your leverage is too high and you are going to blow up account sooner or later. So for sake of staying in business lower your levarage.
Also @jonnycash - you have to Verify your license to post on this forum.