CheckMoneyForTrade function not working on GOLD

 

Hi,

i have a question.


I have to do this 

If a check shows that there are insufficient funds to perform a trade operation, it is necessary to output an error message to the log instead of calling the OrderSend() function.

So i use that code from here https://www.mql5.com/en/articles/2555#not_enough_money

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);
  }

Than i call the function before OrderSend

      if (!CheckMoneyForTrade(_Symbol,lots,type)) return;//Check money for trade

so it is working well with forex symbols.


But when i use Gold or indices than it isnt working.


whats wrong here?? can someone help 

The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • 2016.08.01
  • MetaQuotes Software Corp.
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks, as a small error in the expert or indicator logic can cause losses on the trading account. That is why we have developed a series of basic checks to ensure the required quality level of the Market products. If any errors are identified by the Market...
 
Error Codes
bool CheckMoneyForTrade(string symb, double lots,int type)
  {
   if( AccountInfoDouble(ACCOUNT_FREEMARGIN) < 0 )return(false);
   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);
  }
Sometimes without checking the balance. Returns this error.
 

bool CheckMoneyForTrade(string symb, double lots,int type)
  {
   if( AccountInfoDouble(ACCOUNT_FREEMARGIN) < 0 )(false);    
   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);
  }
Whats ACCOUNT_FREEMARGIN?

Whats with this (false)


after compile it says:

expression has no effect

 
Raphael Schwietering :

Whats ACCOUNT_FREEMARGIN ?

Whats with this (false)


after compile it says:

expression has no effect

Has corrected. I skipped return =)

 
Konstantin Nikitin:

Has corrected. I skipped return =)

if( AccountInfoDouble(ACCOUNT_MARGIN_FREE) < 0 )return(false); 


change it to this.but not working. also same as in my picture

 
Raphael Schwietering :

if( AccountInfoDouble( ACCOUNT_MARGIN_FREE ) < 0 )return(false); 


change it to this.but not working. also same as in my picture

ERR_NOT_ENOUGH_MONEY 134 Not enough money.
Most likely still somewhere it is necessary to search for the reason.
 
Konstantin Nikitin:
Most likely still somewhere it is necessary to search for the reason.

but why it works on forex pairs and not on indices or metals

 
how did you guys do those checks?
Reason: