Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Mar 29, 2024
1 parent 6d0b6ca commit 5de40b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions config.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ order_expiration_time = 8
max_order_breach = 3
stop_loss_threshold = 0.5
risk_factor = 0.618
tp_factor = 2.236
sl_factor = 1.618
be_factor = 0.618
tp_factor = 3.786
sl_factor = 2.382
trl_factor = 0.786
depth = 80

[portfolio]
risk_per_trade = 0.0001
risk_per_trade = 0.0005
account_size = 1000
cagr_threshold = 0.01
sharpe_ratio_threshold = 0.1
sharpe_ratio_threshold = 0.2
total_trades_threshold = 8

[system]
Expand All @@ -39,12 +39,12 @@ leverage = 1
reevaluate_timeout = 3600

[generator]
n_samples = 8
n_samples = 13
blacklist = [USDCUSDT]
timeframes = [1m]

[optimization]
max_generations = 3
max_generations = 5
elite_count = 3
mutation_rate = 0.0236
crossover_rate = 0.8
Expand Down
2 changes: 1 addition & 1 deletion position/risk/break_even.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def next(
tp_threshold = atr[-1] * self.config["tp_factor"]
sl_threshold = atr[-1] * self.config["sl_factor"]

dist = abs(entry_price - take_profit_price) * self.config["be_factor"]
dist = abs(entry_price - take_profit_price) * self.config["tsl_factor"]
curr_dist = abs(entry_price - price)

high = min(ohlcvs[-lookback:], key=lambda x: abs(x.high - price)).high
Expand Down
14 changes: 7 additions & 7 deletions position/risk/volatility.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def next(
ohlcvs: List[Tuple[OHLCV]],
) -> float:
ohlcvs = ohlcvs[:]
lookback = 1
lookback = 3

if len(ohlcvs) < lookback + 3:
return stop_loss_price, take_profit_price

atr = self._atr(ohlcvs, lookback)
price = self._price(ohlcvs)

distance = atr[-1] * self.config["be_factor"]
distance = atr[-1] * self.config["trl_factor"]
tp_threshold = atr[-1] * self.config["tp_factor"]
sl_threshold = atr[-1] * self.config["sl_factor"]

Expand All @@ -41,19 +41,19 @@ def next(
if side == PositionSide.LONG:
next_take_profit = max(entry_price + tp_threshold, take_profit_price - tsl)

if price > tsl:
if price > tsl and price > entry_price:
next_stop_loss = max(entry_price - sl_threshold, stop_loss_price + tsl)

elif side == PositionSide.SHORT:
next_take_profit = max(entry_price - tp_threshold, take_profit_price + tsl)

if price > tsl:
if price > tsl and price < entry_price:
next_stop_loss = min(entry_price + sl_threshold, stop_loss_price - tsl)

return next_stop_loss, next_take_profit

@staticmethod
def _atr(ohlcvs: List[OHLCV], period: int) -> float:
def _atr(ohlcvs: List[OHLCV], period: int) -> List[float]:
highs, lows, closes = (
np.array([ohlcv.high for ohlcv in ohlcvs]),
np.array([ohlcv.low for ohlcv in ohlcvs]),
Expand All @@ -72,8 +72,8 @@ def _atr(ohlcvs: List[OHLCV], period: int) -> float:
for i in range(period, len(true_ranges)):
atr[i] = np.divide((atr[i - 1] * (period - 1) + true_ranges[i]), period)

return atr
return list(atr)

@staticmethod
def _price(ohlcvs: List[OHLCV]) -> float:
return (ohlcvs[-1].high + ohlcvs[-1].low + ohlcvs[-1].close) / 3.0
return (ohlcvs[-1].high + ohlcvs[-1].low + 2 * ohlcvs[-1].close) / 4.0

0 comments on commit 5de40b1

Please sign in to comment.