Questions from Beginners MQL5 MT5 MetaTrader 5 - page 971

 
Sprut112:
Tried and failed to translate from a fixed lot to a percentage lot. Maybe someone can tell me on the full code?

As a percentage of what?

 
xxz:

As a percentage of what?

From the balance sheet, standard

 
Sprut112:

From the balance sheet, the standard

//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double TradeSizeOptimized(void)
  {
   double price=0.0;
   double margin=0.0;
//--- select lot size
   if(!SymbolInfoDouble(_Symbol,SYMBOL_ASK,price))
      return(0.0);
   if(!OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1.0,price,margin))
      return(0.0);
   if(margin<=0.0)
      return(0.0);

   double lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_MARGIN_FREE)*MaximumRisk/margin,2);

it's from the raw data

input double MaximumRisk        = 0.02;    // Maximum Risk in percentage

from available funds...

 
xxz:

this into the raw data

Does this need to be placed instead of something or all together?

 
Sprut112:

Does this need to be placed instead of something or all together?

double get_lot(int pair, double input_lots)

This function should be redesigned, it is called when you calculate a lot...

 
xxz:

redo this function, it is called when you calculate a lot...

The compiler doesn't accept it

 
Sprut112:

The compiler won't accept

I'll try your code now...

 
xxz:

I'm going to try your code now...

Almost got it, there's only one error left - margin

 
xxz:

I'm going to try your code now...

I don't seem to be able to...

 
Sprut112:

Somehow it didn't work out for me.

here's how it works...

MM is a fixed lot option or a percentage option...

Files:
Experiment.mq5  40 kb
Reason: