sorentin

Soren test 222

Say we use strategy.risk.allow_entry_in() to only trade longs. When our script uses the strategy.entry() function to open a short trade, TradingView of course won’t allow our strategy to go short. But that doesn’t mean the trade is ignored. Instead the ‘enter short’ trade – which is actually a sell command – becomes an ‘exit long’ order.

Another way to think about this is the following. The strategy.entry() function can reverse positions: longs into shorts, and shorts into longs. That reverse behaviour gets stopped by strategy.risk.allow_entry_in(). What strategy.entry() instead ends doing is close positions: from long to flat, or from short to flat.

(The example strategies that we discuss later in this article show how strategy.risk.allow_entry_in() makes strategy.entry() close instead of open trades.)

# Can still trade both long or short
strategy.risk.allow_entry_in() can also allow our strategy to trade both long or short. That’s a bit silly, since this is already the default behaviour. But to cod
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?