I know, because I wrote it also. Just want to understand what is the variable that causes, sometimes the expert can buy the biggest lot, and sometime not.
Zsolt Szabo #: I know, because I wrote it also. Just want to understand what is the variable that causes, sometimes the expert can buy the biggest lot, and sometime not.
For this example I will use EUR/USD, where 1 pip-lot is worth 10 USD and a pip is defined as 0.0001 (not 0.00001 which is a point).
However when placing the order, one also has to account for the margin requirements and in this case 1 lot is 100000 EUR (1:1 leverage).
For example, for a leverage of 1:100, one would require 1000 USD for a full lot, or 500 USD for 0.5 lots or 50 USD for 0.05 lots.
In this case, your balance of 400 USD would allow placing the 0.05 order but would give a "not enough money" error for the 0.5 lots, even if your stop-loss risk is only 20 pips (100 USD for 20 pips at 0.5 lots).
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
It must be corrected, Juan. For example: if the EA uses a fixed volume parameter and by default this volume is set at 0.01, but during validation testing the tested symbols do not allow volume 0.01, then the EA does not open a position and will not be able to be published. So, to avoid this problem, you can use a function like the following, in addition to the volume checks recommended in the article:
//+--------------------------------------------------------------------------------------------------------------------+//| This function normalizes the volume according to the minimum volume change step |//+--------------------------------------------------------------------------------------------------------------------+double NormalizeVolume(double Lot)
{
ResetLastError();
//--- Minimal and maximal allowed volume for trade operationsdouble LotMin = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double LotMax = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
//--- Get minimal step of volume changingdouble LotStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
//--- Check if an execution error occurredif(GetLastError() != ERR_SUCCESS)
{
return(WRONG_VALUE);
}
//--- Normalizes the volume
Lot = LotMin + MathFloor((Lot - LotMin) / LotStep) * LotStep;
Lot = NormalizeDouble(MathMin(LotMax, MathMax(LotMin, Lot)), 2);
//--- Normalized volumereturn(Lot);
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Already answered—margin requirements.
Add the following function to your code and change this line:
Forum on trading, automated trading systems and testing trading strategies
Desperate "No trading operations" error
Vinicius Pereira De Oliveira, 2024.04.21 14:42
It must be corrected, Juan. For example: if the EA uses a fixed volume parameter and by default this volume is set at 0.01, but during validation testing the tested symbols do not allow volume 0.01, then the EA does not open a position and will not be able to be published. So, to avoid this problem, you can use a function like the following, in addition to the volume checks recommended in the article:
Add the following function to your code and change this line: