How to calculate proper lot size ? - page 2

 
//+------------------------------------------------------------------+
//| Calculate correct lot size based on risk percentage given        |
//+------------------------------------------------------------------+
double LotCalculator(double risk)
   {
//Calculate lotsize based on risk percentage
    double lot = ((AccountInfoDouble(ACCOUNT_BALANCE) * risk / 100.0) / (MathAbs(INSERT YOUR ENTRY - INSERT YOUR STOPLOSS) * SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE) / SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE)));

//Make sure lotsizes are OK within broker restrictions
    lot = MathRound(lot / SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP)) * SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP);
    lot = MathMax(SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN), MathMin(SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX), lot));

    return(lot);
   }

Could be done like this:

double entry    = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
double stoploss = SymbolInfoDouble(Symbol(), SYMBOL_ASK) - _Point;
double lotsize  = LotCalculator(MathAbs(entry - stoploss), risk_percentage / ArraySize(takeprofits));
//+------------------------------------------------------------------+
//| Calculate correct lot size based on risk percentage given        |
//+------------------------------------------------------------------+
double LotCalculator(double pips, double risk)
   {
//Calculate lotsize based on risk percentage
    double lot = ((AccountInfoDouble(ACCOUNT_BALANCE) * risk / 100.0) / (pips * SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE) / SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE)));

//Make sure lotsizes are OK within broker restrictions
    lot = MathRound(lot / SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP)) * SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP);
    lot = MathMax(SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN), MathMin(SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX), lot));

    return(lot);
   }
 
Why in the name of God is this kind of functionality not already in the standard MQL5 library?! Basing a lot size on a given amount of money is one of the most basic, fundamental trading tasks I can imagine. It's astounding people are having to stumble about cobbling together their own (potentially flawed) solutions to this. I'm appalled, shocked, and supremely disappointed by how lacking is the MQL5 standard library. This is amateur hour.
 
Brady Wright #:
Why in the name of God is this kind of functionality not already in the standard MQL5 library?! Basing a lot size on a given amount of money is one of the most basic, fundamental trading tasks I can imagine. It's astounding people are having to stumble about cobbling together their own (potentially flawed) solutions to this. I'm appalled, shocked, and supremely disappointed by how lacking is the MQL5 standard library. This is amateur hour.

The funny thing is : it is in the standard MQL5 library.

Documentation on MQL5: Standard Library / Strategy Modules / Money Management Classes / CMoneyFixedRisk
Documentation on MQL5: Standard Library / Strategy Modules / Money Management Classes / CMoneyFixedRisk
  • www.mql5.com
CMoneyFixedRisk is a class with implementation of money management algorithm with fixed predefined risk. CMoneyFixedRisk class implements the money...