WARNING!!!!
The snippet below will introduce backtest traps. Read this and this for more details. To reduce the impact of the traps, either
- Use timeframe-detail, or
- Re-calculate
current_profitto use last candle’s close rate
pairs_data = {
"MTL/USDT:USDT": {
"minimal_roi": {
0: 0.257,
38: 0.092,
65: 0.024,
162: 0
},
"stoploss": -0.1,
"trailing_stop_positive": 0.01,
"trailing_stop_positive_offset": 0.06,
},
"ANT/USDT:USDT": {
"minimal_roi": {
0: 0.378,
94: 0.146,
252: 0.051,
417: 0
},
"stoploss": -0.25,
"trailing_stop_positive": 0.01,
"trailing_stop_positive_offset": 0.079,
},
"XEM/USDT:USDT": {
"minimal_roi": {
0: 0.055,
18: 0.043,
69: 0.033,
80: 0
},
"stoploss": -0.5,
"trailing_stop_positive": 0.012,
"trailing_stop_positive_offset": 0.014,
},
}
# Disable global roi
minimal_roi = {
"0": 1000
}
# Disable stoploss
stoploss = -0.99
def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs) -> Optional[Union[str, bool]]:
# reverse roi table, to check from biggest minute first
reverse_roi = dict(reversed(list(self.pairs_data[pair]['minimal_roi'])))
for min, profit in reverse_roi.items():
if (current_time - timedelta(minutes=int(min)) < trade.open_date_utc):
# this minute hasn't been reached. Move to next minute check
continue
else:
if (current_profit >= profit):
return "roi"
break
if (current_profit <= self.pairs_data[pair]['stoploss']):
return "stoploss"
def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs) -> float:
sl_new = 1
if (current_profit >= self.pairs_data[pair]['trailing_stop_positive_offset']):
sl_new = self.pairs_data[pair]['trailing_stop_positive']
return sl_new
[…] Different ROI, trailing and stoploss for each pairs […]