How to Set the Lot Size in TradingView Alerts for MT5
Put q= on the order line: long EURUSD q=0.1 opens 0.1 lots. Add
qt=percent to size from your balance: q=1 qt=percent puts about 1% of the
balance up as margin, which isn't the same as risking 1%. To risk a set share per trade, work out the lots
from your stop in Pine Script.
How do you set the lot size in a TradingView alert?
Add q= with the number of lots to the order line, under your webhook password:
YourWebhookPassword
long EURUSD q=0.1 sl=300 tp=600 That opens 0.1 lots of EURUSD, the same size you'd type into MetaTrader's order window. The EA only reads
q=. The order size in your strategy's properties on TradingView doesn't reach MetaTrader, so
the backtest and the live trade can differ unless you keep the two in step.
Always include q=. Without it the size is 0, and MetaTrader rejects the order as an invalid
volume. Each line of an alert is its own order with its own q=, so one alert can open two
halves with different targets, as
our stop loss and take profit guide
shows.
The EA sends a fixed size to your broker as it is, and the broker checks it against the symbol's
specification. To see it in MT5, right-click the symbol in Market Watch and choose Specification. These are
the fields that limit q=:
| Specification field | What it means for q= |
|---|---|
| Contract size | How much one lot holds, such as 100,000 units of currency on many forex symbols |
| Minimal volume | The smallest q= the broker accepts |
| Maximal volume | The largest q= for one order |
| Volume step | q= has to be a multiple of it, such as 0.01 |
| Volume limit | The most you can hold on the symbol in one direction, pending orders included |
MetaQuotes' Market Watch help defines the contract size as the "number of units of the commodity, currency or financial asset in one lot". It differs by symbol and by broker, so 0.1 lots of gold or of an index isn't the same exposure as 0.1 lots of EURUSD. Check it on every symbol before you pick a size.
How does qt=percent size a trade?
Add qt=percent, and q= becomes a percentage of your account balance:
YourWebhookPassword
long EURUSD q=1 qt=percent sl=300 The EA doesn't risk that percentage. It opens the size whose margin is about q percent of
your balance. On forex symbols it works that out as balance × q% × your account's leverage ÷ contract size,
after converting the balance into the symbol's base currency. On CFDs it uses the margin MetaTrader quotes
for the symbol. Then it rounds the size down to the volume step.
| Alert | Lots | Margin | Loss at a 30-pip stop |
|---|---|---|---|
| q=1 at 1:100 | 0.09 | About $99 | $27 |
| q=10 at 1:100 | 0.90 | About $990 | $270 |
| q=1 at 1:30 | 0.02 | About $73 | $6 |
The same alert opens less than a quarter of the size on a 1:30 account as on a 1:100 one. And the loss at
the stop depends on how far away the stop is, which qt=percent never looks at.
A few more details. The EA reads the balance, so open profit and loss don't change the size.
qt=percent only applies to orders that open trades, long or short, pending ones included, and
flat ignores it. If the rounded size falls below the minimal volume, no trade opens, and the MT5
EA logs "Quantity is 0". The same happens when the EA can't find a rate to convert your balance into the
symbol's currency, as the troubleshooting guide
explains. A size above the maximal volume is cut to the maximum.
How do you risk 1% of your account per trade?
Size from the stop. The loss at the stop is the lots × the stop distance × the contract size, in the symbol's quote currency, so turn that around:
lots = balance × risk% ÷ (stop distance × contract size) On a $10,000 USD account, 1% is $100. A 30-pip stop on EURUSD is a distance of 0.0030, and with a contract size of 100,000 that costs $300 per lot, so $100 buys 0.33 lots. With a 60-pip stop the same $100 buys 0.16 lots. It matters most on prop-firm accounts, where one oversized loss can break the daily loss limit, as our prop firm EA rules guide explains.
An alert can't do this sum by itself, but a Pine Script strategy can, and send the result in
q=. This one risks 1% with the stop below the 10-bar low:
//@version=6
strategy("Risk 1% per trade", overlay = true)
balance = input.float(10000, "MT5 balance")
riskPercent = input.float(1.0, "Risk per trade (%)")
contractSize = input.float(100000, "Contract size")
lotStep = input.float(0.01, "Volume step")
rate = input.float(1.0, "Quote currency per account currency")
stopPrice = ta.lowest(low, 10)
if ta.crossover(ta.sma(close, 20), ta.sma(close, 50)) and close > stopPrice
riskCash = balance * riskPercent / 100 * rate
lots = math.floor(riskCash / ((close - stopPrice) * contractSize) / lotStep) * lotStep
msg = "long EURUSD q=" + str.tostring(lots, "#.##") + " slp=" + str.tostring(stopPrice, format.mintick)
strategy.entry("Long", strategy.long, alert_message = msg) Put {{strategy.order.alert_message}} under your password in the alert's message box, as with any strategy alert:
YourWebhookPassword
{{strategy.order.alert_message}} When the stop is too wide for the risk, the script sends a size of 0 and MetaTrader rejects it, which is the safe way to fail. The balance is an input, so update it as the account grows or shrinks.
The sum is in the quote currency. Leave rate at 1 when the symbol is quoted in your account
currency, such as EURUSD or XAUUSD on a USD account. For USDJPY on a USD account, set it to the USDJPY
price, for example 150: a 30-pip stop then costs about $200 per lot, so $100 buys 0.5 lots.
The alert fires when the bar closes, and the trade opens at your broker's price a moment later, so the real
loss at the stop lands close to the target, not exactly on it.
Our stop loss guide explains how
slp= prices behave when your chart's feed differs from your broker's, and
the strategy guide covers strategy alerts step by step.
Can the alert send the strategy's own order size?
TradingView has a placeholder for it. Its
placeholder list says
{{strategy.order.contracts}} "returns the number of contracts of the executed order", so
long EURUSD q={{strategy.order.contracts}} sends the strategy's size.
The catch is the unit. TradingView counts the size in its own contracts, while the EA reads
q= as MetaTrader lots, and a lot holds the contract size from your broker's specification. The
two only match when the contract size is 1: on a Bitcoin CFD with a contract size of 1, a 0.5 BTC order
sends q=0.5 and opens 0.5 lots. If your strategy trades forex in currency units, such as
10,000, the alert sends q=10000, and the EA asks for 10,000 lots. Your broker rejects anything
above the symbol's maximal volume.
So convert before you send. Divide by the contract size in Pine Script, such as
units / 100000 for a contract size of 100,000, and put the result in
alert_message. Or send a fixed q= that you've checked on a demo account.
Why was the order rejected or the wrong size?
- Invalid volume. MT5 return code 10014, "Invalid volume in the request", or MT4 error
131.
q=is missing, below the minimal volume, above the maximal volume, or not a multiple of the volume step, such as 0.015 with a step of 0.01. - Not enough money. MT5 code 10019, "There is not enough money to complete the request",
or MT4 error 134. The margin for the size is more than your free margin.
qt=percentcan cause this too, becauseq=100asks for the whole balance as margin. - Volume limit. MT5 code 10034, "The volume of orders and positions for the symbol has reached the limit". Your trades and pending orders in that direction already add up to the broker's volume limit.
- "Quantity is 0". A
qt=percentsize rounded below the minimal volume, or the EA couldn't convert currencies. Raiseq=or send a fixed size. - A different size than you expected.
qt=percentrounds down to the volume step, stops at the maximal volume and follows your leverage. Check the Experts tab: the EA prints the lots it worked out.
The codes come from MetaQuotes' lists for MT5 and MT4. The troubleshooting guide covers every other reason an alert doesn't trade.
Frequently asked questions
Is q= in lots or in units?
Lots. long EURUSD q=0.1 opens 0.1 lots, the same size you'd type into MetaTrader's order window. How much a lot holds depends on the symbol's contract size.
What happens if I leave out q=?
The size is 0, and MetaTrader rejects the order as an invalid volume. Always send q=, on its own or with qt=percent.
Does qt=percent risk that percentage of my account?
No. It opens the size whose margin is about that share of your balance. What you lose at the stop depends on the stop distance, so size from the stop if you want a set risk per trade.
Why does qt=percent open different sizes on different accounts?
It follows the balance and the account leverage. On a $10,000 account, q=1 qt=percent opens about 0.09 lots of EURUSD at 1:100 and 0.02 lots at 1:30.
Can I send a size like 0.015 lots?
Only if the symbol's volume step allows it. With a step of 0.01, MetaTrader rejects 0.015 as an invalid volume. The EA rounds qt=percent sizes down to the step for you, but sends fixed sizes as they are.
Does qt=percent use my balance or my equity?
The balance. Open profit and loss don't change the size.
Does lot sizing work the same way on MT4?
Yes. Both EAs read q= as lots and work out qt=percent sizes from the balance, the leverage and the margin in the same way.
Sources
- TradingView: how to use a variable value in alert (strategy placeholders)
- Pine Script docs: strategies (order sizes and alert_message)
- MetaTrader 5 help: Market Watch (symbol specification)
- MQL5 docs: trade server return codes
- MQL4 docs: error codes
All checked November 2026. How the EA sizes each order comes from our own MT4 and MT5 EA code.
Related guides
- How to connect TradingView to MT5
- How to connect TradingView to MT4
- PineConnector alternative with MT4 support
- Best TradingView to MT5 bridges, compared
- Free TradingView to MT5 bridge: what you get for $0
- Free and cheapest TradingView to MT4 bridges
- TradingView trade copier for MT4 and MT5: three types compared
- How to automate a TradingView strategy on MT4 and MT5
- TradingView to MT5 not working? How to fix it
- Prop-firm EA rules: FTMO, FundedNext and The5ers
- TradingView webhook to MT5 and MT4: URL, message format and examples
- TradingConnector alternative for MT4 and MT5
- WebhookTrade alternative for MT4 and MT5
- How to convert Pine Script to MQL5, and when not to
- Does TradingView's free plan have webhooks? Plans compared
- Do you need a VPS for TradingView to MT5?
- How to automate a TradingView strategy on FTMO
- FundedNext TradingView automation: EA rules and setup
- E8 Markets TradingView automation: EA rules and MT5 setup
- FXIFY TradingView automation: EA rules and MT5 setup
- How to run multiple strategies on one MT5 account with magic numbers
- TradingView alert stop loss and take profit on MT4 and MT5
- How to close MT4 and MT5 trades from a TradingView alert
- TradeSgnl alternative: pricing, MT4 support and TradeSgnl vs PineConnector
- How to send TradingView alerts to Telegram and MT5
- MetaConnector alternative: pricing, MT4 support and MetaConnector vs PineConnector
- SignalForge alternative: pricing, hosting and SignalForge vs PineConnector
- TradingView.to alternative: TradingView To Anywhere vs TradingView Link
- TradersPost alternative for MT4 and MT5: TradersPost vs TradingView Link
- AlgoWay alternative for MT4 and MT5: AlgoWay vs TradingView Link
- How to connect TradingView to Exness (MT4 and MT5)
- How to automate TradingView alerts on Pepperstone (MT4 and MT5)
- How to automate TradingView alerts on IC Markets (MT4 and MT5)
- How to automate TradingView alerts on XM (MT4 and MT5)
- How to automate TradingView alerts on Vantage (MT4 and MT5)
- How to automate TradingView alerts on Fusion Markets (MT4 and MT5)
- How to automate TradingView alerts on RoboForex (MT4 and MT5)
- How to automate TradingView alerts on JustMarkets (MT4 and MT5)
- How to automate TradingView alerts on Axi (MT4 and MT5)
- Pricing: plans, limits and what else you pay for
- Full documentation: alert syntax, EA settings and troubleshooting
- FAQ: trials, billing and signal limits