MQL5: Variable Expected Error

 

I'm trying to write a money management class in mql5. (Its a library actually). Here it is:


class MoneyManagement
{
   private:
      double max_pos_mgn_set     = 2;
      double max_use_mgn_set     = 5;
      double current_balance     = AccountInfoDouble(ACCOUNT_BALANCE);
      double margin_used         = AccountInfoDouble(ACCOUNT_MARGIN);
      double free_margin         = AccountInfoDouble(ACCOUNT_FREEMARGIN);
      double max_position_margin = (max_pos_mgn_set/100)*current_balance;  //Set max of 2% margin per open position.;
      double max_usable_margin   = (max_use_mgn_set/100)*current_balance;  //Set max usable margin used to 5% of account balance.
      double usable_margin       = max_usable_margin-margin_used;          //Checks remainder usable margin by subtracting used margin from maximum usable margin.
      double nextpos_margin;
      double open_positions   = PositionsTotal();
      double max_positions    = 5;
      
   public:
      double nextpos_margin_calc();
      
};

MoneyManagement::nextpos_margin_calc()
{
   if (usable_margin > max_position_margin)
   nextpos_margin=max_position_margin;
   else if (usable_margin < max_position_margin)
   nextpos_margin=usable_margin;
   else if (usable_margin==0)
   nextpos_margin=0;
}


could someone please point out the compilation errors i get, what is actually wrong ? (mostly variable expected error)

I declared variable type, name and initialized them.

 
username1 :

I'm trying to write a money management class in mql5. (Its a library actually). Here it is:

could someone please point out the compilation errors i get, what is actually wrong ? (mostly variable expected error)

I declared variable type, name and initialized them.


You can't initialise member variables in their declaration.  You should declare them like this

 

private:
double max_pos_mgn_set;
double max_use_mgn_set;
double current_balance;
// etc

And initialise them in the constructor

 

public:

MoneyManagement()
{
  max_pos_mgn_set = 2.0;
  max_use_mgn_set = 5.0;
  current_balance = AccountInfoDouble(ACCOUNT_BALANCE);
  // etc


}
 
phampton :


You can't initialise member variables in their declaration.  You should declare them like this

 

And initialise them in the constructor

 

 

 

 

 


thanks.