Restricts strategy.entry to opening only long or only short positions.
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
strategy.risk.allow_entry_in(value: simple string) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| value | simple string | required | The 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 fromstrategy.orderare not filtered by it. - Call it once, at the top level of the script.
Example
//@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