Three days up strategy

Hi, I need help to code a strategy that buys a stock if the stock has closed higher than it opened three days/hours/minutes in a row.

I am thinking something like this:
current_date = date.today().isoformat()
yesterday = date.today().isoformat() - timedelta(days=1)
twodaysbefore = date.today().isoformat() - timedelta(days=2)

day1 = api.get_barset(symbol, ‘day’, start=current_date, end=current_date).df
day2 = api.get_barset(symbol, ‘day’, start=yesterday, end=yesterday).df
day3 = api.get_barset(symbol, ‘day’, start=twodaysbefore, end=twodaysbefore).df

& then if day1 < day2 < day3 it buys.
Does this work or do you guys have any other way to do it?

I am new to this so I can be completely wrong, all help needed!
Thanks in advance

Update: I am using python

simply use the last 3 rows and adding another column to calculate the daily return rate, if all increase rate is above 0% will trigger the buy. However, I doubt if the strategy works. Have you done the backtesting?

1 Like

Okay, thanks!
The strategy is for a school project so it does not need to work well, and yes I have done backtesting and with the right exit strategy, the result was better than I expected.
This would work, right?

current_date = date.today().isoformat()
barset = api.get_barset(‘symbol’, ‘day’, start=current_date, end=current_date)
bars = barset[‘symbol’]

day_open = bars[-1].o
day_close = bars[-1].c
percent_change = (day_close - day_open) / day_open * 100

day2_open = bars[-2].o
day2_close = bars[-2].c
percent_change2 = (day2_close - day2_open) / day2_open * 100

day3_open = bars[-3].o
day3_close = bars[-3].c
percent_change3 = (day3_close - day3_open) / day3_open * 100

if percent_change3 > 0 and percent_change > 0 and percent_change2 > 0:

this is a very manual approach. There ways to improve the code efficiency with just 4 lines. Anyway, that also does the work.