Back to Community
Turtle Soup plus One - Need help

I am very new to quant trading and I am trying to code the following rules into my algorithm and I need some help.

  1. 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
  2. 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.
  3. 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.


2 responses

By "trading session" do you mean trading days?

You can get an idea with this algo

If you mean the previous 20 bars you can use the history function to get the prices but you will have to track when you did the last operation for your trades you can have variable for the "context"

close = history(context.period+1, '1d', 'close_price')