-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
I'm looking to calculate the max drawdown point and measure my current distance from that point since I started opening trades. Something like the following:
# Deleverage if we are over a certain percent invested and the market is recovering from the low point elif highly_leveraged and bounce_from_low_pct > 2*atr_threshold_pct: if self.position.pl_pct > decayed_take_profit: self.position.close(size = 0.2)
the bounce_from_low_pct
is
low_point_in_trade = self.equity[-bars_since_trade_open:].min() # The lowest value our account hit since the first trade was entered if we are in a trade bounce_from_low_pct = (self.equity[-1] - low_point_in_trade)/low_point_in_trade
but obviously this doesn't work because self.equity is simply the current equity. I can't access the history.
Should I keep a list that I append the new equity every run of the next() method?
Is there a way to access the _equity[-bars_since_trade_open:]
?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments
-
this is what i came up with but I'm sure I'm not doing this the best way.
if self.position.size > 0: self.equity_during_trade.append(self.equity) else: self.equity_during_trade = []
Beta Was this translation helpful? Give feedback.
All reactions
-
The above works btw, I just wasn't sure if there was a more proper way.
Beta Was this translation helpful? Give feedback.
All reactions
-
Here's an alternative:
if buy_condition: order = self.buy(...) if order not in self.orders: # trade was executed self.low_point_in_trade = self.equity self.low_point_in_trade = min(self.equity, self.low_point_in_trade)
I think I like yours better.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1