'How to set stop loss at previous bar low of long entry?

I would like to set my stop loss at the previous bar low of long entry.

I'm trying value when(your_condition, low[1], 0), but I don't know what "your_condition" is.



Solution 1:[1]

stop parameter in strategy.exit() sets SL price:

stop (series int/float) An optional parameter. Stop loss (requires a specific price).If it is specified, a stop order is placed to exit market position at the specified price (or worse)

Since the function runs on each candle when it closes (and with the data of the candle that just closed) you can set this function so that the stop parameter will set low as the stop loss price:

strategy.exit(id="Close Long", stop=low)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 marc_s