MT5 extremely high margin (Equity 1000.00, Margin: 109188.00, FreeMargin: -108188.00)

 

Hello there,

I just started learning mql and wanted to backtest a strategy from a ebook: https://github.com/rafaelfvcs/Introduction-to-MetaTrader5-and-MQL5---book/blob/master/MA_CROS_RSI.mq5
But unfortunately in my backtest I have extremely high margin / low free margin: 

calculated account state: Assets: 0.00, Liabilities: 0.00, Equity 1000.00, Margin: 109188.00, FreeMargin: -108188.00

I'm trying to buy 1 lot with 1:1 leverage and 1000USD input. If I set the backtest to 100000000USD Input it kinda works.

I don't know why this happens, so I'm asking you for help.

I attached a log, thanks in advance!

Introduction-to-MetaTrader5-and-MQL5---book/MA_CROS_RSI.mq5 at master · rafaelfvcs/Introduction-to-MetaTrader5-and-MQL5---book
Introduction-to-MetaTrader5-and-MQL5---book/MA_CROS_RSI.mq5 at master · rafaelfvcs/Introduction-to-MetaTrader5-and-MQL5---book
  • rafaelfvcs
  • github.com
Expert Advisor taught in the book: Introduction to MetaTrader 5 and Programming with MQL5. Create your 1st Investment Robot with MQL5 step by step from ZERO. - rafaelfvcs/Introduction-to-MetaTrade...
Files:
20240319.log  592 kb
 

You’re trying to buy 1 lot with 1:1 leverage and $1000 input. However, the calculated margin seems unusually high.

The formula for margin calculation is:  Margin = Lot Size / Leverage .
In your example, with 1:1 leverage, the margin required for 1 lot would be $1000.

You may want to try this
Set the tester to 1:1 leverage or test with a fixed lot size.
Ensure that your lot size remains constant during the backtest.

For more detailed guidance you can explore https://www.mql5.com/en/blogs/post/704853

Good luck with your strategy!

[Guide] How to backtest the best way, correctly with 99% real tick data, the best guide 2019
[Guide] How to backtest the best way, correctly with 99% real tick data, the best guide 2019
  • 2018.01.28
  • www.mql5.com
Dear Traders, today I want to present you my Guide "How to backtest the best way" and achieve realistic results, even for scalping EA, with highest precicion. At the end I will attach a youtube video
 
Oleksandr Medviediev #:

You’re trying to buy 1 lot with 1:1 leverage and $1000 input. However, the calculated margin seems unusually high.

The formula for margin calculation is:  Margin = Lot Size / Leverage .
In your example, with 1:1 leverage, the margin required for 1 lot would be $1000.

You may want to try this
Set the tester to 1:1 leverage or test with a fixed lot size.
Ensure that your lot size remains constant during the backtest.

For more detailed guidance you can explore https://www.mql5.com/en/blogs/post/704853

Good luck with your strategy!

Hello, thanks for the reply!

Unfortunately I'm not changing the lot size at all during the backtest, it's supposed to buy only 1 lot. It works better if I add leverage 1:500 instead 1:1.

Could you maybe try to backtest this EA (Introduction-to-MetaTrader5-and-MQL5---book/MA_CROS_RSI.mq5 at master · rafaelfvcs/Introduction-to-MetaTrader5-and-MQL5---book) with just 1 lot size and $1000 and see if you get the no money error / extremely high margin?

Thanks!

 

It appears that the issue you’re facing requires more in-depth assistance and possibly personalised solution.

https://www.mql5.com/en/job might be better suited for this purpose.

In this freelance section, you can find experienced MQL5 developers who can provide tailored solutions, debug your code, and address any issues you encounter during backtesting or live trading. They will also help optimize your EA for better performance.

Remember to provide clear details about your requirements, expectations and any specific constraints when posting your TASK to meet this criteria https://www.mql5.com/en/articles/235 

Good luck with your strategy!

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2024.03.20
  • www.mql5.com
The largest freelance service with MQL5 application developers