what am I missing in this script? it has an error

 
void OnStart()
  {
//---
   
  }
//+------------------------------------------------------------------+
void RiskPercentageByAccountBalance();
{
 double accBalance = ACCOUNT_BALANCE();
 Alert("Your Account Balance is: $" +string(ACCOUNT_BALANCE));
 Alert("Max Risk is: $" + string(0.01 * ACCOUNT_BALANCE));
}
 
Bryan Chang Wey Nerng:
void OnStart()
  {
//---
   RiskPercentageByAccountBalance();
  }
//+------------------------------------------------------------------+
void RiskPercentageByAccountBalance()
{
 double accBalance = AccountInfoDouble(ACCOUNT_BALANCE);
 Alert("Your Account Balance is: $", accBalance);
 Alert("Max Risk is: $", 0.01 * accBalance);

If you don't clearly state what you want to do, no one can help you. I fixed it so it can compile

 
void OnStart() {
   RiskPercentageByAccountBalance();
};

void RiskPercentageByAccountBalance() {
   double dbBalance = AccountInfoDouble( ACCOUNT_BALANCE ),
          dbRisk    = dbBalance * 0.01;
   Alert( "Your Account Balance is: $", DoubleToString( dbBalance, 2 ) );
   Alert( "Max Risk is: $",             DoubleToString( dbRisk,    2 ) );
};
 
Le Minh Duc #:

If you don't clearly state what you want to do, no one can help you. I fixed it so it can compile

sorry, it had an error when I was trying to compile. thank you so much

 
Fernando Carreiro #:

thank you so much. still new to mql5

edit, may I know why is it needed to put DoubleToString instead of just string? and what is the "2" for in the parameters for dbBalance and dbRisk?
 
Bryan Chang Wey Nerng #: thank you so much. still new to mql5edit, may I know why is it needed to put DoubleToString instead of just string? and what is the "2" for in the parameters for dbBalance and dbRisk?

Using DoubleToString sets the exact number of decimal digits to display.

Please reference the documentation, available on MetaEditor via the menu or F1 key, or online on this website:

Documentation on MQL5: Conversion Functions / DoubleToString
Documentation on MQL5: Conversion Functions / DoubleToString
  • www.mql5.com
DoubleToString - Conversion Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Unfortunately you can't run a script through the debugger. But if you build it into the OnInit function of an EA you can.