A test result is only as real as the number of contracts behind it. Today we make sure the test trades what you mean. By the end of this lesson, you'll know how TradingView sizes a test trade if you don't tell it. You'll also fix the size at one contract, and size by the dollars you'd risk.
1 of 9
What you'll learn
- Set a fixed size. Use strategy.fixed and 1 so each test trade is one contract.
- Work out the tick value. Multiply the tick size by the dollars per point.
- Set enough starting money. With the default settings, too little can mean no trades.
- Size by risk. Divide your risk dollars by the stop's dollar cost, then round down.
- Keep risk within your limit. Rounding down keeps it at or under. Too wide a stop gives 0.
Exercise
- Add a strategy to a 5-minute MES1! chart without setting a size, and look at the Size column in the List of trades.
- Then add default_qty_type = strategy.fixed and default_qty_value = 1, save, and check that every trade is now 1 contract.
Quick check
1. If you set no size, how big is each test order?
2. On MES, what is syminfo.mintick * syminfo.pointvalue?
3. Risk $100, stop 24 ticks, tick value $1.25. How many contracts after math.floor?
0 of 3 answered.
Finished this lesson?
Tick it off and keep your place
Read the full notes
Set a futures strategy's size in the code with default_qty_type = strategy.fixed and default_qty_value = 1, or size by risk with math.floor(risk dollars / (stop ticks × syminfo.mintick × syminfo.pointvalue)).
- By default, a strategy's orders use 100% of its pretend money (default_qty_type = strategy.percent_of_equity, default_qty_value = 100), which on futures isn't a set number of An agreement, traded on an exchange, to buy or sell a set amount of something at a price agreed now, on a set date later.More in the glossary. Set the size in the code: default_qty_type = strategy.fixed, default_qty_value = 1.
- syminfo.mintick is the The smallest step a price can move. On many stock index futures that’s 0.25 of a point.More in the glossary size (0.25 on A small futures contract on the S&P 500, traded at CME Group. Each point is worth $5, and its smallest step of 0.25 is worth $1.25.More in the glossary) and syminfo.pointvalue the What a move of one whole point is worth for one futures contract. Tick value is the tick size times the point value.More in the glossary ($5 on MES). Their product is the What one tick is worth in money for one futures contract. On the E-mini S&P 500 it’s $12.50.More in the glossary: $1.25.
- TradingView counts one contract as price × point value: at a made-up 5,000, $25,000. With the default 100% Money kept in a futures account as a deposit to cover losses on open contracts. It isn’t a fee or a down payment, and losses can be bigger than it.More in the glossary setting, the test needs that much starting money (Initial capital, in the Properties tab), or it may place no trades.
- Sizing by The most money a trade is planned to lose if its stop loss is hit, before slippage and fees. Each trader chooses their own.More in the glossary: contracts = math.floor(riskDollars / (stopTicks * tickValue)). With a made-up $100 and a 16-tick stop: 5 contracts. Rounding down keeps risk at or under the limit; a stop too wide for the limit gives 0. Pass the size as the third part of strategy.entry().
- More on these settings: Pine Script strategy settings. See Risk per trade in dollars and Sizing the strategy to your account.
Worked example
Made-up numbersSize a made-up trade by risk
Made-up numbers · $100 risk · 24-tick stop · MES tick value $1.25
- Risk per contract: 24 × $1.25 = $30
- $100 ÷ $30 = 3.33
- math.floor rounds down: 3 contracts, $90 at risk
Rounding down keeps the risk at or under the limit.
Your turn
DrillMade-up example · risk $60 · stop 12 ticks · MES tick value $1.25
Trading is risky. You can lose money. Test results are hypothetical, and a good test doesn't mean future profits. This lesson explains how Pine Script works. It isn't advice.