I want to write a code for a buy condition: closing price has been rising for the last 5 bars
Posted: Tue Jun 22, 2021 2:33 pm
Let's say my strategy is to buy a stock that has been rising for the past 5 bars.
I would write something like this:
longCondition = (close > close[1]) and (close[1] > close[2]) and (close[2] > close[3]) and (close[3] > close[4]) and (close[4] > close[5])
However, I have a feeling that there's a simpler way to code this by using a variable that updates itself. I'm not so sure though. How could I improve this?
I would write something like this:
longCondition = (close > close[1]) and (close[1] > close[2]) and (close[2] > close[3]) and (close[3] > close[4]) and (close[4] > close[5])
However, I have a feeling that there's a simpler way to code this by using a variable that updates itself. I'm not so sure though. How could I improve this?