How to Set the Lot Size in TradingView Alerts for MT5

Last updated · By the TradingView Link team
Short answer

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=:

Where the limits on q= come from
Specification fieldWhat 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.

What qt=percent opens on a $10,000 account, EURUSD at 1.10
AlertLotsMarginLoss 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?

The codes come from MetaQuotes' lists for MT5 and MT4. The troubleshooting guide covers every other reason an alert doesn't trade.

Test your lot size on a demo account
Connect TradingView to MT4 or MT5 and send one alert with q= to see the size MetaTrader opens. 5 free alerts a month, no credit card.

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

All checked November 2026. How the EA sizes each order comes from our own MT4 and MT5 EA code.

Related guides