Position Sizer (MetaTrader expert advisor) calculates how many lots to trade based on:

  • Entry and stop-loss levels
  • Risk tolerance
  • Account size (balance, equity, or even your savings account)
  • Account currency
  • Currency exchange rates

Its main features include:

  • Works with any trading instruments — currency pairs, CFDs, equities, indices, commodities, futures, cryptocurrencies.
  • Calculation inputs and results are displayed in 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 take-profit as distance in points.
  • Alternatively, you can set them as multiples of ATR (Average True Range).
  • If a 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.
  • The expert advisor 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 EA 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.
  • Allows opening positions based on the calculations.
  • The calculated position can be divided into several trades with different take-profit levels.
  • Supports stop limit orders in MetaTrader 5.

This EA is an evolution of our free online tool and the MetaTrader indicator called Position Size Calculator. Position Sizer is available for both MT4 and MT5, but the MT5 version provides slightly better functionality because the platform itself is more advanced.

Interface

Main tab

The main tab of the panel provides the primary control over the EA's functions and serves to output the most important calculation results: the position size, risk, reward, and risk-to-reward ratio. The following controls and outputs are available:

Position Sizer - EA Interface - Main Tab

  1. Direction arrow shows whether the current trade is long (▲) or short (▼). In MT4 version, it is written in words.
  2. Version number.
  3. Spread value in ticks.
  4. Minimization button to fold down the panel.
  5. Close button to remove the expert advisor from the chart.
  6. Main tab switch — it is currently turned on.
  7. Risk tab switch — click on it to see the current and potential risk profile. The Risk tab interface is explained below.
  8. Margin tab switch — click on it to see everything related to required and free margin. The Margin tab interface is explained below.
  9. Swaps tab switch — click on it to see the details on the swaps for the current trading instrument. The Swaps tab interface is explained below.
  10. Trading tab switch — click on it to see the controls for trading operations. The Trading tab interface is explained below.
  11. 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.
  12. Entry input — grayed out when Instant order is used, can be used enter entry level when Pending order is set.
  13. 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.
  14. Stop-loss input.
  15. 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.
  16. Take-profit multiplier, if set via input parameters, applies to the current SL value when Take-profit button is pressed.
  17. Take-profit input.
  18. Multiple take-profit input fields. Visible if TakeProfitsNumber input parameter is set to a value greater than 1.
  19. Stop price input (for stop limit orders, MT5 only).
  20. ATR Period — setting to use with the ATR-based SL/TP. ATR options are visible only if ShowATROptions input parameter is set to true.
  21. ATR — current value of ATR with a given period. ATR options are visible only if ShowATROptions input parameter is set to true.
  22. 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.
  23. 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.
  24. Spread Adjustment for SL — if ticked, the spread value will be subtracted from or added to the stop-loss to make the distance count from the price the trade can be closed at. ATR options are visible only if ShowATROptions input parameter is set to true.
  25. Spread Adjustment for TP — if ticked, the spread value will be subtracted from or added to the take-profit to make the distance count from the price the trade can be closed at. ATR options are visible only if ShowATROptions input parameter is set to true.
  26. 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.
  27. Order type button to switch between Instant, Pending, and Stop Limit.
  28. Hide/show lines button to quickly switch the display of the Entry, Take-profit, and Stop-loss lines on the chart.
  29. 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.
  30. 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.
  31. Account size in account currency units.
  32. 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.
  33. Quick risk button #1 — first button to quickly set percentage risk value.
  34. Quick risk button #2 — second button to quickly set percentage risk value.
  35. 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.
  36. 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.
  37. Risk (result) — percentage risk calculated based on the actual position size allowed in your broker's platform.
  38. Risk money (result) — money risk calculated based on the actual position size allowed in your broker's platform.
  39. Reward in account currency is based on the position size calculated without taking into account platform's restrictions.
  40. Reward (result) — reward in account currency is based on the actual position size allowed in your broker's platform.
  41. Reward/risk (input) — input reward divided by input risk.
  42. Reward/risk ratio (result) — reward result divided by risk result.
  43. Position size — actual position size calculation output. You can modify it yourself if you want to calculate your risk based on position size.
  44. Point value per calculated position size.
  45. 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.

Risk tab

The risk tab can help you assess current and potential risk and reward profile. Using a simple algorithm, the EA 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 expert advisor 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 three checkboxes and see the calculation results in ten output fields:

Position Sizer - EA Interface - Risk Tab

  1. Count pending orders — if checked, the EA will also attempt to calculate the risk of pending orders in addition to currently open positions.
  2. 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.
  3. 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.
  4. Current portfolio risk (currency) — shows the risk in currency units without the position that is currently being calculated by this expert advisor.
  5. Potential portfolio risk (currency) — shows the risk in currency units as if you have already opened a position that is currently calculated by this expert advisor.
  6. Current portfolio risk (%) — same as Current portfolio risk (currency) but in percentage to the account size.
  7. Potential portfolio risk (%) — same as Potential portfolio risk (currency) but in percentage to the account size.
  8. Current portfolio reward (currency) — shows the reward in currency units without the position that is currently being calculated by this expert advisor.
  9. Potential portfolio reward (currency) — shows the reward in currency units as if you have already opened a position that is currently calculated by this expert advisor.
  10. Current portfolio reward (%) — same as Current portfolio reward (currency) but in percentage to the account size.
  11. Potential portfolio reward (%) — same as Potential portfolio reward (currency) but in percentage to the account size.
  12. Current portfolio lots — the total size of the currently open positions in lots.
  13. Potential portfolio lots — the total size in lots of the open positions plus the one, which is currently being calculated by this expert advisor.

Margin tab

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 Sizer - EA Interface - Margin Tab

  1. 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.
  2. Future used margin is calculated based on the current used margin and position margin.
  3. Future free margin shows how much free margin you will have left after opening the calculated position.
  4. Custom leverage input lets you set your own leverage for all the margin calculations done by this expert advisor.
  5. Default leverage shows the account's actual leverage for your reference.
  6. 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.
  7. Maximum position size by margin displays the biggest trade you can take with your currently available free margin and leverage.

Swaps tab

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:

Position Sizer - EA Interface - Swaps Tab

  1. Type shows the type of swaps used by the broker for the current trading instrument. It can be one of several kinds: points, base currency, interest, account currency, margin currency, reopening.
  2. Triple swap shows the day of week when triple swaps are charged/paid (to account for Saturday and Sunday).
  3. Nominal swaps (Long) — nominal swaps paid or charged by a broker for long positions.
  4. Nominal swaps (Short) — nominal swaps paid or charged by a broker for short positions.
  5. Daily swap per lot (Long) — daily swap paid or charged by a broker for long positions in account currency per lot.
  6. Daily swap per lot (Short) — daily swap paid or charged by a broker for short positions in account currency per lot.
  7. 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).
  8. 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).
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. Position size duplicates the display of the position size calculated by the EA on the Main tab.

Trading tab

The trading tab lets you trade based on the results of the calculation and also to control the trading process.

Position Sizer - EA Interface - Trading Tab

  1. Trade — a button to open a trade (or multiple trades) based on the position size calculation results.
  2. Trailing stop — a number of points to apply as a trailing stop to trades with the given Magic number.
  3. Breakeven — a number of points in profit when a breakeven will be applied to a trade with the given Magic number.
  4. Magic number — Magic number that will be assigned to the orders and positions opened using the expert advisor.
  5. Order commentary — commentary for orders and positions opened using the expert advisor.
  6. Auto-suffix — if checked, the EA 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.
  7. Max # of trades — if opening a new trade will make the number of open trades exceed the maximum value, the EA won't open the trade.
  8. All symbols — if checked, the EA will count trades for all symbols (not only for the current one) when considering the maximum number of trades allowed.
  9. Disable trading when lines are hidden — a simple checkbox to prevent the EA from opening a position when you have chosen to hide the lines via the Main tab.
  10. Fill take-profits inwards — a button to fill multiple take-profit fields equidistantly from Entry level to main Take-Profit level.
  11. Fill take-profits outwards — a button to fill multiple take-profit fields equidistantly with the main Take-Profit level as the closest one.
  12. Multiple take-profit levels — a number (set via TakeProfitsNumber 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.
  13. Shares to divide the position size — each take-profit level is assigned its percentage of the total position size calculated on the Main tab.
  14. Max slippage — the maximum tolerable slippage value (in points) that will be used in trading functions of the expert advisor.
  15. Max spread — the EA will not trade if current spread is wider than the value given here.
  16. Max Entry/SL distance — the EA will not trade if distance between the Entry level and Stop-Loss level becomes greater than this value.
  17. Min Entry/SL distance — the EA will not trade if distance between the Entry level and Stop-Loss level becomes less than this value.
  18. Max position size — if the calculated position size exceeds this value (in lots), the EA will only open a trade of the size given in this field.
  19. Subtract open positions volume — if checked, the EA 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.
  20. Subtract pending orders volume — if checked, the EA 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.
  21. Do not apply stop-loss — if checked, the EA 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.
  22. Do not apply take-profit — if checked, the EA 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.
  23. Ask for confirmation — if checked, the EA will ask for confirmation before trading.

Usage

Using this expert advisor is very simple if your main aim is to calculate the position size based on your stop-loss and the current market parameters and then to execute the trade based on that calculated position size.

  1. Attaching Position Sizer 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 on.
  2. 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.
  3. If not, you can freely change the stop-loss — either by dragging the stop-loss line on the chart or by entering the value into the stop-loss input in the panel. You can also set your stop-loss as a distance in points by turning on the respective input parameter.
  4. You can set your take-profit the same way. Additionally, you can quickly set the TP equal to the current SL value (or with some preset multiplier) by clicking the Take-profit button. Similar to the stop-loss, the take-profit can be set as distance in points if the respective input parameter is turned on. Multiple take-profit levels are supported when TakeProfitsNumber input parameter is set to a value greater than 1.
  5. If you turn ATR settings on via the EA's input parameters, you can also control the ATR values for stop-loss and take-profit calculation.
  6. Adding a take-profit will turn on the display of Reward and Reward/risk ratio for your information.
  7. 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 changed manually. When Pending or Stop Limit (in MT5) order is used, the Entry level can be set either via panel's input or by dragging the chart line.
  8. The EA will warn if the Entry level is too close to the current price in the Pending order mode and if the Stop-loss or Take-profit level is too close to the Entry level.
  9. 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.
  10. Switching the account size from balance to equity or to balance minus portfolio risk can be useful in some cases and is done by one or two clicks on the respective button.
  11. Adjusting the risk tolerance can be done in two ways: by setting the percentage risk value or by setting the money risk value. Both are done via the input fields in the panel. You can also use the quick risk setting buttons if you need to switch risk per trade often.
  12. 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.
  13. The Margin tab is not necessary either if your goal is to calculate the optimal position size based on your risk and stop-loss. This tab will inform you on the 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.
  14. The 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.
  15. The Trading tab will help you to execute the actual trade and control how it is done.

Trading

You can use the position size output of this EA to open trades manually in the same or some other platform. Alternatively, you can use its trading capability to open trades based on the calculated position size and with the given entry, SL, and TP levels. You can either use the Trade button on the Trading tab or the hotkey (set via input parameters).

Trade execution example with confirmation to open a position:

Position Sizer EA - Order confirmation window

Autotrading should be enabled for trading to work. Here is how to enable it in MetaTrader 4:

MetaTrader 4 - Allowing Autotrading for Expert Advisors

And here is how to enable Algo Trading in MetaTrader 5:

MetaTrader 5 - Allowing Algo Trading for Expert Advisors

How to set a keyboard shortcut for trade execution

You can set a keyboard shortcut via the TradeHotKey input parameter. You can either use a single key (e.g., "T") or with a combination of Shift and Ctrl keys (e.g., "Ctrl+Shift+T").

Warning! There is a known issue with using the keyboard shortcut in MT4. If either Shift or Ctrl is used and the Ask for confirmation option is turned on, the shortcut stops working after the first time the confirmation popup appears. That is why the default value for the shortcut in MT4 is just "T". This problem is absent in MT5.

Demonstration video

This video demonstrates how you can use the Position Sizer expert advisor, showcasing its most important functions:

Input parameters

The EA has a set of input parameters besides the panel-based controls. The Position Sizer's display options and a number of default options are set via standard MetaTrader inputs.

Compactness

  • 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.
  • ShowATROptions (default = false) — if true, the panel will display options for ATR indicator to be used for SL/TP calculation.

Fonts

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

Lines

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

Defaults

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) — the default trade direction. Can be Long or Short.
  • SL (default = 0) — if non-zero, the stop-loss level of a newly attached Position Sizer 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 Sizer will be set to this value in points.
  • EntryType (default = Instant) — the 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) — the default period for ATR indicator.
  • ATRMultiplierSL (default = 0) — the default multiplier for ATR value when calculating ATR-based stop-loss.
  • ATRMultiplierTP (default = 0) — the 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 Sizer will use this timeframe for ATR calculation.
  • SpreadAdjustmentSL (default = false) — the default state of the spread adjustment checkbox for the ATR-based stop-loss field. If true, the ATR-based stop-loss level will be adjusted by the spread value.
  • SpreadAdjustmentTP (default = false) — the default state of the spread adjustment checkbox for the ATR-based take-profit field. If true, the ATR-based take-profit level will be adjusted by the spread value.
  • Commission (default = 0) — the default commission size.
  • AccountButton (default = Balance) — the default state of the Account button. Can be Balance, Equity, or Balance - Risk (account balance minus the current portfolio risk).
  • Risk (default = 1) — the 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) — the default value for the Count pending orders checkbox on the Risk tab.
  • IgnoreOrdersWithoutStopLoss (default = false) — the default value for the Ignore orders without stop-loss/take-profit checkbox on the Risk tab.
  • CustomLeverage (default = 0) — the default value for the Custom leverage field on the Margin tab.
  • MagicNumber (default = 2022052714) — the default Magic number for the Trading tab.
  • Commentary (default = "") — the default order commentary for trades.
  • AutoSuffix (default = false) — if true, a suffix will be automatically appended to the order commentary.
  • DisableTradingWhenLinesAreHidden (default = false) — the default value for the Disable trading when lines are hidden checkbox on the Trading tab.
  • MaxSlippage (default = 0) — the default value for the maximum slippage on the Trading tab.
  • MaxSpread (default = 0) — the default value for the maximum spread on the Trading tab.
  • MaxEntrySLDistance (default = 0) — the default maximum entry/SL distance for the Trading tab.
  • MinEntrySLDistance (default = 0) — the default minimum entry/SL distance for the Trading tab.
  • SubtractOPV (default = false) — the default value for the Subtract open positions volume checkbox on the Trading tab.
  • SubtractPOV (default = false) — the default value for the Subtract pending orders volume checkbox on the Trading tab.
  • DoNotApplyStopLoss (default = false) — the default value for the Do not apply stop-loss checkbox on the Trading tab.
  • DoNotApplyTakeProfit (default = false) — the default value for the Do not apply take-profit checkbox on the Trading tab.
  • AskForConfirmation (default = true) — the default value for the Ask for confirmation checkbox on the Trading tab.
  • PanelPositionX (default = 0) — the default horizontal distance from the selected panel position corner.
  • PanelPositionY (default = 15) — the default vertical distance from the selected panel position corner.
  • PanelPositionCorner (default = CORNER_LEFT_UPPER) — the default panel position corner.
  • TPLockedOnSL (default = false) — the default state of the take-profit "lock" on the stop-loss. If true, the take-profit tracks the stop-loss distance automatically.
  • TrailingStop (default = 0) — the default trailing stop value in points for the Trading tab.
  • BreakEven (default = 0) — the default breakeven value in points for the Trading tab.
  • MaxNumberOfTrades (default = 0) — the default maximum number of trades to tolerate in the account. The zero value means no limit.
  • AllSymbols (default = true) — the default state of the All symbols checkbox for the maximum number of trades limit. If true, the EA will count trades on all symbols. If false, the EA will only count trades on the current symbol.

Miscellaneous

  • TP_Multiplier (default = 1) — the 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 expert advisor. 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.
  • ATRCandle (default = Current candle) — which candle to use to get the ATR value from — current or previous.
  • TakeProfitsNumber (default = 1) — if greater than 1, multiple take-profit levels will be available on the Trading tab 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) — the 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) — the 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 = "PS_") — the prefix for chart objects' names. It lets Position Sizer avoid conflicts with other chart tools.
  • TradeHotKey (default = "T") — a case-insensitive hotkey shortcut to open a new trade based on the calculations. Supports Shift and Ctrl modifiers.
  • SymbolChangeReset (default = false) — if true, changing the current chart's symbol to another one and then turning back will result in all panel values reset to the input parameters' defaults.

Demonstration video on input parameters

You can see a visual demonstration of how the Position Sizer's input parameters work in this detailed video:

Screenshots

Main tab

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

Position Sizer - Main Tab on White Background

Risk tab

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.

Position Sizer - Risk Tab on Black Background

Margin tab

Even the wildest color scheme works well with Position Sizer. In this case, cyan background is combined with green and red candlesticks. Stop-loss color is set to black.

Position Sizer - Margin Tab on Cyan Background

Swaps tab

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.

Position Sizer - Swaps Tab on White Background

Trading tab

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

Position Sizer - Trading Tab with Panel as Background

Minimized panel

Minimizing the panel in one click makes it completely non-obtrusive and allows trader to easily see the entire chart.

Position Sizer - Minimized Panel

Downloads (ver. 3.02, 2022-08-12)

Position Sizer for MetaTrader 4

Position Sizer for MetaTrader 5

Position Sizer is being developed via a dedicated GitHub repository. You are encouraged to actively participate in the improvement of this EA by submitting your own features via pull-requests and by reviewing existing suggestions, changes, fixes, and so on.

Installation

To install the expert advisor, make sure that you copy the entire folder from the archive to /MQL4/Experts/ or /MQL5/Experts/ (if you are on MetaTrader 5).

The EA folder should contain the following files:

  • Defines.mqh
  • Position Sizer.mq4 or Position Sizer.mq5
  • Position Sizer.mqh
  • Position Sizer Trading.mqh
  • errordescription.mqh (MT5 only)

You need to compile Position Sizer.mq4 (or Position Sizer.mq5), not any of the other files.

Frequently asked questions

I get compilation errors when compiling Position Sizer. How do I solve this?

First, make sure that you are compiling the correct filePosition Sizer.mq4 in MetaTrader 4 or Position Sizer.mq5 in MetaTrader 5. Second, make sure that the other files — Defines.mqh, Position Sizer.mqh, Position Sizer Trading.mqh, and errordescription.mqh (in MT5) — are placed in the same folder as the file you compile. If the problem isn't solved, please post in the official discussion thread, stating the version of Position Sizer, version of MetaTrader, and providing a copy or a screenshot of the compilation errors.

I installed the expert advisor 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 expert advisors in MetaTrader's Navigator window and press Enter. MetaEditor will open the EA's source code. Now press F7. See the answer to the question above if there are compilation errors.

Position Sizer doesn't work correctly. What do I do?

To help you with the issue, I would need to know what version of the EA you are using, what version of MetaTrader (including the 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:

Reporting Problems with Position Sizer - Experts Output

Discussion

Do you have any suggestions or questions regarding this expert advisor? You can always discuss Position Sizer 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 the Position Sizer expert advisor.

Changelog

3.02 — 2022-08-12

  • Fixed a bug that could result in wrong or malfunctioning position size calculation when switching the chart's symbol (MT5 only).
  • Fixed the Commentary and Auto-Suffix fields which weren't working correctly (MT5 only).
  • Fixed a bug that prevented newly set default input parameters to change the respective fields on the panel.
  • Fixed a bug that could result in reward-related Main tab elements to show up when some other tab was selected.
  • Fixed a bug that sometimes prevented the Position Size field change from registering when the panel was calculating the Risk based on the Position Size.
  • Moved the ShowATROptions input parameter to the Compactness inputs group.
  • Removed the redundant Stop Price Label Color input parameter as there is no such label (MT5 only).
  • Made some purely cosmetic changes.

3.01 — 2022-07-28

  • Fixed a critical bug for breakeven functioning with sell orders.
  • Fixed bugs related to the trading hotkey.

© 2005–2022

EarnForex.com

Design — Mart Studio

Forex trading bears intrinsic risks of loss. You must understand that Forex trading, while potentially profitable, can make you lose your money. Never trade with the money that you cannot afford to lose! Trading with leverage can wipe your account even faster.

CFDs are leveraged products and as such loses may be more than the initial invested capital. Trading in CFDs carry a high level of risk thus may not be appropriate for all investors.