Pine Script Max Contract Size Limit
Runs the desired order size through a firm scaling-plan cap before it reaches strategy.entry, so a stale input or a sizing bug can never place an oversized order.
Pine Script
//@version=6
strategy("Target Filled - Max Contract Limit Example", overlay=true, calc_on_every_tick=false)
// --- Inputs ---------------------------------------------------
wantedQty = input.int(5, "Desired Contracts", minval=1)
firmCap = input.int(2, "Firm Scaling Cap", minval=1,
tooltip="Your current scaling-plan limit. Raise it as the account clears milestones.")
// --- Enforce the cap before any order is sent --------------------
sendQty = math.min(wantedQty, firmCap)
// --- Sample signal — replace with your own entry logic ---------
fastMA = ta.ema(close, 9)
slowMA = ta.ema(close, 21)
if ta.crossover(fastMA, slowMA) and strategy.position_size == 0
strategy.entry("Long", strategy.long, qty=sendQty)
strategy.exit("Long Exit", "Long", profit=20, loss=10)
if ta.crossunder(fastMA, slowMA) and strategy.position_size == 0
strategy.entry("Short", strategy.short, qty=sendQty)
strategy.exit("Short Exit", "Short", profit=20, loss=10)
// --- On-chart readout ---------------------------------------------
var table readout = table.new(position.top_right, 1, 1)
if barstate.islast
table.cell(readout, 0, 0, "Sending " + str.tostring(sendQty) + " / cap " + str.tostring(firmCap),
bgcolor=color.new(color.teal, 80), text_color=color.white) Settings
| Input | Default | Purpose |
|---|---|---|
| wantedQty | 5 | What your sizing logic wants to trade before the cap is applied. |
| firmCap | 2 | Hard ceiling from your scaling plan — the order can never exceed it. |
How to use
- Paste into the Pine Editor and swap the EMA-crossover placeholder for your own entry conditions.
- If quantity comes from a risk calculation elsewhere, route its output through
math.min(qty, firmCap)right beforestrategy.entry. - Bump
firmCapas the account clears scaling milestones — pull the current number from your firm's dashboard first. - The top-right table confirms the quantity actually sent, so you can verify the clamp is doing its job.
Typical scaling-plan caps
Contract ceilings vary by firm and account size, and they change over time. The figures below are current per-firm numbers — always confirm against your own dashboard before wiring firmCap into a live strategy.
| Firm | Account | Contract Cap |
|---|---|---|
| Apex | 50k | 10 MES / 10 MNQ |
| Apex | 100k | 2 ES |
| Apex | 150k | 2 NQ |
| Topstep | 50k | 5 micros / 1 mini |
| Topstep | 100k | 10 micros / 2 minis |
| Topstep | 150k | 15 micros / 3 minis |
Frequently Asked Questions
How do I cap position size in Pine Script?
Run whatever quantity your sizing logic produces through
math.min(qty, cap) before it ever reaches strategy.entry. The clamp has to sit on both the long and the short branch — a scaling bug that only guards one direction still breaches the rule the first time it fires the other way.What is a prop firm scaling plan?
A schedule that limits how many contracts an account may hold at once, with the ceiling rising as balance or buffer grows. Apex, for example, allows 10 MES or MNQ contracts on a 50k account but only 2 ES contracts once balance supports a 100k-style position. Topstep scales differently by account size — check the current ladder on the rules database before hardcoding a number, since firms revise these periodically.