new events for trailing stop
This commit is contained in:
parent
af089554ce
commit
04c5279826
12
main.py
12
main.py
@ -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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user