negating SL pct and adding tests
This commit is contained in:
parent
f2599ffe90
commit
9b38c04579
@ -240,16 +240,16 @@ class Trade(_DECL_BASE):
|
|||||||
if not self.stop_loss:
|
if not self.stop_loss:
|
||||||
logger.debug("assigning new stop loss")
|
logger.debug("assigning new stop loss")
|
||||||
self.stop_loss = new_loss
|
self.stop_loss = new_loss
|
||||||
self.stop_loss_pct = stoploss
|
self.stop_loss_pct = -1 * abs(stoploss)
|
||||||
self.initial_stop_loss = new_loss
|
self.initial_stop_loss = new_loss
|
||||||
self.initial_stop_loss_pct = stoploss
|
self.initial_stop_loss_pct = -1 * abs(stoploss)
|
||||||
self.stoploss_last_update = datetime.utcnow()
|
self.stoploss_last_update = datetime.utcnow()
|
||||||
|
|
||||||
# evaluate if the stop loss needs to be updated
|
# evaluate if the stop loss needs to be updated
|
||||||
else:
|
else:
|
||||||
if new_loss > self.stop_loss: # stop losses only walk up, never down!
|
if new_loss > self.stop_loss: # stop losses only walk up, never down!
|
||||||
self.stop_loss = new_loss
|
self.stop_loss = new_loss
|
||||||
self.stop_loss_pct = stoploss
|
self.stop_loss_pct = -1 * abs(stoploss)
|
||||||
self.stoploss_last_update = datetime.utcnow()
|
self.stoploss_last_update = datetime.utcnow()
|
||||||
logger.debug("adjusted stop loss")
|
logger.debug("adjusted stop loss")
|
||||||
else:
|
else:
|
||||||
|
@ -599,32 +599,42 @@ def test_adjust_stop_loss(fee):
|
|||||||
|
|
||||||
trade.adjust_stop_loss(trade.open_rate, 0.05, True)
|
trade.adjust_stop_loss(trade.open_rate, 0.05, True)
|
||||||
assert trade.stop_loss == 0.95
|
assert trade.stop_loss == 0.95
|
||||||
|
assert trade.stop_loss_pct == -0.05
|
||||||
assert trade.initial_stop_loss == 0.95
|
assert trade.initial_stop_loss == 0.95
|
||||||
|
assert trade.initial_stop_loss_pct == -0.05
|
||||||
|
|
||||||
# Get percent of profit with a lower rate
|
# Get percent of profit with a lower rate
|
||||||
trade.adjust_stop_loss(0.96, 0.05)
|
trade.adjust_stop_loss(0.96, 0.05)
|
||||||
assert trade.stop_loss == 0.95
|
assert trade.stop_loss == 0.95
|
||||||
|
assert trade.stop_loss_pct == -0.05
|
||||||
assert trade.initial_stop_loss == 0.95
|
assert trade.initial_stop_loss == 0.95
|
||||||
|
assert trade.initial_stop_loss_pct == -0.05
|
||||||
|
|
||||||
# Get percent of profit with a custom rate (Higher than open rate)
|
# Get percent of profit with a custom rate (Higher than open rate)
|
||||||
trade.adjust_stop_loss(1.3, -0.1)
|
trade.adjust_stop_loss(1.3, -0.1)
|
||||||
assert round(trade.stop_loss, 8) == 1.17
|
assert round(trade.stop_loss, 8) == 1.17
|
||||||
|
assert trade.stop_loss_pct == -0.1
|
||||||
assert trade.initial_stop_loss == 0.95
|
assert trade.initial_stop_loss == 0.95
|
||||||
|
assert trade.initial_stop_loss_pct == -0.05
|
||||||
|
|
||||||
# current rate lower again ... should not change
|
# current rate lower again ... should not change
|
||||||
trade.adjust_stop_loss(1.2, 0.1)
|
trade.adjust_stop_loss(1.2, 0.1)
|
||||||
assert round(trade.stop_loss, 8) == 1.17
|
assert round(trade.stop_loss, 8) == 1.17
|
||||||
assert trade.initial_stop_loss == 0.95
|
assert trade.initial_stop_loss == 0.95
|
||||||
|
assert trade.initial_stop_loss_pct == -0.05
|
||||||
|
|
||||||
# current rate higher... should raise stoploss
|
# current rate higher... should raise stoploss
|
||||||
trade.adjust_stop_loss(1.4, 0.1)
|
trade.adjust_stop_loss(1.4, 0.1)
|
||||||
assert round(trade.stop_loss, 8) == 1.26
|
assert round(trade.stop_loss, 8) == 1.26
|
||||||
assert trade.initial_stop_loss == 0.95
|
assert trade.initial_stop_loss == 0.95
|
||||||
|
assert trade.initial_stop_loss_pct == -0.05
|
||||||
|
|
||||||
# Initial is true but stop_loss set - so doesn't do anything
|
# Initial is true but stop_loss set - so doesn't do anything
|
||||||
trade.adjust_stop_loss(1.7, 0.1, True)
|
trade.adjust_stop_loss(1.7, 0.1, True)
|
||||||
assert round(trade.stop_loss, 8) == 1.26
|
assert round(trade.stop_loss, 8) == 1.26
|
||||||
assert trade.initial_stop_loss == 0.95
|
assert trade.initial_stop_loss == 0.95
|
||||||
|
assert trade.initial_stop_loss_pct == -0.05
|
||||||
|
assert trade.stop_loss_pct == -0.1
|
||||||
|
|
||||||
|
|
||||||
def test_adjust_min_max_rates(fee):
|
def test_adjust_min_max_rates(fee):
|
||||||
|
Loading…
Reference in New Issue
Block a user