Position Size Calculator
Position Size Calculator is now an expert advisor.
Please proceed to the new description page:
This old Position Size Calculator (ver. 2.xx) is no longer developed.
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:
- 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.
- 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.
- 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 spread display.
- Optional display of the point 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. The trading script can also divide the position into several trades with different take-profit levels.
- Supports stop limit orders in MetaTrader 5.
This indicator is an evolution of the free 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 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.
- Long/Short switch — enables you to quickly switch between long and short trade calculation. The trade direction can also be switched by pressing the Tab key on your keyboard.
- Entry input — grayed out when Instant order is used, can be used enter entry level when Pending order is set.
- Stop-loss button will set stop-loss level to a given default value. Visible only if a non-zero default stop-loss is set via SL input parameter.
- Stop-loss input.
- Take-profit button allows quick setting of TP to the multiple of the current SL value or to peg the TP level to the SL value.
- Take-profit multiplier, if set via input parameters, applies to the current SL value when Take-profit button is pressed.
- Take-profit input.
- Multiple take-profit input fields. Visible if ScriptTakeProfitsNumber input parameter is set to a value greater than 1.
- Stop price input (for stop limit orders).
- ATR Period — setting to use with the ATR-based SL/TP. ATR options are visible only if ShowATROptions input parameter is set to true.
- ATR — current value of ATR with a given period. ATR options are visible only if ShowATROptions input parameter is set to true.
- SL multiplier — 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. ATR options are visible only if ShowATROptions input parameter is set to true.
- TP multiplier — 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. ATR options are visible only if ShowATROptions input parameter is set to true.
- ATR timeframe — timeframe to calculate ATR on. Click the button to switch between timeframes. ATR options are visible only if ShowATROptions input parameter is set to true.
- Order type button to switch between Instant, Pending, and Stop Limit.
- 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 (one-way) — set it if your broker charges commission and you want it included into risk size when calculating position size.
- 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.
- Account size in account currency units.
- Account size asterisk signals that either custom account balance or additional funds are set via input parameters; the funds were added to the account size value.
- Quick risk button #1 — first button to quickly set percentage risk value.
- Quick risk button #2 — second button to quickly set percentage risk value.
- 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 (input) — input reward divided by input risk.
- Reward/risk ratio (result) — reward result divided by risk result.
- Position size — actual position size calculation output. You can modify it yourself if you want to calculate your risk based on position size.
- Point value per calculated position size.
- Max PS button to set the position size to the maximum value possible based on the account's free margin. The button only appears if the ShowMaxPSButton input parameter is set to true.
- Direction arrow shows whether the current trade is long (▲) or short (▼). In MT4 version, it is written in words.
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 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 ten 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/take-profit — 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.
- Ignore orders in other symbols — if checked, will only calculate risk and reward for the current chart's symbol, ignoring all positions and orders in other symbols.
- Current portfolio risk (currency) — shows the risk in currency units without the position that is currently being calculated by this indicator.
- Potential portfolio risk (currency) — shows the risk in currency units as if you have already opened a position that 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.
- Current portfolio reward (currency) — shows the reward in currency units without the position that is currently being calculated by this indicator.
- Potential portfolio reward (currency) — shows the reward in currency units as if you have already opened a position that is currently calculated by this indicator.
- Current portfolio reward (%) — same as Current portfolio reward (currency) but in percentage to the account size.
- Potential portfolio reward (%) — same as Potential portfolio reward (currency) but in percentage to the account size.
- Current portfolio lots — the total size of the currently open positions in lots.
- Potential portfolio 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 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.
- Custom leverage input lets you set your own leverage for all the margin calculations done by this indicator.
- Default leverage shows the account's actual leverage for your reference.
- 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.
- Maximum position size by margin displays the biggest trade you can take with your currently available free margin and leverage.
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: 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 (Long) — nominal swaps paid or charged by a broker for long positions.
- Nominal swaps (Short) — nominal swaps paid or charged by a broker for short positions.
- Daily swap per lot (Long) — daily swap paid or charged by a broker for long positions in account currency per lot.
- Daily swap per lot (Short) — daily swap paid or charged by a broker for short positions in account currency per lot.
- Daily swap per PS (Long) — daily swap paid or charged by a broker for long positions in account currency for calculated position size (on the Main tab).
- Daily swap per PS (Short) — daily swap paid or charged by a broker for short positions in account currency for calculated position size (on the Main tab).
- Yearly swap per lot (Long) — swap paid or charged by a broker for long positions in account currency per lot. Calculated for a period of 360 days.
- Yearly swap per lot (Short) — swap paid or charged by a broker for short positions in account currency per lot. Calculated for a period of 360 days.
- Yearly swap per PS (Long) — swap paid or charged by a broker for long positions in account currency for calculated position size (on the Main tab). Calculated for a period of 360 days.
- Yearly swap per PS (Short) — swap paid or charged by a broker for 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.
- Fill take-profits inwards — a button to fill multiple take-profit fields equidistantly from Entry level to main Take-Profit level.
- Fill take-profits outwards — a button to fill multiple take-profit fields equidistantly with the main Take-Profit level as the closest one.
- Multiple take-profit levels — a number (set via ScriptTakeProfitsNumber input parameter) of take-profits to divide the position among. The first take-profit is always the same as the one set on the Main tab.
- Shares to divide the position size — each take-profit level is assigned its percentage of the total position size calculated on the Main tab.
- Max slippage — maximum tolerable slippage value (in points) 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 — if calculated position size exceeds this value (in lots), the script will only open a trade of the size given in this field.
- Subtract open positions volume — 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.
- Subtract pending orders volume — 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.
- Do not apply stop-loss — if checked, the script will open a trade without stop-loss. This can be useful if you use a separate expert advisor or some other means to trigger your stop-loss.
- Do not apply take-profit — if checked, the script will open a trade without take-profit. This can be useful if you use a separate expert advisor or some other means to trigger your take-profit.
- Ask for confirmation — if checked, the script will ask for confirmation before trading.
- Auto-suffix — if checked, the script will append a unique suffix to the order commentary set up above. This can be particularly useful when you want to set the same commentary for all parts of a multi-TP trade, but you want the next multi-TP trade to use a different commentary.
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 the 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. You can also change the position size field manually to calculate the risk based on its value.
- 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 also set stop-loss as distance in points by turning on the respective input parameter.
- 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. Similarly to stop-loss, take-profit can be set as distance in points if the respective input parameter is turned on. Multiple take-profit levels are supported when ScriptTakeProfitsNumber input parameter is set to a value greater than 1.
- If you turn on ATR settings via the indicator's input parameters, you can also control the ATR values for stop-loss and take-profit calculation.
- Adding a 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 (one-way) 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. You can also use quick risk setting buttons if you need to switch risk per trade often.
- Moving on to the Risk tab 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.
- 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.
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. 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 points will be shown below the stop-loss and take-profit lines.
- ShowAdditionalSLLabel (default = false) — if true, percentage and money risk will be displayed above the stop-loss line.
- ShowAdditionalTPLabel (default = false) — if true, percentage and money targets and a risk-to-reward ratios will be displayed above the take-profit lines. If multiple take-profits are used, the relevant trade size will also be displayed there.
- 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, the account size display and button will be hidden.
- ShowPointValue (default = false) — if true, the point value will be displayed in the bottom of the Main tab.
- ShowMaxPSButton (default = false) — if true, the maximum position size button will be displayed near the position size field.
- StartPanelMinimized (default = false) — if true, the panel will be created in a minimized state.
- 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.
- Stop Price Line Color (default = clrPurple) — color of the stop price line for stop limit orders (MT5 only).
- 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.
- Stop Price Line Style (default = STYLE_DOT) — stop price line style for stop limit orders (MT5 only).
- 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.
- Stop Price Line Width (default = 1) — stop price line width for stop limit orders (MT5 only).
All default parameters can be changed via the panel. They are added here for the sake of convenience — you can save them to a settings file or to create chart templates.
- TradeDirection (default = Long) — default trade direction. Can be Long or Short.
- SL (default = 0) — if non-zero, the stop-loss level of a newly attached Position Size Calculator will be set to this value in points. Will also turn on the Stop-loss button on the main tab.
- TP (default = 0) — if non-zero, the take-profit level of a newly attached Position Size Calculator will be set to this value in points.
- EntryType (default = Instant) — default order type. Can be Instant or Pending.
- ShowLines (default = true) — if true, SL, TP, and Entry lines won't be hidden.
- LinesSelected (default = true) — if true, SL, TP, and Entry lines will be selected for moving. Be careful not to delete them occasionally!
- ATRPeriod (default = 14) — default period for ATR indicator.
- ATRMultiplierSL (default = 0) — default multiplier for ATR value when calculating ATR-based stop-loss.
- ATRMultiplierTP (default = 0) — default multiplier for ATR value when calculating ATR-based take-profit.
- ATRTimeframe (default = PERIOD_CURRENT) — if set to some specific timeframe, a newly attached Position Size Calculator will use this timeframe for ATR calculation.
- Commission (default = 0) — default commission size.
- AccountButton (default = Balance) — default state of the Account button. Can be Balance, Equity, or Balance_minus_Risk (account balance minus the current portfolio risk).
- Risk (default = 1) — default value for percentage risk.
- MoneyRisk (default = 0) — if greater than zero, will be used as the default value for money risk and the percentage risk will be calculated based on the money risk.
- CountPendingOrders (default = false) — default value for the Count pending orders checkbox on the Risk tab.
- IgnoreOrdersWithoutStopLoss (default = false) — default value for the Ignore orders without stop-loss/take-profit checkbox on the Risk tab.
- CustomLeverage (default = 0) — default value for the Custom leverage field on the Margin tab.
- MagicNumber (default = 0) — default Magic number for the Script tab.
- Commentary (default = "") — default order commentary for PSC-Trader script.
- AutoSuffix (default = false) — if true, a suffix will be appended to the order commentary by the script automatically.
- DisableTradingWhenLinesAreHidden (default = false) — default value for the Disable trading when lines are hidden checkbox on the Script tab.
- MaxSlippage (default = 0) — default value for the maximum slippage on the Script tab.
- MaxSpread (default = 0) — default value for the maximum spread on the Script tab.
- MaxEntrySLDistance (default = 0) — default maximum entry/SL distance for Script tab.
- MinEntrySLDistance (default = 0) — default minimum entry/SL distance for Script tab.
- SubtractOPV (default = false) — default value for the Subtract open positions volume checkbox on the Script tab.
- SubtractPOV (default = false) — default value for the Subtract pending orders volume checkbox on the Script tab.
- DoNotApplyStopLoss (default = false) — default value for the Do not apply stop-loss checkbox on the Script tab.
- DoNotApplyTakeProfit (default = false) — default value for the Do not apply take-profit checkbox on the Script tab.
- AskForConfirmation (default = false) — default value for the Ask for confirmation checkbox on the Script tab.
- PanelPositionX (default = 0) — default horizontal distance from the selected panel position corner.
- PanelPositionY (default = 15) — default vertical distance from the selected panel position corner.
- PanelPositionCorner (default = CORNER_LEFT_UPPER) — default panel position corner.
- TPLockedOnSL (default = false) — default state of take-profit "lock" on stop-loss. If true, take-profit tracks the stop-loss distance automatically.
- TP_Multiplier (default = 1) — multiplier value for the take-profit button.
- UseCommissionToSetTPDistance (default = false) — if true, the take-profit button will take into account the commission field when calculating the appropriate TP level.
- 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.
- CustomBalance (default = 0) — you can set custom balance size for the calculator. For example, if you are calculating position size for another account. This parameter will override the AdditionalFunds parameter.
- SLDistanceInPoints (default = false) — if true, stop-loss will be set in points and the SL line will be following the entry line.
- TPDistanceInPoints (default = false) — if true, take-profit will be set in points and the TP line will be following the entry line.
- ShowATROptions (default = false) — if true, the panel will display options for ATR indicator to be used for SL/TP calculation.
- ATRCandle (default = Current candle) — which candle to use to get the ATR value from — current or previous.
- ScriptTakeProfitsNumber (default = 1) — if greater than 1, multiple take-profit levels will be available on the Script tab to let the PSC-Trader script to split the position in several trades with different take-profits.
- CalculateUnadjustedPositionSize (default = false) — if true, position size calculation result will not be adjusted using broker's minimum/maximum volume and volume step parameters.
- RoundDown (default = true) — if true, position size and potential reward are rounded down. If false, normal math rounding rule is used. Switching to false may lead you to risking more than you planned.
- QuickRisk1 (default = 0) — percentage risk value to be assigned to the first quick button. Alongside with the second quick risk button, it enables you to quickly set a specific risk level.
- QuickRisk2 (default = 0) — percentage risk value to be assigned to the second quick button. Alongside with the first quick risk button, it enables you to quickly set a specific risk level.
- ObjectPrefix (default = "PSC_") — prefix for chart objects' names. It lets Position Size Calculator avoid conflicts with other chart tools.
Input parameters explanation video
This explanation video below demonstrates how changing the parameters described above change the Position Size Calculator's behavior:
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. The order type is set to Stop Limit here, so the purple stop price line is also visible on the chart.
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 entire chart.
Download (ver. 2.42, 2022-02-28)
Position Size Calculator is now an expert advisor.
Please proceed to the new description page:
This old Position Size Calculator (ver. 2.xx) is no longer developed.
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.
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 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.
Trading script execution example with confirmation to open a position:[[version_psc_script]]
- Download PSC-Trader (.mq4) for MetaTrader 4
- Download PSC-Trader (.zip) for MetaTrader 4
- Download PSC-Trader (.mq5) for MetaTrader 5
- Download PSC-Trader (.zip) for MetaTrader 5
How to set a keyboard shortcut for PSC-Trader script
After installing the script, you can add add a hotkey for a quick access.
Adding a hotkey (keyboard shortcut) to the script will make placing trades nearly instantaneous. Here is a short tutorial on how to add a hotkey to the script in MetaTrader:
1. Right-click on the script in the Navigator panel of your MetaTrader:
2. Then set a control key for your shortcut. It can be either Ctrl or Alt:
3. Now you can set the main trigger key:
4. Done! You can now press the selected key combination to invoke the script at any time to open your trade immediately.
PS: Of course, you should enable Autotrading in your platform for the script to work, whether you start it with a mouse click or a key press:
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.
Frequently asked questions
I get compilation errors when compiling Position Size Calculator. How do I solve this?
First, make sure that you are compiling the correct file — PositionSizeCalculator.mq4 in MetaTrader 4 or PositionSizeCalculator.mq5 in MetaTrader 5. Second, make sure that the other two files — Defines.mqh and PositionSizeCalculator.mqh — are placed in the same folder as the one you compile. If the problem isn't solved, please post in the official discussion thread, stating the version of Position Size Calculator, version of MetaTrader, and providing a copy or a screenshot of the compilation errors.
I installed the indicator but when I add it to a chart, nothing happens. Why?
Most likely, you need to compile it. To do this, left-click it in the list of indicators in MetaTrader's Navigator window and press Enter. MetaEditor will open the calculator's source code. Now press F7. See the answer to the question above if there are compilation errors.
The indicator/script doesn't work right. What do I do?
To help you with the issue, I would need to know what version of the indicator/script you are using, what version of MetaTrader (including Build number) you are using, and also what broker, account type, and account currency you are trying it on. Additionally, please provide the output in the Experts tab of your Terminal/Toolbox subwindow:
2.42 — 2022-02-28
- Added a display of the current trade direction (long/short) as an arrow in the top-left corner of the panel (MT5) or as a word in the panel's caption (MT4).
- Added the TAB key as a keyboard shortcut to switch the trade's direction from long to short and vice versa.
- Fixed a bug that resulted in a misplaced line label when switching from long-quote symbol to a short-quote one in MT4.
- Fixed a typo in the ScriptTakeProfitsNumber input parameter. It may reset after you update to a new version — don't forget to change it back to your preferred value if this happens.
- Fixed SL and TP lines snapping back while dragging them to a new level.
- Fixed portfolio risk calculation by adding existing swap values to it (MT4 version only).
- Script: Fixed detection of pending/instant order type by analyzing the panel rather than relying on price levels alone.
- Script: Added extra information in the order confirmation window.
- Script: Fixed order opening when stop-loss is too close to the current price. Previously, it could result in a trade without a stop-loss; no trade will be opened now.
- Script: Added an option to append automatically generated suffix to order commentary. This can be helpful to uniquely mark sets of orders when trading with multiple take-profit levels. A default value input parameter (AutoSuffix) has been added.
- Script: Improved execution performance due to fewer calls to chart object values.
- Changed "pips" to "points" everywhere for clarity.
2.41 — 2021-10-22
- Added an input parameter (StartPanelMinimized) to make the panel start in the minimized state.
- Added ATRCandle input parameter to control which candle is used for ATR calculation — the current one (default) or the previous one.
- Fixed a bug that caused poor compatibility with other panel-based indicators and EAs.
- Fixed a bug in portfolio risk calculation that caused it to omit the commission accumulated on current trades. Applies only to MT4 as commission is deducted from balance in MT5.
- Fixed a bug that caused very large values in extra TP edit fields when switching TPDistanceInPoints to true.
- Fixed a minor glitch with extra TP lines jumping in some cases.
- Fixed a bug that caused the PSC-Trader script to open a trade without stop-loss and take-profit if an invalid take-profit was passed in Market execution and to not open a trade at all if invalid TP was passed in Instant execution.
- Fixed a bug in the PSC-Trader script that caused opening trades with random volume when the resulting calculated volume was below the broker's minimum lot size in a multi-TP mode.
- Renamed input parameters UseFixedSLDistance and UseFixedTPDistance to SLDistanceInPoints and TPDistanceInPoints for clarity.
2.40 — 2021-09-13
- Added a Max PS button (turned on via the new ShowMaxPSButton input parameter) to quickly set the position size to the maximum value allowed by the account's margin.
- Added advanced reference pair search for MT4 to find correction coefficient using two currency pairs for CFDs. For example, the PSC will now use both USD/SEK and USD/CHF rate to convert profit/loss for CAD/CHF trades if the account currency is SEK.
- Fixed stop-loss value switching to -1 pip when switching the chart's symbol to a symbol without loaded history in MT5.
- Fixed margin calculation for CFDs in the MT5 version, which sometimes could do it incorrectly.
- Fixed a bug with position size calculation for futures instruments in MT5.
- Fixed decimal places calculation accuracy.
- Script: Added sounds on successful and failed order execution.
2.39 — 2021-07-14
- Hotfix for proper handling of instruments with periods (".") in their name.
2.38 — 2021-07-07
- Added possibility to edit the account balance field directly via the panel.
- Added the CustomBalance input parameter to set account balance via input parameters.
- Added an input parameter (DefaultTPLockedOnSL) to control the default state of the Take-profit button on the Main tab.
- Improved labeling of the DefaultCommission input parameter.
- Fixed multiple TP values on the Main tab when UseFixedTPDistance is set to true.
- Fixed an issue with TP value going too high or too low when switching the chart's symbol. It will now get reset to the DefaultTP input parameter if given, or zero otherwise.
- Fixed a bug when dragging the stop-loss line or changing the default SL stopped working when UseFixedStopLoss was set to true.
- Fixed a glitch that caused the Stop price line to display on top of the panel when switching from Pending to Stop Limit order type in MT5 version.
- Fixed deleted lines restoration to restore them hidden when necessary.
- Fixed a bug when the panel's position and minimization status got reset after another indicator is added to the chart's main window and the user switches the timeframe or restarts the platform.
2.37 — 2021-04-13
- Fixed a bug that caused the stop-loss to reset to its default value (if given via the DefaultSL input parameter) on timeframe switching.
- Fixed a bug in the MT5 version that prevented swap values to appear on the Swaps tab.
2.36 — 2021-04-06
- Changed how position size shares are distributed when total position size cannot be divided evenly due to minimum position size or minimum lot step.
- Fixed deletion of extra TP lines when switching to a lower value in the ScriptTakeProfitsNumber input parameter.
2.35 — 2021-03-20
- MT5 only: fixed a bug that moved window focus to the chart with minimized panel on every tick.
2.34 — 2021-03-20
- Added multiple TP lines and TP input fields on the Main tab when the ScriptTakeProfitsNumber input parameter is greater than 1.
- Added additional SL label option to show risk above the stop-loss line. This can be helpful when the panel is minimized.
- Added risk-to-reward ratio display to the additional TP label.
- Added lot display for additional TP labels when multiple TP levels are in use.
- Added Stop-loss button when default SL value is set via input parameters.
- Added current symbol filter checkbox to the Risk tab.
- Added automatic restoration of line objects if they get accidentally deleted.
- Added helpful tooltips to relevant panel elements and lines.
- Added a warning for cases when calculated position size is greater than the maximum position size possible with current free margin — position size becomes red.
- MT5 wide format for 8 decimal places now kicks in only if either account balance or the chart symbol use so many decimal places.
- PSC-Trader script will now correctly detect the status of the Disable trading when lines are hidden checkbox.
- Fixed a bug in MT5 version that made the stop price line appear after input parameters change even if order type wasn't set to stop limit.
- Fixed a bug in MT5 version that prevented the LinesSelected input parameter from working properly.
- Fixed a bug in MT4 that resulted in invalid stop-loss values when SL in pips was used and the chart's symbol switch occurred.
- Fixed a bug in MT5 that resulted in some panel fields to appear when a chart timeframe was switched on a minimized panel in the locked take-profit mode.
- Fixed potential 'division by zero' errors when chart data isn't ready.
2.33 — 2020-12-13
- Fixed a potential 'division by zero' error when ShowAdditionalTPLabel is set to true.
- Fixed risk and reward calculation for cases when the currency pair's base currency is the same as the account currency.
- Fixed display of redundant trailing zeros in swaps.
2.32 — 2020-11-18
- Added support for stop limit pending orders in MetaTrader 5.
- Added optional confirmation for trades executed by PSC-Trader script.
- Added a 'fixed' state to the Take-profit button, which makes the TP line to automatically follow the changing distance between Entry and Stop-loss.
- Added the Current timeframe to the ATR Timeframe-switching button.
- Added optional additional label for the take-profit line — reward size in percentage and currency units.
- Added buttons to quickly set predetermined risk levels.
- Added buttons to quickly fill multiple take-profit levels on the Script tab. One button fills the TPs in such a way that the main TP becomes the farthest one and the rest are equidistant between the entry and the main TP. The second button fills the TPs in such a way that the main TP becomes the closest one and the rest are placed equidistantly farther out.
- Added input parameter (RoundDown) to control whether position size and reward are rounded down or normally.
- Added a prefix for chart objects to improve compatibility with other indicators, expert advisors, and scripts that add graphical objects to charts.
- Fixed an 'array out of range' error when switching from multiple TPs to a single TP.
- Fixed a bug that prevented checkboxes from updating on the panel when their values were changed via input parameters.
- Fixed a bug with Long/Short switching when lines are hidden.
- Fixed a bug that caused PSC-Trader script to apply take-profit even when the 'Do not apply take-profit' checkbox was ticked.
- Fixed a bug with symbol leverage calculation when non-zero custom leverage is given.
- Fixed a bug with minimized panel not retaining its coordinates when switching charts/timeframes.
- Fixed an MT4-only bug with reward calculation for CFDs with profit currency same as the account currency.
- Fixed an MT4-only bug with position size calculation for futures instruments with profit currency different from the account currency.
- Fixed compatibility of Position Size Calculator with other panel indicators and EAs (Account Protector for example).
- Fixed calculation for FORTS Futures trading instruments (MT5 only).
- Fixed an MT5-only issue of maximum position size by margin potentially using wrong number of decimal places.
- Fixed switching over from another chart so that the line labels are moved to the correct place faster.
- Fixed potential precision issues by replacing
- Fixed another potential issue when Russian ruble is called RUR (instead of RUB) in broker's system.
- Removed old code parts from PSC-Trader script responsible for compatibility with the legacy version of Position Size Calculator (pre-2.00).
2.31 — 2020-06-23
- Hotfix for a bug when panel got moved to another position after adding it to a specific corner and then interacting with the chart without first moving the panel.
2.30 — 2020-06-22
- Fixed bugs with finding reference currency pairs for Futures, CFD, and Forex No Leverage instruments.
- Fixed bugs with panel placement when it couldn't remain in a position that isn't visible when the chart is windowed.
- Fixed possible rounding errors causing inaccurate position size calculation.
- When entering non-zero TP value in the first TP field on the Script tab, a TP line will appear if it was absent before.
- Multiple TP levels for script are now auto-adjusted for tick size granularity.
- Fixed a bug in MT4 version that prevented TP line from appearing when attaching the indicator with ShowATROptions and non-zero ATRMultiplierTP.
- Added input parameter (CalculateUnadjustedPositionSize) to let PSC calculate unadjusted position size. This can be useful if you are calculating in one platform and then executing the trade in another platform.
- Fixed a bug in MT5 version that prevented Entry line from being selected initially when attaching the indicator with EntryType is set to Pending.
- The PSC-Trader script will now issue an alert if AutoTrading is disabled.
2.291 — 2020-05-29
- Hotfix for a persistent bug in MT5 version that caused incorrect pip value calculations.
2.29 — 2020-05-29
- Added support for splitting the position into multiple trades with different take-profit levels when executing PSC-Trader script.
- All panel parameters (including its location on a chart) can now be configured via a group of "default" input parameters.
- Entry, stop-loss, and take-profit line objects are now selected by default and are ready to be moved around. Be careful not to delete them accidentally.
- Added Long/Short button to the Main tab for quick switch between Long and Short position calculation.
- Improved performance by deferring the recalculation on timer to only be performed when at least 1 second has passed since the previous calculation.
- Improved potential risk/reward calculation formulas, especially in MT5 version.
- Take-profit button will now attempt to use profit pip value to calculate the appropriate distance from Entry.
- Fixed a bug in MT5 version when pip value wasn't calculated correctly in accounts without leverage.
2.28 — 2020-05-13
- Changed how pip value calculation is done for position size, portfolio risk/reward, margin, and swaps. This should yield more accurate results for some trading instruments with some brokers while also eliminating the need for UseCFDMultiplier and DisableTickValueAdjustment input parameters. Margin calculation can still be off with some MT4 brokers.
- Optimized indicator's performance by making portfolio risk/reward, margin, and swap data recalculate only when the respective tab is selected.
- Optimized the process of finding reference pairs for currency conversion.
- Fixed the problem of lines becoming unselected after hiding and then showing them again.
- Added Script tab options to not apply stop-loss or take-profit to a trade executed by PSC-Trader.
- Fixed a bug in the MT5 version of the indicator when hidden lines could reappear after changing one of the indicator's input parameters.
- Fixed various typos in the source code.
2.27 — 2019-11-07
- Fixed errors in CFD margin calculation for non-USD accounts that could occur in some cases in MetaTrader 5.
- Fixed division by zero error when calculating portfolio risk for trades with base currency same as the account currency.
- Fixed potential portfolio reward calculation when no take-profit is set in the panel.
- Fixed default entry and stop-loss positioning when PSC is loaded on a new chart with a default.tpl template.
- Changed the way file names for PSC settings are generated — all currently attached panels will be reset when upgrading to version 2.27.
- Added DisableTickValueAdjustment input parameter to disable tick value adjustment calculation. It might turn helpful for cases when broker incorrectly reports the symbol's profit currency.
- Added input groups in MetaTrader 5.
2.26 — 2019-10-09
- Fixed a bug that sometimes prevented finding correct reference currency pair for cases when account currency was different from the symbol's profit currency.
2.25 — 2019-10-05
- Fixed compilation errors in MT5 Build 2170 (and newer versions).
2.24 — 2019-08-21
- Implemented a more accurate way to calculate risk and reward for portfolios that include currency pairs with the account currency as their base currency.
- MT5 only: Fixed interest type swaps calculation for some CFDs when UseCFDMultiplier input parameter is set to true.
2.23 — 2019-08-03
- Fixed a glitch with a redundant text label appearing on some tabs.
- Added a more accurate way to calculate position size, risk, and reward for currency pairs with base currency same as the account currency.
2.22 — 2019-07-08
- Fixed a bug in MT4 version that could cause incorrect calculations for RUB accounts.
- Fixed a potential division by zero error when calculating symbol leverage.
- The take-profit button can now take into account commission if UseCommissionToSetTPDistance is set to true.
- Both TP and SL lines can now be freely moved even when fixed SL/TP distance is used.
- ATR timeframe can now be set to different from what the current chart is set to.
2.21 — 2019-03-29
- 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.
2.20 — 2019-03-21
- Fixed a bug that could cause the DefaultSL and DefaultTP input parameters to be applied slightly incorrectly.
2.19 — 2019-03-14
- 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 aren't yet available.
- Fixed panel hiding outside the chart's borders when resizing the chart window.
2.18 — 2019-02-27
- Added ATR options to the calculator's panel (turn on by setting ShowATROptions to true) 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 Risk tab.
- Added display of the number of lots to the Risk tab.
- 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 Script tab rounding incorrectly after switching timeframes or restarting the platform.
2.17 — 2018-11-14
- Fixed a bug with incorrect take-profit value showing up if UseFixedTPDistance was set to true and DefaultTP was zero.
- Fixed a bug that could cause slightly incorrect SL/TP values to show up due to a rounding error.
2.16 — 2018-11-09
- Fixed a bug with poor number formatting, which caused wrong calculation results showing up.
2.15 — 2018-11-06
- Added an input parameter for adjusting CFD position size calculation (UseCFDMultiplier) when tick value is incorrectly set on the broker's 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 with cryptocurrencies in 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 symbol's 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.
- Fixed nominal swap value formatting.
- Added two checkboxes to instruct the PSC-Trader script to open a trade taking into account currently open positions or pending orders.
- Changed how script uses Maximum position size 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.
2.14 — 2018-05-18
- 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.
2.13 — 2018-02-19
- Fixed another bug with wrong position size calculation for non-Forex trading instruments in both MT4 and MT5 versions of the indicator.
2.12 — 2017-12-22
- Fixed a bug that resulted in wrong position size and pip value calculated for CFD trading instruments in MetaTrader 5 version of the 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.