Backtrader Close the position after 5 days
tsz fung Chan last edited by
The trading logic is the close is higher than EMA200 then buy
close is lower than EMA200 then close the position
How can I code:
if after 5 days no close signal (price is lower than EMA200) then close the position
@tsz-fung-chan You can keep track of the time data via the self.data.datetime.datetime() function. You can save this value when you enter a position; if the latest datapoint's timestamp is bigger than a defined length of time you can then exit the position.