Cant understand return value of AccountFreeMarginCheck()

 

Hi, why is AccountFreeMarginCheck() returning a negative number within this code? And hence not letting me place the trade?   


//+------------------------------------------------------------------+
//|                                                       Test 7.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                         https://www.intraday-trading-tools.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.intraday-trading-tools.co.uk"
#property version   "1.00"
#property strict

// Input variables
sinput string SECTION_A="*** Magic Number & Slippage ***";
input int MagicNumber=1807; // Magic Number
input int Slippage=10;

extern string SECTION_B="*** Lot Size ***";
input double LotSize=0.01;  // Lot Size

extern string SECTION_C="*** Maximum Spread Size ***";
input int Spread=30; // Maximum Spread  (EG on EURUSD 3 = 0.00003)  

extern string SECTION_D="*** Trade Management ***";
input int StopLoss= 20;     // Stop Loss
input int TakeProfit = 20;    // Take Profit

extern string SECTION_F = "*** Money Management ***";
input bool UseMoneyManagement=true; // Money Management 
input double RiskPercent=2.0;    // Risk Percentage     

// Global variables
int gBuyTicket;

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   //-------------- 
   // Adjust Lot Size     
   //--------------
   double lotSize=LotSize; 
   
   if(UseMoneyManagement==true)
   {
      double accPerc=AccountBalance()*(RiskPercent/100.0);    
      double lotsize=(accPerc/StopLoss); 
      lotSize = NormalizeDouble(lotsize,1); 
   }
   else lotSize=LotSize;

   //-------------- 
   // Timer            
   //--------------
   int hour = Hour();
   int timehour = 10;
   
   // Reset tickets   
   if(OrdersTotal() == 0) gBuyTicket = 0;
   
   //-------------- 
   // Main Condition            
   //--------------
   if(hour == timehour && gBuyTicket == 0) 
   {
      if(!CheckMoneyForTrade(Symbol(),lotSize, OP_BUY)) return;
   
      // Open Trades Here
      gBuyTicket = OrderSend(_Symbol,OP_BUY,LotSize,Ask,Slippage,0,0,"Buy order",MagicNumber,0,clrGreen);
      
      // Add stop loss & take profit to Buy order
      if(gBuyTicket > 0 && (StopLoss > 0 || TakeProfit > 0))
      {
         bool select = OrderSelect(gBuyTicket,SELECT_BY_TICKET);
         
         // Calculate stop loss & take profit
         double stopLoss = 0, takeProfit = 0;
         if(StopLoss > 0) stopLoss = OrderOpenPrice() - (StopLoss * _Point);
         if(TakeProfit > 0) takeProfit = OrderOpenPrice() + (TakeProfit * _Point); 

         // Modify order
         bool modify = OrderModify(gBuyTicket,0,stopLoss,takeProfit,0);
      }   
   }  
}

//+------------------------------------------------------------------+
// Checks for if we have enough money
//+------------------------------------------------------------------+
bool CheckMoneyForTrade(string symb, double lots,int type)
  {
   double free_margin=AccountFreeMarginCheck(symb,type,lots);
   
   Print(" free_margin = ",free_margin);

   //-- 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);
  }
 
Be good if someone answered this