Position Size Calculator (MetaTrader indicator) tells you how many lots to trade based on:
- Given entry and stop-loss levels
- Risk tolerance
- Account size (balance, equity, or even your savings account)
- Account currency
- Price of the quote currency (when different from account currency)
Its main features include:
- The calculation inputs and results are displayed inside a graphical panel.
- The panel can be moved freely across the chart.
- You can easily close or minimize it.
- All calculation parameters can be adjusted inside the panel in one or two mouse clicks.
- Entry, stop-loss, and take-profit lines can be dragged directly on the chart.
- If take-profit is given, the calculator shows the potential reward level and the risk-to-reward ratio.
- Supports pending and instant orders (easy switching).
- You can see current and potential risk profile.
- Information about required margin is available in a separate tab.
- Calculator can show the maximum position size based on available margin.
- You can enter a custom leverage to calculate position margin based on it.
- Detailed swaps (rollover interest) information is available in a separate tab.
- Optional spread display.
- Optional display of the pip value for the calculated position size.
- The indicator automatically saves and loads its inputs on timeframe change or platform restart, preserving your configuration efforts.
- Custom profiles restore panel's location, status, and settings.
- Completely free and open-source project.
- Does not require any DLL imports.
- Can be used together with a trading script (PSC-Trader) to make it easy for traders to open positions based on the calculations.
It is an evolution of the text-based legacy version of the same indicator and is an adaptation of the free online tool by the same name. Position Size Calculator is available for both MT4 and MT5.
The main tab of the panel provides the primary control over the indicator's functions and serves to output the most important calculation results — position size, risk, reward, and risk-to-reward ratio. The following controls and outputs are available:
- Indicator's version number.
- Spread value in ticks.
- Minimization button to fold down the panel.
- Close button to remove the indicator from the chart.
- Main tab switch — it is currently turned on.
- Risk tab switch — click it to see the current and potential risk profile. The Risk tab interface is explained below.
- Margin tab switch — click it to see everything related to required and free margin. The Margin tab interface is explained below.
- Swaps tab switch — click it to see the details on the swaps for the current trading instrument. The Swaps tab interface is explained below.
- Script tab switch — click it to see controls for the PSC-Trader script. The Script tab interface is explained below.
- Entry input — grayed out when Instant order is used, can be used enter entry level when Pending order is set.
- Stop-loss input.
- Take-profit input.
- Take-profit button allows quick setting of TP to the level equal to the current SL value.
- Take-profit multiplier, if set via input parameters, applies to the current SL value when Take-profit button is pressed.
- Order type button to switch between Instant and Pending.
- Hide/show lines button to quickly switch the display of the Entry, Take-profit, and Stop-loss lines on the chart.
- Commission size per lot — set it if your broker charges commission and you want it included into risk size when calculating position size.
- Account size in account currency units.
- Account size asterisk signals that additional funds are set via input parameters; the funds were added to the account size value.
- Account size button switches between balance, equity, and "Balance - CPR"; the latter being account balance less the current portfolio risk as calculated on the Risk tab.
- Risk input — you can set your tolerated risk in percentage of the account size. If you set your risk via Risk money input, percentage risk will be calculated based on that input.
- Risk money input — you can set your tolerated risk in account currency units. If you set your risk via Risk percentage input, money risk will be calculated based on that input.
- Risk (result) — percentage risk calculated based on the actual position size allowed in your broker's platform.
- Risk money (result) — money risk calculated based on the actual position size allowed in your broker's platform.
- Reward in account currency is based on the position size calculated without taking into account platform's restrictions.
- Reward (result) — reward in account currency is based on the actual position size allowed in your broker's platform.
- Reward/risk ratio — reward divided by risk.
- Position size — actual position size calculation output.
- Pip value per calculated position size.
The risk tab can help you assess current and potential risk profile. Using simple algorithm, the indicator calculates the risk of the currently open positions and pending orders based on their stop-loss levels (or lack thereof). The employed risk analysis method does not account for complex situations involving hedged orders and positions. You can use the Risk Calculator indicator for a deeper portfolio risk analysis. You can control the Risk tab using two checkboxes and see the calculation results in four output fields:
- Count pending orders — if checked, the indicator will also attempt to calculate the risk of pending orders in addition to currently open positions.
- Ignore orders without stop-loss — if checked, will simply ignore all risk coming from orders and positions without SL value set. Can be useful if you prefer not to set stop-loss for some of your trades.
- Current portfolio risk (currency) — shows the risk in currency units without the position being currently calculated by this indicator.
- Potential portfolio risk (currency) — shows the risk in currency units as if you have already opened a position, which is currently calculated by this indicator.
- Current portfolio risk (%) — same as Current portfolio risk (currency) but in percentage to the account size.
- Potential portfolio risk (%) — same as Potential portfolio risk (currency) but in percentage to the account size.
The margin tab provides information about the calculated position's margin, amount of used and available margin after opening the calculated position, and the biggest possible position size considering the current available margin and leverage. The tab has only one input and five output fields:
- Position margin shows the margin that will be used for the calculated position. Negative value means that the future used margin will be lower than the current due to lower requirement for margin of the hedged positions.
- Future used margin is calculated based on the current used margin and position margin.
- Future free margin shows how much free margin you will have left after opening the calculated position.
- Default leverage shows the account's actual leverage for your reference.
- Maximum position size by margin displays the biggest trade you can take with your currently available free margin and leverage.
- Custom leverage input lets you set your own leverage for all the margin calculations done by this indicator.
- Symbol leverage shows the actual leverage for the current trading instrument. It is calculated based on required margin and contract size/value. It may be inaccurate in some cases.
The swaps tab displays details on the overnight interest payments associated with the current trading instrument and calculated position size. It shows swaps type, nominal swaps, daily, yearly, per lot, per calculated position size, and both for long and short positions:
- Type shows the type of swaps used by the broker for the current trading instrument. Can be one of several kinds: pips/points, base currency, interest, account currency, margin currency, reopening.
- Triple swap shows the day of week when triple swaps are charged/paid (to account for Saturday and Sunday).
- Nominal swaps — nominal swaps paid or charged by a broker for long and short positions.
- Daily swap per lot — daily swap paid or charged by a broker for long and short positions in account currency per lot.
- Daily swap per PS — daily swap paid or charged by a broker for long and short positions in account currency for calculated position size (on the Main tab).
- Yearly swap per lot — swap paid or charged by a broker for long and short positions in account currency per lot. Calculated for a period of 360 days.
- Yearly swap per PS — swap paid or charged by a broker for long and short positions in account currency for calculated position size (on the Main tab). Calculated for a period of 360 days.
- Position size duplicates the display of the position size calculated by the indicator on the Main tab.
The script tab serves to provide you with some control over the trading script. You may skip this tab if you are not using PSC-Trader.
- Magic number — Magic number that will be assigned to the orders and positions opened using the script.
- Order commentary — commentary for orders and positions opened using the script.
- Disable trading when lines are hidden — a simple checkbox to prevent script from opening a position when you have chosen to hide the lines via the Main tab.
- Max slippage — maximum tolerable slippage value (in broker pips) that will be used in trading functions of the script.
- Max spread — the script will not trade if current spread is wider than the value given here.
- Max Entry/SL distance — the script will not trade if distance between the Entry level and Stop-Loss level becomes greater than this value.
- Min Entry/SL distance — the script will not trade if distance between the Entry level and Stop-Loss level becomes less than this value.
- Max position size — the script will not trade if calculated position size exceeds this value (in lots).
Using this indicator is very simple if your main aim is to calculate the position size based on your stop-loss and current market parameters.
- Attaching Position Size Calculator to a chart will automatically set an entry level to the current price, preparing for a market buy order. Stop-loss level will be set to nearest low. Take-profit will be turned off.
- Now, you can already use its position size output to enter a trade if you planned a market buy order with SL set to the low of the current bar and with 1% of balance risk.
- If not, you can freely change the stop-loss — either by dragging the stop-loss line on chart or by entering the value into the stop-loss input in the panel.
- You can set take-profit the same way. Additionally, you can quickly set TP equal to the current SL value (or with some preset multiplier) by clicking the Take-profit button.
- Adding take-profit will turn on the display of Reward and Reward/risk ratio for your information.
- Switching the type of order from Instant to Pending (and backwards) is done with the order type button. When Instant order is used, the Entry level will trail the current price (Bid or Ask) and cannot be manually changed. When Pending order is used, the Entry level can be set either via panel's input or by dragging the chart line.
- The indicator will warn if the Entry level is too close to the current price in Pending order mode and if the Stop-loss or Take-profit level are too close to the Entry level.
- You can set the size of commission applied by your broker if you want your potential loss to be calculated including this cost of trading.
- Switching account size from balance to equity or to balance minus portfolio risk can be useful in some cases and is done by a one or two clicks on the respective button.
- Adjusting the risk tolerance can be done in two ways: by setting percentage risk value or by setting money risk value. Both are done via input fields in the panel.
- Moving on to the Risk tab of the panel is completely optional and provides information about your current and potential risk. You can control how pending orders and orders without stop-loss are treated in this tab.
- Margin tab is not necessary too if your goal is to calculate the optimal position size based on your risk and stop-loss. This tab will inform you on amount of free and used margin resulting from your position. It will also show you what is the biggest position size that you can open with your current free margin and leverage. A custom leverage can be entered if need arises.
- Swaps tab can be consulted if you wish to know how costly the daily rollover will be for your position. It will be especially useful if you are using a carry trade strategy.
- Script tab will help you to control how the PSC-Trader script behaves if you use it for position opening.
The indicator has a set of input parameters besides the panel-based controls. Calculator's display options and a number of default options are set via standard MetaTrader inputs.
- ShowLineLabels (default = true) — if true, SL and TP distance in pips will be shown below stop-loss and take-profit lines.
- DrawTextAsBackground (default = false) — if true, the line labels will be drawn as background. It can be useful if the labels are obscuring something on the chart.
- PanelOnTopOfChart (default = true) — if true, the panel will be drawn on foreground, and the chart will be drawn as background. Setting it to false will uncover the chart behind the panel.
- HideAccSize (default = false) — if true, account size display and button will be hidden.
- ShowPipValue (default = false) — if true, pip value will be displayed in the bottom of the Main tab.
- SL Label Font Color (default = clrLime) — font color for stop-loss line label.
- TP Label Font Color (default = clrYellow) — font color for take-profit line label.
- Labels Font Size (default = 13) — font size for the text in labels.
- Labels Font Face (default = "Courier") — font face for the text in labels.
- Entry Line Color (default = clrBlue) — color of the entry line.
- Stop-Loss Line Color (default = clrLime) — color of the stop-loss line.
- Take-Profit Line Color (default = clrYellow) — color of the take-profit line.
- Entry Line Style (default = STYLE_SOLID) — entry line style.
- Stop-Loss Line Style (default = STYLE_SOLID) — stop-loss line style.
- Take-Profit Line Style (default = STYLE_SOLID) — take-profit line style.
- Entry Line Width(default = 1) — entry line width.
- Stop-Loss Line Width (default = 1) — stop-loss line width.
- Take-Profit Line Width (default = 1) — take-profit line width.
- Risk (default = 1) — default value for percentage risk. Can be changed via the panel later.
- EntryType (default = Instant) — default order type. Can be changed via the panel later.
- Commission (default = 0) — default commission size. Can be changed via the panel later.
- Commentary (default = "") — default order commentary for PSC-Trader script. Can be changed via the panel later.
- TP_Multiplier (default = 1) — multiplier value for take-profit button.
- ShowSpread (default = false) — if true, current spread value in ticks will be displayed inside the panel's caption.
- AdditionalFunds (default = 0) — funds to be added to the account size for the purpose of risk and position size calculation. For example, this could be some funds you hold outside the broker's account but consider a part of your Forex risk capital.
The main tab is the biggest one and looks nice on any background — this one is white for example. Take-profit line's color has been changed to orange via an input parameter for better readability.
Black background color and chart grid do not interfere with the panel as you can see on this screenshot of the Risk tab. The risk outputs show Infinity as there is, apparently, a sell order without stop-loss.
Even the wildest color scheme works well with Position Size Calculator. In this case, cyan background is combined with green and red candlesticks. Stop-loss color is set to black.
This example shows swaps tab with a classic black and white color scheme chart. This broker is charging some serious rollover fees for margin trading in Bitcoin.
When the panel is set to background, it becomes transparent and you can easily analyze the exposed chart. At the same time, you are able to see the values used for trading script management on this tab.
Minimizing the panel in one click makes it completely non-obtrusive and allows trader to easily see the whole chart.
Downloads (ver. 2.11, 2017-11-08)
Position Size Calculator for MetaTrader 4
Position Size Calculator for MetaTrader 5
To install the indicator, make sure that you copy all three files to /MQL4/Indicators/ or /MQL5/Indicators/ (if you are on MetaTrader 5) or to the same subfolder there:
- PositionSizeCalculator.mq4 or PositionSizeCalculator.mq5
You need to compile PositionSizeCalculator.mq4 (or PositionSizeCalculator.mq5) not the other two.
You can use the position size output of this indicator to open trades manually in the same or in some other platform. Additionally, you can use a custom trading script that will open trades based on the calculated position size and with the given entry, SL, and TP levels. Just copy it to /MQL4/Scripts/ (or /MQL5/Scripts/) subfolder of your platform's data folder. After compilation, It will become available in the Navigator subwindow of your trading terminal under Scripts as PSC-Trader. You can also set a hotkey to run this script if you want to open orders really fast. The script's behavior is controlled via Script tab of the Position Size Calculator.
Download script (ver. 1.05, 2017-08-25)
Do you have any suggestions or questions regarding this indicator? You can always discuss Position Size Calculator with other traders and MQL programmers in the forum.
You can also subscribe to our monthly newsletter to keep yourself updated about future changes to Position Size Calculator indicator.
2.11 — 2017-11-08
- Fixed a bug that prevented proper panel initialization (e.g. wrong Pending/Instant button state, two panels appearing after template application, etc.).
- Fixed a bug in MT5 version that prevented proper change of input parameters.
2.10 — 2017-10-12
- The panel's location will now remain unchanged when minimizing and maximizing it.
- Changing the indicator's input parameters Risk, EntryType, Commission, and Commentary will now update the respective panel fields without the need to reattach the indicator.
- Fixed a bug with the labels — they will now disappear immediately when the ShowLineLabels parameter is changed to false.
2.09 — 2017-08-31
- Input parameters now have priority when changing the settings (color/style/width) of the lines (entry/SL/TP). This fixes a bug that caused lines to remain unaltered when you updated the inputs. If you want to change the lines' look, please do it via the indicator's input parameters.
- Fixed a bug when, in the MT5 version only, the line label colors depended on the line colors input parameters rather than on the label colors input parameters.
2.08 — 2017-08-25
- Added persistence of panel location, status, and parameters through chart profile changes.
- Added optional pip value display.
- Added account currency code near reward display.
- Fixed a minor bug with the hide/show lines button.
- MT5 version of PSC-Trader script 1.04 or older will not work with the calculator versions 2.08 and newer.
2.07 — 2017-07-24
- Added take-profit button multiplier for fast TP adjustment.
- Added spread display in the panel's caption. NB: It uses ticks, not standard pips.
- Added input parameter for additional funds to be applied to the account size.
- Added default parameters (can be saved in chart templates): Commission, Order Commentary, Take-Profit Multiplier, Show Spread, Additional Funds.
- Fixed a bug with the panel's caption disappearing above the screen's top border.
2.06 — 2017-03-14
- Fixed a bug with how the panel remembers its minimized/maximized state.
2.05 — 2017-02-18
- Fixed two potential division by zero errors.
2.04 — 2016-12-21
- Added DPI scaling for high-resolution displays.
- Added Magic number and order commentary for trading script.
- Reinstated HideAccSize input parameter for compactness.
- Reinstated Risk and EntryType input parameters for template convenience.
- Fixed compilation errors in latest MT4/MT5 builds.
- Fixed a bug with incorrect decimal places count for nominal swap rates.
- SL/Entry lines are no longer saved to templates.
2.03 — 2016-11-11
- Added 3rd state in balance button: Balance - CPR.
- Added tab with Swaps details.
- Added tab with Script settings.
- Panel now remembers its minimized/maximized state and X/Y position.
- Added PanelOnTopOfChart input parameter.
- Added display update on timer.
- Fixed bug with TP line showing on top of panel when adding TP via button.
- Fixed bug with deinitialization on parameters change and recompilation.
- Fixed bug with margin calculation when using custom leverage.
- Optimized execution (removed unnecessary MarketInfo() calls).
2.02 — 2016-09-23
- Fixed bug with panel disappearing upon change of timeframe.
2.01 — 2016-09-20
- Added Symbol leverage display to Margin tab.
- Fixed panel resizing bug.
- Fixed duplicate panel bug.
- Optimized interface.
- Optimized code.
2.00 — 2016-09-07
- First version of PSC with graphical panel interface.
The legacy version of Position Size Calculator is the text version of the same indicator that was developed and supported during 2012-2016. It is still fully functional and is compatible with the latest builds of MetaTrader platform.
It is less powerful and has a more complex interface than the current panel version, but it can still do the job — calculate the position size based on the given entry/stop-loss levels, risk tolerance, and the current market data, such as account size and currency, and the price of the quote currency of the traded pair relatively to the account currency.
The result is displayed as a text label in the main or separate chart window. Traders can adjust many parameters, both for calculation and for display.
You may choose the legacy version of the PSC over the graphical one if you prefer. However, the former is no longer developed, though bug reports will be considered. Below, follows the description of the legacy version.
- ShowPortfolioRisk (default = false) — if true, then portfolio risk will be calculated based on open positions and/or orders.
- ShowMargin (default = false) — if true, then margin information for the planned position will be shown.
- EntryType (default = Instant) — if Instant, then entry level will trail the current Ask/Bid rate; if Pending, entry is movable and warning is issued if entry is too close to current rate.
- EntryLevel (default = 0) — planned position entry price.
- StopLossLevel (default = 0) — planned position stop-loss price.
- TakeProfitLevel (default = 0) — planned position take-profit price. It is optional and is used only in reward/risk ratio calculation.
- Risk (default = 1) — tolerated risk in percentage points of the account balance/equity.
- MoneyRisk (default = 0) — tolerated risk in account currency.
- CommissionPerLot (default = 0) — your broker's commission per lot charged in account currency. Enter the value charged for one side of the trade, not round-turn.
- UseMoneyInsteadOfPercentage (default = false) — if true, then position size will be calculated based on risk tolerance given in money, not percentage.
- UseEquityInsteadOfBalance (default = false) — if true, then account equity is used instead of balance in calculations.
- DeleteLines (default = false) — if true, Entry and Stop-Loss lines will be deleted on deinitialization. Also, deletes the old lines on initialization. Otherwise, it will leave the lines on chart, so the levels could be restored on subsequent indicator initialization.
- CountPendingOrders (default = false) — if true, then portfolio risk calculation will involve pending orders.
- IgnoreOrdersWithoutStopLoss (default = false) — if true, orders and positions without stop-loss will not be ignored in portfolio risk calculation.
- HideAccSize (default = false) — if true, the account size line will not be shown.
- HideSecondRisk (default = false) — if true, the second risk line will not be shown.
- HideEmpty (default = false) — if true, the empty line before divider will not be shown.
- ShowLineLabels (default = true) — if true, SL and TP distance in pips will be shown below stop-loss and take-profit lines.
- DrawTextAsBackground (default = false) — if true, all text label graphical objects used by the indicator will be drawn as background. It can be useful if you want to prevent the indicator from obscuring the chart.
- entry_font_color (default = clrBlue) — font color for entry level display.
- sl_font_color (default = clrLime) — font color for stop-loss level display.
- sl_label_font_color (default = clrLime) — font color for stop-loss line labels.
- tp_font_color (default = clrYellow) — font color for take-profit level display.
- tp_label_font_color (default = clrYellow) — font color for take-profit line labels.
- ps_font_color (default = clrRed) — font color of the position size result.
- rp_font_color (default = clrLightBlue) — font color for risk percentage display.
- balance_font_color (default = clrLightBlue) — font color for account size display.
- rmm_font_color (default = clrLightBlue) — font color for risk money display.
- margin_font_color (default = clrSlateBlue) — font color for margin display.
- stopout_font_color (default = clrRed) — font color for stop-out or 'not enough money' warning display.
- pp_font_color (default = clrLightBlue) — font color for potential profit display.
- rr_font_color (default = clrYellow) — font color for reward/risk ratio display.
- div_font_color (default = clrSlateGray) — font color for text divider/header.
- font_size (default = 12) — font size of the displayed text.
- font_face (default = "Courier") — font face of the indicator.
- corner (default = CORNER_LEFT_UPPER) — location for the indicator's text. In MT4: 0 — for top-left corner, 1 — top-right, 2 — bottom-left, 3 — bottom-right. In MT5 it's quite obvious.
- distance_x (default = 10) — horizontal distance from the corner to the indicator's text.
- distance_y (default = 15) — vertical distance from the corner to the indicator's text.
- line_height (default = 15) — line height for output. Change it with the font face and size.
- entry_line_color (default = clrBlue) — color of the entry line.
- stoploss_line_color (default = clrLime) — color of the stop-loss line.
- takeprofit_line_color (default = clrYellow) — color of the take-profit line and the reward/risk ratio.
- entry_line_style (default = STYLE_SOLID) — entry line style.
- stoploss_line_style (default = STYLE_SOLID) — stop-loss line style.
- takeprofit_line_style (default = STYLE_SOLID) — take-profit line style.
- entry_line_width (default = 1) — entry line width.
- stoploss_line_width (default = 1) — stop-loss line width.
- takeprofit_line_width (default = 1) — take-profit line width.
- MaxNumberLength (default = 14) — the maximum expected number of digits in displayed values.
Using the indicator
Obviously, this indicator is not suitable for trading signals generation. Its purpose is to help Forex traders calculate position size for their allowed risk size and the given position parameters.
If both EntryLevel and StopLossLevel input parameters are set to zero, this indicator will try to put them at some local levels. You can drag the entry/stop-loss lines up and down directly on the chart. Position size value is recalculated every tick and on every line move.
A trader may also set TakeProfitLevel input parameter to see the calculated reward/risk ratio along with the position size.
Additionally, this indicator can track the whole portfolio risk based on the open trades and pending orders. However, the risk tracking is quite limited with this indicator. It is recommended to use a separate Risk Calculator for the purpose of risk analysis.
You can also use it to see the necessary margin and expected changes in margin based on the calculated size of the position.
You can also make it easier to trade based on the calculated position size. Just download our free MetaTrader script to place orders based on this calculator's output.
I change the StopLossLevel, TakeProfitLevel, or EntryLevel input parameters, but output values do not change and the lines remain at their old levels. Why does it happen and how do I fix this?
It happens because DeleteLines input parameter is set to false. This helps to preserve the level values set by moving the lines. If you want the lines to be updated according to the input parameters, please set DeleteLines to true or delete the lines manually.
Download legacy version (ver. 1.29, 2016-12-23)
Position Size Calculator (Separate Window) for MetaTrader 4
Position Size Calculator (Separate Window) for MetaTrader 5
Position Size Calculator (Main Window) for MetaTrader 4
Position Size Calculator (Main Window) for MetaTrader 5