How to set a profit target? Can we have an example code? #350
Unanswered
Raymond-Peng
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Python builtin Why don't you show us some of your code to see where you're stuck. Setting basic TP targets to prev 5-day max, along with SL class S(TrailingStrategy):
def init(self):
super().init()
self.prev_5bar_max = self.I(self.data.High.s.rolling(5).max)
def next(self):
super().next()
if self.data.Close < prev_5bar_max:
self.buy(tp=prev_5bar_max) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Creators and Community,
I wonder how to use 'tp' to set a profit target to exit a strategy alongside with a trailing stop loss. Could you provide an example with the "compassable strategy" script under "doc/examples/Strategies Library.py" and set a profit target like higher than previous 5 day's high? It would be really helpful if there's a strategy example that shows the implementation of both the trailing stop and profit target at the same time. Also I wonder what's the 'super' in this code do since it doesn't appear in other scripts? Thank you in advance :)
Regards,
Ray
Beta Was this translation helpful? Give feedback.
All reactions