fbpx
Tickerly Trading bot service logo

BLOG

Pyramiding in a TradingView Strategy: Setup and Automation

by

Pyramiding in a TradingView strategy means allowing a script to add more entries in the same direction while a position is already open. You control it with one setting, pyramiding, which caps how many entries can stack up. The default is 1, so no adds happen until you raise it. Once you do, every added entry is a separate order fill, and each fill can fire its own alert. That matters when you route those alerts to an exchange. We built Tickerly to turn TradingView strategy alerts into live bot orders, and every layered entry needs to be planned with that in mind.

This guide covers what pyramiding is, how the setting behaves, how to write entry logic that adds only to winners, and what to confirm before you automate it.

Tickerly
Automate Every Strategy Entry
Connect TradingView alerts to Tickerly bots to automate layered entries across exchange platforms.

Try for free

Key Takeaways

  • The pyramiding property sets the maximum number of same-direction entries from strategy.entry calls. It does not limit strategy.order calls.
  • Pyramiding adds to a position that is moving your way. Averaging down adds to one that is moving against you. They are opposite behaviors.
  • Entry limits are checked when an order is generated, so a backtest with layered entries can behave differently from what you expect on a bar-by-bar read.
  • Each added entry is its own fill and its own alert. Check the full alert sequence before connecting a bot.
  • Position size, stops and exits belong in your TradingView strategy code, so build them into the script before you automate it.

Table of Contents

What pyramiding means in a TradingView strategy

Pyramiding is adding to a winning position as the trend continues. A trader opens a first position, and as price confirms the idea, adds a second and a third, often in smaller size. One trading education site describes it as adding positions only to winners, while averaging down means adding after a price drop to lower the average entry price.

The difference changes your risk profile:

Pyramiding Averaging down
When you add Price moves in your favor Price moves against you
Effect on average entry Moves it toward current price Pulls it down (long)
Exposure as the trade grows Grows after confirmation Grows while the idea is being challenged

In Pine Script, both are the same mechanical act: another strategy.entry in the direction of the open position. TradingView does not know whether the add is a pyramid or an average-down. The pyramiding setting only counts entries. The logic that decides when to add is yours.

How the pyramiding setting works

TradingView’s Strategy properties page defines pyramiding as the maximum number of successive entries allowed in the same direction. With it effectively off, the strategy can open only one long or one short position, even when entry conditions fire again. The same page says the setting affects only strategy.entry orders, not strategy.order orders.

The Pine Script strategies documentation adds that the default value is 1, meaning a strategy can open new positions but cannot add to them with strategy.entry calls. You can set a higher default in the strategy() declaration with pyramiding = 3, or change it in the strategy’s Settings dialog under Properties.

A few behaviors catch people out:

  • The cap counts entries, not size. Pyramiding of 3 allows three entries. If each is 10% of equity, you can hold 30% of equity in that direction.
  • Opposite entries reverse. Per TradingView’s Strategies documentation, an opposite-direction strategy.entry while a position is open increases the order quantity by the open contracts, so the result is a reversal rather than an add.
  • Limits are checked at order generation. The same documentation explains that entry conditions such as pyramiding are evaluated when orders are generated, not when they fill. With pyramiding at 2 and two entries open, a third order is not placed. With pyramiding off, two price-based entries submitted together can both fill in a backtest, because no position existed when each was generated.

That last point is why a strategy that looks clean in code can produce stacked positions you did not intend. If you submit several entry orders at once, test that exact scenario on the chart.

Writing entry conditions that add only to winners

The pyramiding number is a ceiling. What makes it a pyramid rather than a pile-on is your add condition. Three conditions cover most designs:

  1. A position is open in the right direction. Check strategy.position_size > 0 for longs.
  2. The position is in profit. Compare close with strategy.position_avg_price.
  3. The trend confirms again. A new breakout high, a pullback bounce, or an indicator re-cross.

Here is a compact Pine Script v6 example:

//@version=6
strategy("Pyramid example", overlay=true, pyramiding=3,
     default_qty_type=strategy.percent_of_equity, default_qty_value=10)

fast = ta.ema(close, 20)
slow = ta.ema(close, 50)

firstLong = ta.crossover(fast, slow)
inProfit  = strategy.position_size > 0 and close > strategy.position_avg_price
addLong   = inProfit and close > ta.highest(close, 20)[1]

if firstLong
    strategy.entry("Long", strategy.long)
if addLong
    strategy.entry("Add", strategy.long)
if strategy.position_size > 0 and ta.crossunder(fast, slow)
    strategy.close_all()

This opens on a moving-average cross, adds when price breaks its 20-bar high while the trade is profitable, and closes everything when the cross reverses. With pyramiding=3, it can hold up to three entries.

Two refinements are worth making in your own version:

  • Space the adds. Without a minimum gap, a strong candle can trigger adds on consecutive bars. Track the bar of the last entry with ta.barssince or a variable and require a gap.
  • Shrink later entries. Many pyramid designs use decreasing size so the average price stays well behind the market. You can calculate the quantity in the script and pass it to strategy.entry through its qty argument.

Position size, stops and exits in a pyramid

Pyramiding multiplies exposure, so sizing and exits carry more weight than in a single-entry strategy. All of it is defined in your TradingView strategy.

Order size. TradingView’s Strategy properties list three modes: a fixed quantity, an amount in the base currency, and a percentage of available equity at the time the trade opens. Percent of equity is convenient, but note that each added entry is calculated against equity at that moment.

Margin. The same page explains that margin is the percent of a position you must fund. A 25% long margin allows up to 400% of equity per trade, and a margin call liquidates part of the position if funds fall short. A deep pyramid on leveraged margin can reach that territory faster than you think.

Trader reviewing strategy margin settings

Risk rules. TradingView’s strategy.risk.* commands are evaluated on every tick and order execution and cannot be turned off at runtime. When one triggers, the strategy cancels unexecuted orders and closes the position with a market order if it is not flat, per the Strategies documentation. That makes them a useful cap on a layered position.

A practical sequence for exits:

  1. Decide the maximum total exposure, then divide it across your allowed entries.
  2. Decide whether the stop applies to the whole position or moves up as you add.
  3. Write a single exit condition that closes the full stack, or exits that close each leg, and test both.
  4. Cap pyramiding at the smallest number your idea needs.

Because position sizing, stops and risk rules live in the strategy, Tickerly does not set them for you. Whatever your script sends is what the alert carries.

Backtesting a pyramiding strategy without fooling yourself

TradingView’s backtest runs on a broker emulator. The Pine Script v6 User Manual states that strategy.* calls send orders to this emulator, which simulates execution and produces the strategy report. It is a simulation, and layered entries expose its assumptions.

Settings to review before trusting the numbers, all documented on the Strategy properties page:

  • Commission. Applied on both entries and exits, as a percentage of value, a cash amount per contract, or a cash amount per order. A pyramid with four entries pays four entry commissions.
  • Slippage. Set in ticks for market and stop fills. More entries mean more chances for slippage to accumulate.
  • Bar Magnifier and process_orders_on_close. Both change when and at what price orders fill within a bar.
  • Margin. It changes whether a deep stack is even possible.

We cover the broader limits of the tester in our guide to Pine Script Strategy Tester limitations. The short version: a backtest result is a description of how your rules behaved on historical bars under those assumptions. It does not tell you what a live fill will look like.

How pyramiding entries become alerts

This is where pyramiding meets automation. TradingView’s alerts help page says strategy alerts can trigger on order fills and alert function calls, on order fills only, or on alert function calls only. The Pine Script Essential Alerts documentation adds that alerts run around the clock on TradingView’s servers without you being logged in, and that order-fill alerts can be created from the interface on any strategy without special code.

For a pyramid, that has a direct consequence: first entry, second entry and third entry are each a fill, and each produces an alert. An exit is another. So a single trade idea can generate a sequence of four or five messages.

That is also why the choice between strategy alerts and study alerts matters. Our comparison of strategy alerts vs study alerts explains which one carries the order-by-order detail a layered strategy produces.

What to check before you automate

Before a pyramiding strategy touches a live account, walk through this list:

  1. Count the alerts on a full trade. Replay or watch a complete cycle and confirm the number and order of alerts matches your design: entry, each add, exit.
  2. Confirm the pyramiding value in the alert’s strategy. The setting saved in the strategy properties when you create the alert is the one that applies. Check it after any edit.
  3. Use a closed-bar trigger where possible. The Essential Alerts documentation recommends triggering only on the close of the realtime bar to avoid repainting, where the signal appears and disappears while the bar is forming. A pyramid that adds on a repainting condition can fire adds you never saw on the chart.
  4. Match realtime to history. Settings such as calc_on_every_tick and calc_on_order_fills can make live behavior differ from the backtest, so compare your first live sessions with what the chart shows.
  5. Confirm total exposure on the exchange. Add up the largest position your pyramid can build and confirm your account, leverage and margin can carry it.
  6. Test on a demo account first. Tickerly testing uses the exchange’s demo account, where an exchange offers one, so you can watch a full stack of entries go through before real funds are involved.

Our walkthroughs on going from alert to live order and setting up automated trading from TradingView cover the connection steps.

Perspective

Pyramiding is a strategy-design choice that becomes an execution question the moment you automate it. In the chart, three entries look like one neat idea. At the exchange, they are three separate orders arriving at three separate moments.

That is why we focus on the alert-to-order path. Tickerly takes your TradingView strategy alerts and converts them into live orders on your connected exchange, within a fraction of a second, with no coding and no VPS needed for direct exchange connections. You can run several strategies, each with its own alerts, so a pyramiding strategy can sit beside others on the same account.

What we do not do is decide your risk. Position size, stops and exit rules belong in your Pine Script strategy, where you can see and test them. Build the layering logic there, and let the automation carry out what the script says.

Jay

Try your pyramiding strategy with Tickerly

If your strategy is ready and you want its alerts to become orders, Tickerly offers a 30-day free trial. Paid plans are billed monthly: Level 2 at $19 per month, Level 3 at $29 per month and Level 4 at $39 per month, with a Level 4 Ultra option listed on the same page. Plans differ by supported asset classes, the number of strategies and alert limits, so pick the one that covers the number of strategies you plan to run.

Tickerly

If you run the same strategy on several symbols, our guide to a multi symbol TradingView strategy explains how to avoid repainting and automate its alerts.

FAQ

What is the default pyramiding value in TradingView?

The default is 1, according to the Pine Script documentation. That means the strategy can open a position but cannot add to it with strategy.entry calls. Raise the value in the strategy() declaration or in the strategy’s Properties tab.

Does pyramiding apply to strategy.order calls?

No. TradingView’s Strategy properties page says the setting affects only strategy.entry orders. If your script uses strategy.order, the pyramiding cap does not limit it, so you need to enforce limits in your own conditions.

Is pyramiding the same as averaging down?

No. Pyramiding adds while the trade is moving in your favor, and averaging down adds while it moves against you. TradingView treats both as additional same-direction entries, so the difference is entirely in the conditions you write.

Does each pyramid entry send its own alert?

When the alert is set to trigger on order fills, each filled order generates an alert, so a first entry, each add and the exit all send messages. Count them on a full trade before automating, using the checks above.

Sources

This article was produced with Al assistance and reviewed for accuracy. It is provided for general information only and is not professional or financial advice.

Tags :

Latest Post