-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
A feature to exit at the end of day. #529
wolfcuring
started this conversation in
Ideas
-
As I am interested in intra-day trading, I need to exit at the last bar of day. I checked kernc's package, it does not seem to support this functionality. So I coded a func to added a column to the OHLC data, so that when it is the second last bar of a day, it gives a signal of 1.
def col_day_end(es):
es['end_of_day'] = 0
es['day'] = es.index.astype(str).str.split(' ').str[0]
last = pd.DataFrame.last_valid_index
es.loc[es.groupby('day').apply(last),'end_of_day'] = 1
es.end_of_day = es.end_of_day.shift(periods=-1)
return es.end_of_day
...
if self.position:
if self.data.end_of_day == 1 :
self.position.close()
It works, but seems quite clumsy. Maybe this can be added to the package in further version.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment