I am very new to quant trading and I am trying to code the following rules into my algorithm and I need some help.
- The stock makes a new 20-day low. The previous 20-bar low must have been made at least three trading sessions earlier. The close of the new low (day one) must be at or below the previous 20-bar low
- An entry buy stop is placed the next day (day two) at the earlier 20 day low. If you are not filled on day two, the trade is cancelled.
- If filled, place a protective sell stop one tick under the lower of the day-one low or the day-two low.
I don't know how to code the following parts
a) previous 20 bar low
b) check whether previous 20 bar low was made at least 3 trading sessions earlier
Any help would be much appreciated.