//+------------------------------------------------------------------+//| Calculate correct lot size based on risk percentage given |//+------------------------------------------------------------------+double LotCalculator(double risk)
{
//Calculate lotsize based on risk percentagedouble 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);
}
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.
Could be done like this:
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.