For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Backtrader Close the position after 5 days
-
The trading logic is the close is higher than EMA200 then buy
close is lower than EMA200 then close the positionHow 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.