Not enough Money error

 

Hi everyone,  I hope this message finds you well.

I am encountering an issue for the first time, specifically related to "Not enough Money" MQL4 TESTER (see image below).

I attempted to address this problem by using the minimum lot size, but unfortunately, that did not resolve the issue. Additionally, I implemented a custom function to check the volume value using CheckVolumeValue, but this also proved ineffective.

It's worth noting that no problems were observed during backtesting or while using a demo account.

If anyone has a solution or suggestion for handling this error, I would greatly appreciate your assistance.

Thank you in advance.


 

MT4?
There is one article about it related to MT5 but it is same logic:

Before sending every trade order, it is necessary to check if there are enough funds on the account. Lack of funds to support the future open position or order is considered a blunder.

The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
 
Sergey Golubev #:

MT4?
There is one article about it related to MT5 but it is same logic:

Before sending every trade order, it is necessary to check if there are enough funds on the account. Lack of funds to support the future open position or order is considered a blunder.

Yes, in MT4, I found a solution using the same function that is described in the related article. Thank you!"

bool CheckMoneyForTrade(string symb, double lots,int type)
  {
   double free_margin=AccountFreeMarginCheck(symb,type, lots);
   //-- if there is not enough money
   if(free_margin<0)
     {
      string oper=(type==OP_BUY)? "Buy":"Sell";
      Print("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError());
      return(false);
     }
   //--- checking successful
   return(true);
  }