Skip to content

Commit

Permalink
Improve CatchTheWave Strategy
Browse files Browse the repository at this point in the history
- Add ``vr24h_min`` parameter
  • Loading branch information
math-a3k committed Aug 22, 2023
1 parent 8ff3707 commit 736f84e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions base/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class CatchTheWave(TradingStrategy):
"sell_safeguard": {"default": "0.3", "type": "decimal"},
"use_local_memory": {"default": "1", "type": "bool"},
"use_matrix_time_res": {"default": "0", "type": "bool"},
"vr24h_min": {"default": "3", "type": "decimal"},
}

def __init__(self, bot, symbol=None, **kwargs):
Expand All @@ -233,10 +234,21 @@ def __init__(self, bot, symbol=None, **kwargs):
self.use_matrix_time_res = self.get_param(
"use_matrix_time_res", kwargs
)
self.vr24h_min = self.get_param("vr24h_min", kwargs)

def evaluate_buy(self):
if self.use_matrix_time_res and self.time_safeguard:
return (False, "Holding - Using matrix's time resolution...")
if (
self.vr24h_min > 0
and self.bot.symbol.variation_range_24h < self.vr24h_min
):
return (
False,
f"Symbol's Variation Range below threshold "
f"({self.bot.symbol.variation_range_24h:.3f} < "
f"{self.vr24h_min:.3f}) - waiting for next turn...",
)
if self.is_on_good_status() and self.is_on_wave_onset():
return True, None
return (False, "Symbol is not in good status and ascending...")
Expand Down
7 changes: 7 additions & 0 deletions base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,13 @@ def test_catchthewave(self):
"Using matrix's time resolution",
self.bot1.others["last_logs"][-1],
)
self.bot1.symbol.last_updated = timezone.now()
self.bot1.symbol.variation_range_24h = 1
self.bot1.decide()
self.assertIn(
"Variation Range",
self.bot1.others["last_logs"][-1],
)


@pytest.mark.usefixtures("celery_session_app")
Expand Down
3 changes: 3 additions & 0 deletions docs/trading_bots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Parameters
``use_matrix_time_res``
Use matrix's time resolution (:settings:`TIME_INTERVAL`) (``1`` | ``0``, defaults to ``0``)

``vr24h_min``
Minimum Variation Range (24h) of a Symbol to buy (``Decimal``, defaults to ``3``) if enabled (greater than zero). Meant to keep the bot out of the market when it is moving sideways narrowly.


.. rubric:: References
.. [1] .. autoclass:: base.models.TraderoBot
Expand Down

0 comments on commit 736f84e

Please sign in to comment.