Sidechair

strategy.risk.allow_entry_in()

Browse the reference

Restricts strategy.entry to opening only long or only short positions.

Try it in the editor

strategy.risk.allow_entry_in(value) chooses which side the strategy may open. With strategy.direction.long, a short entry no longer opens a short; if a long position is open it only closes it. strategy.direction.short does the reverse, and strategy.direction.all, the default, allows both.

It lets one script serve a long-only account without a second code path: the same crossover signals work, and the short side is quietly removed.

Syntax

Pine Script
strategy.risk.allow_entry_in(value: simple string) -> void

Arguments

NameTypeDefaultDescription
valuesimple stringrequiredThe direction entries may open: strategy.direction.long, strategy.direction.short or strategy.direction.all.

Returns

Nothing. The rule stays in force for the whole run.

Remarks

  • The rule applies to strategy.entry. Orders from strategy.order are not filtered by it.
  • Call it once, at the top level of the script.

Example

Pine ScriptLong-only version of a crossoverOpen in editor
//@version=6
strategy("Long only", overlay = true)
strategy.risk.allow_entry_in(strategy.direction.long)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
    strategy.entry("Short", strategy.short)
plot(fast, "Fast", color.green)
plot(slow, "Slow", color.red)

See also

Runs on Sidechair