1

In my strategy, I want to set the stoploss as the minimum price between 24 hours.


lowest = ta.lowest(low, 25)

if (4.2 >= stoploss and stoploss >= 1.7)
    strategy.entry("LONG", strategy.long, when=long)
    strategy.exit("exit", "LONG", loss= lowest, profit= close * 4)

However, if I use the lowest I set, the bar will continue to pile up after entering from the long, and the minimum value will change.

How can I use it as a stoploss by fixing the minimum value between 25 hours?

enter image description here

vitruvius
  • 15,740
  • 3
  • 16
  • 26
bnagkeun
  • 11
  • 2

1 Answers1

0

You can use a var if you want to save some data.

var is the keyword used for assigning and one-time initializing of the variable.

So, as long as you don't assign a new value to it, it will keep its value.

So, something like this:

var float lowest_at_entry = na
lowest = ta.lowest(low, 25)

if (long)  // Your long condition
    lowest_at_entry := lowest
vitruvius
  • 15,740
  • 3
  • 16
  • 26