Skip to content

Why TradingView doesn't follow pyramiding settings when you use `strategy.order()`

Why TradingView doesn’t follow pyramiding settings when you use strategy.order()

Section titled “Why TradingView doesn’t follow pyramiding settings when you use strategy.order()”

TL;DR
strategy.entry() honours pyramiding and strategy.risk.allow_entry_in. strategy.order() bypasses them entirely, so you can easily oversize positions unless you add your own guard.

Order functionRespects pyramiding?Respects allow_entry_in?Typical use
strategy.entryStandard entries where TradingView manages exposure.
strategy.orderCustom sizing, scale-ins/scale-outs, bracket logic.
strategy.exit, strategy.closeN/AN/AExits only; they do not add exposure.
  • Audit scripts that mix strategy.entry and strategy.order—ensure you cap exposure manually.
  • Use strategy.opentrades or strategy.position_size to implement your own guard if needed.
  • Prefer strategy.entry when you want TradingView to enforce pyramiding automatically.
//@version=5
strategy("Pyramiding demo", overlay=true, pyramiding=1)
// This respects pyramiding
if ta.crossover(close, ta.sma(close, 20))
strategy.entry("Long", strategy.long)
// This ignores pyramiding completely
if ta.crossover(close, ta.sma(close, 10))
strategy.order("Aggressive", strategy.long, qty=1)
Tip. If you must use `strategy.order`, guard it with your own counter: `if strategy.opentrades < maxAllowed`.
ScenarioRecommended function
Simple entries with pyramiding limitsstrategy.entry
Adding to winning trades but still respecting risk limitsstrategy.entry with higher pyramiding plus strategy.risk.allow_entry_in
Precise scale-in/scale-out sequencestrategy.order (add custom checks)
Bracket orders (entry + exit submitted together)strategy.order with stop/limit parameters

Adding Manual Guards Around strategy.order

Section titled “Adding Manual Guards Around strategy.order”
maxManualTrades = input.int(2, "Max manual orders")
canAddManual = strategy.position_size >= 0 and strategy.opentrades < maxManualTrades
if canAddManual and ta.crossover(close, ta.sma(close, 10))
strategy.order("Manual add", strategy.long, qty=1)

You’re responsible for maintaining these counters—the platform won’t do it for you.

//@version=5
strategy("Hybrid pyramiding", overlay=true, pyramiding=1)
fast = ta.ema(close, 21)
slow = ta.ema(close, 55)
atr = ta.atr(14)
riskPct = input.float(0.5, "Risk per add-on (%)", minval=0.1)
maxAddOns = input.int(2, "Max manual add-ons", minval=0)
useOrders = input.bool(true, "Use strategy.order for add-ons")
baseQty = strategy.equity * (riskPct * 0.01) / (atr * 2)
if ta.crossover(fast, slow)
strategy.entry("Base", strategy.long, qty=baseQty)
if useOrders and strategy.position_size > 0 and strategy.opentrades < maxAddOns + 1 and close > strategy.position_avg_price + atr
strategy.order("Add-on", strategy.long, qty=baseQty)
if strategy.position_size > 0
strategy.exit("Base Exit", from_entry="Base", stop=strategy.position_avg_price - atr * 2)
Why this works.
  • The base entry uses `strategy.entry` and respects pyramiding=1.
  • Manual add-ons use `strategy.order`, but a custom counter ensures only two additional legs.
  • The exit continues to manage the entire position regardless of how it was built.
  • strategy.order is powerful but dangerous—use it only when you need custom fill logic or simultaneous stop/limit orders.
  • Combine manual exposure guards with risk checks (e.g., if strategy.position_size + qty <= maxSize).
  • Remember strategy.order can submit entries even when strategy.position_size is zero and pyramiding = 0, effectively overriding your intent.
  • Consider using strategy.entry plus strategy.risk.allow_entry_in for most pyramiding use cases—it’s safer and easier to maintain.

My position size exceeds pyramiding—why?

Section titled “My position size exceeds pyramiding—why?”

You likely used strategy.order. Replace it with strategy.entry or add manual checks (strategy.opentrades, strategy.position_size).

Yes. Use strategy.entry for base trades and strategy.order for exceptional cases, but always guard manual orders with counters.

Do risk functions apply to strategy.order?

Section titled “Do risk functions apply to strategy.order?”

Most strategy.risk.* guards do not restrict strategy.order. Treat it as a raw API.

  • strategy.entry respects TradingView’s pyramiding/risk controls; strategy.order does not.
  • If you rely on strategy.order, build your own exposure safeguards.
  • Choose the function that matches your intent—simplicity and platform safeguards vs full manual control.

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.