Pine Script strategy.entry(): Orders, Fills and an RSI Example
strategy.entry() creates an entry order in a Pine strategy simulation. Understanding the difference between a signal, an order and a filled position is necessary before interpreting a backtest. An entry condition alone does not establish profitability or send a live broker order.

Order creation and position changes
The function takes an order ID and direction, with optional size and price arguments. Without a limit or stop price, an entry is a market order. A stop argument on an entry is an entry trigger; it is not a protective stop-loss exit.
Under the usual strategy settings, calculations occur at bar close and a market order can fill at the next available tick, commonly the next bar's open in historical testing. Opposite-direction entries can reverse a position. Pyramiding governs additional same-direction entries; it does not prohibit reversal. Confirm these settings in TradingView's strategy documentation.
Order IDs link the logic to the trade report and related exits. They are labels for orders or groups of entries, not proof that each call produced a separate fill. When debugging, inspect the position before and after the order, rather than counting condition markers alone.
Inspect an RSI entry example
This existing v5 example is retained as an entry-and-exit reading exercise. Its final source passed a syntax check during this revision. No market-data performance test is claimed. The defaults illustrate mechanics and are not recommended trading parameters.
//@version=5
strategy("RSI Reversal Entry System", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Input parameters
rsi_length = input(14, title="RSI Length")
rsi_oversold = input(30, title="RSI Oversold Level")
rsi_overbought = input(70, title="RSI Overbought Level")
stop_loss_pct = input(2.0, title="Stop Loss %") / 100
// Calculate RSI
rsi_value = ta.rsi(close, rsi_length)
// Entry conditions
long_condition = ta.crossover(rsi_value, rsi_oversold) and close > ta.sma(close, 20)
short_condition = ta.crossunder(rsi_value, rsi_overbought) and close < ta.sma(close, 20)
// Execute entries
if (long_condition)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", stop=close * (1 - stop_loss_pct))
if (short_condition)
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", stop=close * (1 + stop_loss_pct))
// Plot RSI for visual reference
plot(rsi_value, title="RSI", color=color.blue)
hline(rsi_oversold, "Oversold", color=color.green)
hline(rsi_overbought, "Overbought", color=color.red)
The long condition requires two events on the same calculation: RSI crosses above its oversold threshold, and price is above the 20-bar SMA. The short condition requires the corresponding cross below the overbought threshold with price below the SMA. These tests define the rule; they do not establish that the market has reversed.
The SMA is a filter, so some RSI crosses produce no entry. That makes a useful first debugging exercise: locate a cross, compare the same bar's close with its SMA, then explain whether the combined boolean was true. Avoid interpreting every RSI crossing as a missing order.
What this code does not guarantee
The stop uses the signal bar's close, not the eventual fill price. With the default 2% input and a hypothetical signal close of 100, the long stop is 98. If the entry fills at 103, the distance to that same stop is 5, not 2% of 103. Gaps and execution costs can further change the loss.
The exit call sits inside the entry-condition block. It does not calculate a new stop on every bar, and this is not a trailing-stop implementation. A later qualifying signal can issue an exit update. Review that behavior before describing the stop as permanently fixed at the original entry.
The 10% equity default is position allocation, not account loss at the stop. For a simplified unlevered position worth 1,000 in a 10,000 account, a 2% adverse price change equals 20 before costs: 0.2% of account equity. This arithmetic assumes that exact position value and price move; it is not a maximum-loss promise or sizing recommendation. Contract multipliers, leverage, currency and fill price require separate treatment.
There are no explicit commission or slippage settings in this source. There is also no take-profit order, time exit, session filter or input-bound validation. RSI and its horizontal levels are plotted on the main pane because overlay is true, which may make the price chart awkward to read. These are visible properties of the example, not hidden features supplied by the function.
A focused verification sequence
- Use a standard candle chart and record the exact symbol, timeframe, session and testing dates.
- Locate one long and one short condition. Record the RSI cross, close and SMA at each signal bar.
- Compare order creation with the fill shown in the trade report. Include a gap if the dataset has one.
- Calculate the stop from the signal close and compare it with the entry fill. Check whether a later condition changed it.
- Inspect an opposite-direction signal while a position is open. Confirm the resulting reversal quantity and final position.
- Set representative costs, rerun the same frozen rules and save the report before changing any parameters.
This sequence checks whether the implementation matches the stated rule. Evaluating an edge requires a separate experiment, including unseen data and a record of every parameter variation tried. Adding volume, session or higher-timeframe conditions may reduce signals; it does not establish higher-quality trades without comparison.
Building and testing through Pineify
Pineify's visual tools can assemble supported indicators and entry conditions into Pine code. Review the generated source and run the resulting strategy on TradingView. The builder does not remove the need to inspect fills, configure costs or distinguish a percentage allocation from risk at a stop. See the feature overview.
For alert workflows, TradingView alerts and an external order executor are separate from the strategy's simulated orders. An alert needs to be created and configured; a chart marker is not a broker receipt. Read TradingView's alert documentation before connecting any execution service.
The companion stop-loss article explains why the stop's reference price and update rule must be explicit. For shorter bars, the scalping workflow covers the additional importance of execution costs.
Does strategy.entry() immediately open a position?
It creates an order in the strategy simulation. Whether and when it fills depends on order type, prices and strategy settings. Inspect the trade report rather than assuming the signal bar is the fill bar.
Is the stop parameter in strategy.entry() a stop loss?
It sets a price trigger for entering. A protective exit is separate. In the example, strategy.exit creates the stop exit tied to the matching entry ID.
Does the example risk 10% of equity?
The default requests a position allocation of 10% of equity. The loss depends on price movement, fills, costs and instrument specifications. Allocation and loss at an exit are different quantities.
Do extra entry filters improve a strategy?
They change which trades are allowed. Compare a fixed baseline with the filtered version using the same costs and untouched evaluation data. Fewer trades alone do not establish an improvement.


