Position Size Calculator (MetaTrader indicator)

Works with any trading instruments currency pairs, CFDs, equities, indices, commodities, futures, cryptocurrencies.

Calculation inputs and results are displayed inside a graphical panel.

The panel can be moved freely across the chart.

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.

You can choose to set stop-loss and/or take-profit as distance in points.

Alternatively, you can set them as multiples of ATR (Average True Range).

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 even calculate risk based on a given position size.

You can see current and potential risk and reward 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 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 panels location, status, and settings.

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 thetext-based legacy versionof the same indicator and is an adaptation of thefree online tool by the same name. Position Size Calculator is available for both MT4 and MT5, but the MT5 version looks differently and provides better functionality because the platform itself is more advanced.

The main tab of the panel provides the primary control over the indicators 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:

button to remove the indicator from the chart.

switch click it to see the current and potential risk profile. The Risk tab interface is explained below.

switch click it to see everything related to required and free margin. The Margin tab interface is explained below.

switch click it to see the details on the swaps for the current trading instrument. The Swaps tab interface is explained below.

switch click it to see controls for the PSC-Trader script. The Script tab interface is explained below.

input grayed out when Instant order is used, can be used enter entry level when Pending order is set.

allows quick setting of TP to the level equal to the current SL value.

, if set via input parameters, applies to the current SL value when Take-profit button is pressed.

button to switch between Instant and Pending.

button to quickly switch the display of the Entry, Take-profit, and Stop-loss lines on the chart.

(one-way) set it if your broker charges commission and you want it included into risk size when calculating position size.

signals that additional funds are set via input parameters; the funds were added to the account size value.

switches between balance, equity, and Balance – CPR; the latter being account balance less the current portfolio risk as calculated on the Risk tab.

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.

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.

percentage risk calculated based on the actual position size allowed in your brokers platform.

money risk calculated based on the actual position size allowed in your brokers platform.

in account currency is based on the position size calculated without taking into account platforms restrictions.

reward in account currency is based on the actual position size allowed in your brokers platform.

actual position size calculation output. You can modify it yourself if you want to calculate your risk based on position size.

multiplier for ATR-based stop-loss. The ATR value is multiplied by this value to produce the actual stop-loss distance. Set to zero to disable ATR-based stop-loss.

multiplier for ATR-based take-profit. The ATR value is multiplied by this value to produce the actual take-profit distance. Set to zero to disable ATR-based take-profit.

The risk tab can help you assess current and potential risk and reward 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). It also assesses the potential reward of already opened positions and the position calculated by the indicator based on take-profit levels. The employed risk analysis method does not account for complex situations involving hedged orders and positions. You can use theRisk Calculator indicatorfor a deeper portfolio risk analysis. You can control the Risk tab using two checkboxes and see the calculation results in ten output fields:

if checked, the indicator will also attempt to calculate the risk of pending orders in addition to currently open positions.

if checked, will simply ignore all risk coming from orders and positions without SL/TP value set. Can be useful if you prefer not to set stop-loss/take-profit for some of your trades.

shows the risk in currency units without the position, which is currently being calculated by this indicator.

shows the risk in currency units as if you have already opened a position, which is currently calculated by this indicator.

shows the reward in currency units without the position, which is currently being calculated by this indicator.

shows the reward in currency units as if you have already opened a position, which is currently calculated by this indicator.

the total size of the currently open positions in lots.

the total size in lots of the open positions plus the one, which is currently being calculated by this indicator.

The margin tab provides information about the calculated positions 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:

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.

is calculated based on the current used margin and

shows how much free margin you will have left after opening the calculated position.

shows the accounts actual leverage for your reference.

displays the biggest trade you can take with your currently available free margin and leverage.

input lets you set your own leverage for all the margin calculations done by this indicator.

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:

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.

shows the day of week when triple swaps are charged/paid (to account for Saturday and Sunday).

nominal swaps paid or charged by a broker for long and short positions.

daily swap paid or charged by a broker for long and short positions in account currency per lot.

daily swap paid or charged by a broker for long and short positions in account currency for calculated position size (on the Main tab).

swap paid or charged by a broker for long and short positions in account currency per lot. Calculated for a period of 360 days.

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.

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 thetrading script. You may skip this tab if you are not using PSC-Trader.

Magic number that will be assigned to the orders and positions opened using the script.

commentary for orders and positions opened using the script.

a simple checkbox to prevent script from opening a position when you have chosen to hide the lines via the Main tab.

maximum tolerable slippage value (in broker pips) that will be used in trading functions of the script.

the script will not trade if current spread is wider than the value given here.

the script will not trade if distance between the Entry level and Stop-Loss level becomes greater than this value.

the script will not trade if distance between the Entry level and Stop-Loss level becomes less than this value.

if calculated position size exceeds this value (in lots), the script will only open a trade of the size given in this field.

if checked, the script will calculate the total open volume for a given trading instrument and will subtract it from the calculated position size, so the resulting volume after a new trade opens is equal to the calculated position size.

if checked, the script will calculate the total volume of all pending orders on a given trading instrument and will subtract it from the calculated position size, so the resulting volume after a new trade opens is equal to the calculated position size.

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

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. You can also change the position size field manually to calculate the risk based on its value.

either by dragging the stop-loss line on chart or by entering the value into the stop-loss input in the panel. You can also set stop-loss as distance in pips by turning on the respective input parameter.

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. Similarly to stop-loss, take-profit can be set as distance in pips if the respective input parameter is turned on.

If you turn on ATR settings via the indicators input parameters, you can also control the

ATR values for stop-loss and take-profit calculation

Adding take-profit will turn on the display of

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 panels input or by dragging the chart line.

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.

(one-way) applied by your broker if you want your potential loss to be calculated including this cost of trading.

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

value. Both are done via input fields in the panel.

of the panel is completely optional and provides information about your current and potential risk and reward. You can control how pending orders and orders without stop-loss/take-profit are treated in this 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.

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 acarry trade strategy.

will help you to control how the PSC-Trader script behaves if you use it for position opening.

This video demonstrates how you can use the Position Size Calculator indicator, showcasing most of it functions:

The indicator has a set of input parameters besides the panel-based controls. Calculators display options and a number of default options are set via standard MetaTrader inputs.

, SL and TP distance in pips will be shown below stop-loss and take-profit lines.

, the line labels will be drawn as background. It can be useful if the labels are obscuring something on the chart.

, the panel will be drawn on foreground, and the chart will be drawn as background. Setting it to

, account size display and button will be hidden.

, pip value will be displayed in the bottom of the Main tab.

(default = clrLime) font color for stop-loss line label.

(default = clrYellow) font color for take-profit line label.

(default = 13) font size for the text in labels.

(default = Courier) font face for the text in labels.

(default = clrBlue) color of the entry line.

(default = clrLime) color of the stop-loss line.

(default = clrYellow) color of the take-profit line.

(default = STYLE_SOLID) stop-loss line style.

(default = STYLE_SOLID) take-profit line style.

(default = 1) default value for percentage risk. Can be changed via the panel later.

(default = Instant) default order type. Can be changed via the panel later.

(default = 0) default commission size. Can be changed via the panel later.

(default = ) default order commentary for PSC-Trader script. Can be changed via the panel later.

(default = 0) if non-zero, the stop-loss level of a newly attached Position Size Calculator will be set to this value in pips.

(default = 0) if non-zero, the take-profit level of a newly attached Position Size Calculator will be set to this value in pips.

(default = 1) multiplier value for take-profit button.

, current spread value in ticks will be displayed inside the panels caption.

(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 brokers account but consider a part of your Forex risk capital.

, stop-loss will be set in pips and the SL line will be following the entry line.

, take-profit will be set in pips and the TP line will be following the entry line.

, the tick value used in position size calculation will be multiplied by the contract size when working with CFDs. Toggle this input if your position size seems off by an order of magnitude or two. This parameter is available only in MT5 version of the indicator.

, the panel will display options for ATR indicator to be used for SL/TP calculation.

This explantion video below demonstrates how changing the parameters described above change the Position Size Calculators behavior:

The main tab is the biggest one and looks nice on any background this one is white for example. Take-profit lines 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 showInfinityas 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 inBitcoin.

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.

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:

You need to compilePositionSizeCalculator.mq4(orPositionSizeCalculator.mq5) not the other two.

This how-to video explains how to install Position Size Calculator in MetaTrader 5 platform, but the process is very similar for MetaTraer 4:

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 acustom trading scriptthat 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 platforms data folder. After compilation, It will become available in the Navigator subwindow of your trading terminal under Scripts asPSC-Trader. You can also set a hotkey to run this script if you want to open orders really fast. The scripts behavior is controlled via Script tab of the Position Size Calculator.

Warning!If you do not know how to install this indicator, please read theMetaTrader Indicators Tutorial.

Do you have any suggestions or questions regarding this indicator? You can alwaysdiscuss Position Size Calculatorwith other traders and MQL programmers in the forum.

You can also subscribe to ourmonthly newsletterto keep yourself updated about future changes to Position Size Calculator indicator.

Changed the way the indicator behaves when loading a saved chart template with PSC the take-profit line is now removed.

Fixed a bug that caused take-profit to reset when switching from normal level to TP based on pip distance.

input parameters to be applied slightly incorrectly.

Fixed a bug that prevented cleanup of the old panel objects after loading a template with PSC in it.

Fixed a potential division by zero error when data for a currency conversion symbol arent yet available.

Fixed panel hiding outside the charts borders when resizing the chart window.

Added ATR options to the calculators panel (turn on by setting

) to calculate stop-loss and take-profit based on the Average True Range indicator.

Added reverse calculation you can set position size to calculate its risk.

Added display of the potential reward profile to the

Fixed a bug when SL/TP lines could be moved to invalid value; now they will stick to the nearest tick size multiple.

Fixed a bug when Position Size Calculator could not save its settings correctly when working with a trading symbol that had three periods in its name (for example, EURUSD…).

Fixed a bug with the maximum position size field on the

tab rounding incorrectly after switching timeframes or restarting the platform.

Fixed a bug with incorrect take-profit value showing up if

Fixed a bug that could cause slightly incorrect SL/TP values to show up due to a rounding error.

Fixed a bug with poor number formatting, which caused wrong calculation results showing up.

Added an input parameter for adjusting CFD position size calculation (

) when tick value is incorrectly set on the brokers trading server.

Added input parameters for default stop-loss and take-profit values.

Added support for 8 decimal places (down to 0.00000001) in position size calculation for use withcryptocurrenciesin MT5.

Added clarification that commission size is set as one-way.

Fixed a reward value not taking into account the given commission size.

Fixed the number of decimal places used in position size display based on symbols properties.

Fixed multiple bugs when margin and account currencies were not converted to the account currency.

Fixed a bug when loading a chart template with PSC with non-zero take-profit did not show all relevant fields on the panel.

Fixed a bug when adding second position size calculator to the chart was not prevented properly by MetaTrader 4.

Fixed symbol leverage calculation for non-Forex symbols in MT5.

Added two checkboxes to instruct the PSC-Trader script to open a trade taking into account currently open positions or pending orders.

field it will now open a trade even if the calculated position size exceeds the given maximum, but will bring the position size down to that maximum.

Fixed trading script execution when working with hedging mode with market execution in MetaTrader 5.

Fixed another bug in MetaTrader 5 PSC-Trader, which prevented proper setting of SL/TP in market execution mode.

Fixed reward calculation that could be wrong in some cases.

Added capability to set SL and TP as distance in points to the entry line.

Fixed another bug with wrong position size calculation for non-Forex trading instruments in both MT4 and MT5 versions of the indicator.

Fixed a bug that resulted in wrong position size and pip value calculated for CFD trading instruments in MetaTrader 5 version of the indicator.

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.

The panels location will now remain unchanged when minimizing and maximizing it.

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

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 indicators 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.

Added persistence of panel location, status, and parameters through chart profile changes.

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.

Added take-profit button multiplier for fast TP adjustment.

Added spread display in the panels 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 panels caption disappearing above the screens top border.

Fixed a bug with how the panel remembers its minimized/maximized state.

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.

Added 3rd state in balance button: Balance – CPR.

Panel now remembers its minimized/maximized state and X/Y position.

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).

Fixed bug with panel disappearing upon change of timeframe.

First version of PSC with graphical panel interface.

Thelegacy versionof 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, thoughbug reportswill be considered. Below, follows the description of the legacy version.

, then portfolio risk will be calculated based on open positions and/or orders.

, then margin information for the planned position will be shown.

, then entry level will trail the current Ask/Bid rate; if

, entry is movable and warning is issued if entry is too close to current rate.

(default = 0) planned position entry price.

(default = 0) planned position stop-loss price.

(default = 0) planned position take-profit price. It is optional and is used only in reward/risk ratio calculation.

(default = 1) tolerated risk in percentage points of the account balance/equity.

(default = 0) tolerated risk in account currency.

(default = 0) your brokers commission per lot charged in account currency. Enter the value charged for one side of the trade, not round-turn.

, then position size will be calculated based on risk tolerance given in money, not percentage.

, then account equity is used instead of balance in calculations.

, 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.

, then portfolio risk calculation will involve pending orders.

, orders and positions without stop-loss will not be ignored in portfolio risk calculation.

, the empty line before divider will not be shown.

, SL and TP distance in pips will be shown below stop-loss and take-profit lines.

, 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.

(default = clrBlue) font color for entry level display.

(default = clrLime) font color for stop-loss level display.

(default = clrLime) font color for stop-loss line labels.

(default = clrYellow) font color for take-profit level display.

(default = clrYellow) font color for take-profit line labels.

(default = clrRed) font color of the position size result.

(default = clrLightBlue) font color for risk percentage display.

(default = clrLightBlue) font color for account size display.

(default = clrLightBlue) font color for risk money display.

(default = clrSlateBlue) font color for margin display.

(default = clrRed) font color for stop-out or not enough money warning display.

(default = clrLightBlue) font color for potential profit display.

(default = clrYellow) font color for reward/risk ratio display.

(default = clrSlateGray) font color for text divider/header.

(default = 12) font size of the displayed text.

(default = Courier) font face of the indicator.

(default = CORNER_LEFT_UPPER) location for the indicators text. In MT4: 0 for top-left corner, 1 top-right, 2 bottom-left, 3 bottom-right. In MT5 its quite obvious.

(default = 10) horizontal distance from the corner to the indicators text.

(default = 15) vertical distance from the corner to the indicators text.

(default = 15) line height for output. Change it with the font face and size.

(default = clrBlue) color of the entry line.

(default = clrLime) color of the stop-loss line.

(default = clrYellow) color of the take-profit line and the reward/risk ratio.

(default = STYLE_SOLID) stop-loss line style.

(default = STYLE_SOLID) take-profit line style.

(default = 14) the maximum expected number of digits in displayed values.

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 po