-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trailing pct instead of ATR #223 #377
base: master
Are you sure you want to change the base?
Conversation
Add code description and use float type for default percentage value.
Same as the other request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I think that you should rebase your commit to have a clean historic, and change the propertie name.
super().init() | ||
|
||
def set_trailing_sl(self, percentage: float = 5): | ||
assert percentage > 0, "percentage must be greater than 0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere else, the framework uses "pct" and "percent" to really mean rate (e.g. 5% == 0.05). I wonder if here shouldn't be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So are you saying that a user should be inputting 0.05 instead of 5 and the code should use that value as is?
index = len(self.data)-1 | ||
for trade in self.trades: | ||
if trade.is_long: | ||
trade.sl = max(trade.sl or -np.inf, | ||
self.data.Close[index]*(1-self._sl_pct)) | ||
else: | ||
trade.sl = min(trade.sl or np.inf, | ||
self.data.Close[index]*(1+self._sl_pct)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index = len(self.data)-1 | |
for trade in self.trades: | |
if trade.is_long: | |
trade.sl = max(trade.sl or -np.inf, | |
self.data.Close[index]*(1-self._sl_pct)) | |
else: | |
trade.sl = min(trade.sl or np.inf, | |
self.data.Close[index]*(1+self._sl_pct)) | |
price = self.data.Close[-1] | |
for trade in self.trades: | |
if trade.is_long: | |
trade.sl = max(trade.sl or -np.inf, price*(1 - self._sl_pct)) | |
else: | |
trade.sl = min(trade.sl or np.inf, price*(1 + self._sl_pct)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before I make this change, I want to let you know that I used index = len(self.data)-1
instead of -1 to be consistent with the TrailingStrategy code. I understand that in TrailingStrategy, we were using ATR which was computed differently and to get an absolute value for an index, we had to use len(self.data)-1, But I don't see any harm in using it here. Thoughts?
@kernc Have you had a chance to look at the questions that I asked? |
7fd493d
to
e7981c7
Compare
7e8513a
to
e28ac6a
Compare
60eff81
to
109c352
Compare
428c361
to
0ce6cab
Compare
No description provided.