new events for trailing stop

This commit is contained in:
Giulio De Pasquale 2020-11-28 16:13:27 +00:00
parent af089554ce
commit 04c5279826

12
main.py
View File

@ -35,6 +35,8 @@ class EventKind(Enum):
REACHED_GOOD_PROFIT = 6,
REACHED_MAX_LOSS = 7,
CLOSE_POSITION = 8,
TRAILING_STOP_SET = 9,
TRAILING_STOP_MOVED = 10
class Event():
@ -283,7 +285,15 @@ def update_stop_percentage(state: State, status: Status):
last_position.profit_loss_percentage, TAKER_FEE)
# set stop percentage for first time
if not status.stop_percentage or last_pl_net_perc - TRAIL_STOP_PERCENTAGES[state] > status.stop_percentage:
if not status.stop_percentage:
status.add_event(Event(EventKind.TRAILING_STOP_SET, status.get_current_tick()))
status.stop_percentage = last_pl_net_perc - \
TRAIL_STOP_PERCENTAGES[state]
return
# moving trailing stop
if last_pl_net_perc - TRAIL_STOP_PERCENTAGES[state] > status.stop_percentage:
status.add_event(Event(EventKind.TRAILING_STOP_MOVED, status.get_current_tick()))
status.stop_percentage = last_pl_net_perc - \
TRAIL_STOP_PERCENTAGES[state]