nCalculate Lot by Percent - MetaTrader 5 Library - MT4/MT5 Resources


Automatically calculates the size of trading positions (lots) so that the potential loss when a stop loss is triggered is a specified percentage of your deposit. This is the basis of effective money management.
You set: risk percentage (e.g. 2%) and stop loss price.
This function calculates how much you can trade so that your account loses no more than 2% if the price reaches your stop loss.
The function translates this into lots, taking into account your broker's instrument specifications.
Smart logic: automatically applies the correct formula to pairs like EURUSD and USDJPY .
Check: Monitor correct price, minimum and maximum lot sizes.
Ready for use: A function call that returns the lot size to be sent to the market order.
// Risk 1.5% of deposit by setting stop loss at 1.08500
double myLot = _Lot_( 1.5 , 1.08500 ); if (myLot > 0 ) {
// Open a position using the calculated lot size Trade.Sell(myLot, _symbol , 0 , 1.08500 , 0 , "Trade with 1.5% risk" );
}Bottom line: This code gets rid of manual calculations and helps you maintain risk discipline on every trade. Just plug it into your EA or script.
Find the perfect trading time frame
WPR indicator in chart window with TPSL
Overbought and oversold indicators are designed to identify where a price reversal may occur.
Draw colored range boxes for Asia, London and New York sessions on any chart. Includes a statistics panel showing the average trading session range in pips and optional breakout alerts when price exits a trading session.
Attachment download
📎 Percent_of_Deposit.mqh (4.42 KB)
📎 Screenshot_1.png (76.81 KB)
📎 nCalculate_Lot_by_Percent.mq5 (3.01 KB)
Source: MQL5 #68396
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •