Skip to content
Algo Trade Analytics Docs

strategy.entry() - Pine Script Function

Creates an order that enters a position. A call creates a market order when neither limit nor stop is supplied. It can also create limit, stop, and stop-limit orders. Calls are affected by the strategy’s pyramiding setting and can reverse an open position in the opposite direction.

strategy.entry(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, disable_alert) → void
NameTypeDescription
idseries stringOrder identifier. Reusing an ID can modify an unfilled order with that ID.
directionstrategy_directionstrategy.long or strategy.short.
qtyseries int/floatOptional order size. When omitted, the strategy’s default order-size settings apply.
limitseries int/floatOptional limit price. With no stop, creates a limit order.
stopseries int/floatOptional stop price. With no limit, creates a stop order; with limit, creates a stop-limit order.
oca_nameseries stringOptional One-Cancels-All group name.
oca_typeinput stringOptional OCA behavior such as strategy.oca.none, strategy.oca.cancel, or strategy.oca.reduce.
commentseries stringOptional label shown instead of the order ID in strategy output.
alert_messageseries stringOptional custom message for an order-fill alert. Use {{strategy.order.alert_message}} in TradingView’s alert Message field.
disable_alertseries boolWhen true, suppresses the order-fill alert for the order created by this call.
//@version=6
strategy("Moving-average entries", overlay = true, pyramiding = 1)
float fast = ta.sma(close, 14)
float slow = ta.sma(close, 28)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 1)
if ta.crossunder(fast, slow)
strategy.entry("Short", strategy.short, qty = 1)
plot(fast, "Fast", color.aqua)
plot(slow, "Slow", color.orange)
  • An entry in the opposite direction reverses the open position by default. The transaction size can therefore be larger than the requested resulting position.
  • The strategy’s pyramiding property controls how many entries created by strategy.entry() can be open in the same direction.
  • A priced order can remain unfilled. Creating an order is not the same as the broker emulator filling it.
  • To exit without reversing, use strategy.exit(), strategy.close(), or strategy.close_all() as appropriate.