简体   繁体   中英

Unable to invoke `when` condition in strategy.exit

I can't make strategy.exit work properly when only when condition is set. I have code written as follows:

strategy.entry("buy", strategy.long, when=rsi(close, 14) < 30)
strategy.exit("sell", "buy", qty_percent=100, when=rsi(close, 14) > 70)

if I add any other condition in exit the the selling is triggered. Can anybody please help me understand what am I doing wrong?

Thanks in advance.

As the official documentation says

If all the following parameters 'profit', 'limit', 'loss', 'stop', 'trail_points', 'trail_offset' are 'NaN', the command will fail. To use market order to exit, the command strategy.close or strategy.close_all should be used.

https://www.tradingview.com/pine-script-reference/v4/#fun_strategy {dot}exit

So it doesn't work with another params. when is only when to put order, but there must be at least some additional params, like 'profit'.

Use strategy.close if you want to exit by market.

There's actually a warning about that.

警告

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM