Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Views:
90
Rating:
(2)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance


Module of lot calculation by risk percentage

Purpose:

Automatically calculates the size of a trading position (lot) so that the potential loss when a stop loss is triggered is a specified percentage of your deposit. This is the basis of competent money management.

How it works:

  1. You set:risk percentage (for example, 2%) and stop loss price.

  2. The function calculateshow much you can trade for to lose no more than 2% of your account if the price reaches the stop.

  3. The function translates this amount into lots, taking into account the specification of the instrument at your broker.

Key features:

  • Smart logic: automatically applies the correct formula for pairs like EURUSD and USDJPY .

  • Checks: monitors correct prices, minimum and maximum lots.

  • Ready to use: one function call returns the lot to be sent to the market order.

Example of use in the code:

// Risk 1.5% of the deposit by placing a stop loss at 1.08500
double myLot = Calculate_Lot_by_Percent(1.5, 1.08500);

if(myLot > 0) {
    // Open a deal with the calculated lot
    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 in every trade. Simply plug it into your EA or script.


Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/68396

Timeframe Quality Analyzer Timeframe Quality Analyzer

Find Perfect Timeframe to trade

WPR With TPSL WPR With TPSL

WPR indicator in chart window with TPSL

WPR for Overbought and Oversold WPR for Overbought and Oversold

Overbought and oversold indicators aim to determine where the price may experience a reversal.

MACD Signals MACD Signals

Indicator edition for new platform.