From 72bf91c7e7be226b1133cf8384e0c9c6231715a7 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Thu, 18 Apr 2024 19:25:22 +0200 Subject: [PATCH 1/3] [WebInterface] use ssl_fallback_aiohttp_client_session --- Services/Interfaces/web_interface/models/configuration.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Services/Interfaces/web_interface/models/configuration.py b/Services/Interfaces/web_interface/models/configuration.py index 12a9c74d5..462b131fe 100644 --- a/Services/Interfaces/web_interface/models/configuration.py +++ b/Services/Interfaces/web_interface/models/configuration.py @@ -50,6 +50,7 @@ import octobot_commons.symbols as commons_symbols import octobot_commons.display as display import octobot_commons.errors as commons_errors +import octobot_commons.aiohttp_util as aiohttp_util import octobot_commons import octobot_backtesting.api as backtesting_api import octobot.community as community @@ -1140,7 +1141,7 @@ async def _fetch_currency_logo(session, data_provider, currency_id): async def _fetch_missing_currency_logos(data_provider, currency_ids): - async with aiohttp.ClientSession() as session: + async with aiohttp_util.ssl_fallback_aiohttp_client_session("https://coingecko.com") as session: await asyncio.gather( *( _fetch_currency_logo(session, data_provider, currency_id) From c5dd168166c30d7d9cd21cf103f5def8a6044ade Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Fri, 19 Apr 2024 10:17:58 +0200 Subject: [PATCH 2/3] [DeathAndGoldenCrossEvaluator] fix signals to only trigger on crosses --- Evaluator/TA/trend_evaluator/trend.py | 38 ++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Evaluator/TA/trend_evaluator/trend.py b/Evaluator/TA/trend_evaluator/trend.py index c25586240..f9df3750f 100644 --- a/Evaluator/TA/trend_evaluator/trend.py +++ b/Evaluator/TA/trend_evaluator/trend.py @@ -147,7 +147,7 @@ async def ohlcv_callback(self, exchange: str, exchange_id: str, time_frame, include_in_construction=inc_in_construction_data) self.eval_note = commons_constants.START_PENDING_EVAL_NOTE - if len(close) > self.slow_length: + if len(close) > max(self.slow_length, self.fast_length): await self.evaluate(cryptocurrency, symbol, time_frame, candle, close, volume) await self.evaluation_completed(cryptocurrency, symbol, time_frame, eval_time=evaluators_util.get_eval_time(full_candle=candle, @@ -155,23 +155,37 @@ async def ohlcv_callback(self, exchange: str, exchange_id: str, async def evaluate(self, cryptocurrency, symbol, time_frame, candle, candle_data, volume_data): if self.fast_ma_type == "vwma": - ma1 = tulipy.vwma(candle_data, volume_data, self.fast_length)[-1] + fast_ma = tulipy.vwma(candle_data, volume_data, self.fast_length) elif self.fast_ma_type == "lsma": - ma1 = tulipy.linreg(candle_data, self.fast_length)[-1] + fast_ma = tulipy.linreg(candle_data, self.fast_length) else: - ma1 = getattr(tulipy, self.fast_ma_type)(candle_data, self.fast_length)[-1] + fast_ma = getattr(tulipy, self.fast_ma_type)(candle_data, self.fast_length) if self.slow_ma_type == "vwma": - ma2 = tulipy.vwma(candle_data, volume_data, self.slow_length)[-1] + slow_ma = tulipy.vwma(candle_data, volume_data, self.slow_length) elif self.slow_ma_type == "lsma": - ma2 = tulipy.linreg(candle_data, self.slow_length)[-1] + slow_ma = tulipy.linreg(candle_data, self.slow_length) else: - ma2 = getattr(tulipy, self.slow_ma_type)(candle_data, self.slow_length)[-1] - - if ma1 > ma2: - self.eval_note = -1 - elif ma1 < ma2: - self.eval_note = 1 + slow_ma = getattr(tulipy, self.slow_ma_type)(candle_data, self.slow_length) + + if min(len(fast_ma), len(slow_ma)) < 2: + # can't compute crosses: not enough data + self.logger.debug(f"Not enough data to compute crosses, skipping {symbol} {time_frame} evaluation") + return + + just_crossed = ( + fast_ma[-1] > slow_ma[-1] and fast_ma[-2] < slow_ma[-2] + ) or ( + fast_ma[-1] < slow_ma[-1] and fast_ma[-2] > slow_ma[-2] + ) + if just_crossed: + # crosses happen when the fast_ma and fast_ma just crossed, therefore when it happened on the last candle + if fast_ma[-1] > slow_ma[-1]: + # golden cross + self.eval_note = -1 + elif fast_ma[-1] < slow_ma[-1]: + # death cross + self.eval_note = 1 # evaluates position of the current (2 unit) average trend relatively to the 5 units average and 10 units average trend From ea38f735bbd9aec348b72133f89bd5c003724a65 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Fri, 19 Apr 2024 10:36:44 +0200 Subject: [PATCH 3/3] [DeathAndGoldenCrossEvaluator] update docs --- .../resources/DeathAndGoldenCrossEvaluator.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Evaluator/TA/trend_evaluator/resources/DeathAndGoldenCrossEvaluator.md b/Evaluator/TA/trend_evaluator/resources/DeathAndGoldenCrossEvaluator.md index 5b3437028..916ede433 100644 --- a/Evaluator/TA/trend_evaluator/resources/DeathAndGoldenCrossEvaluator.md +++ b/Evaluator/TA/trend_evaluator/resources/DeathAndGoldenCrossEvaluator.md @@ -1,4 +1,7 @@ DeathAndGoldenCrossEvaluator is based on two [moving averages](https://www.investopedia.com/terms/m/movingaverage.asp), by default one of **50** periods and other one of **200**. If the fast moving average is above the slow moving average, this indicates a bull market (signal: -1) When this happens it's called a [Golden Cross](https://www.investopedia.com/terms/g/goldencross.asp). -Inversely, if it's the fast moving average which is above the slow moving average this indicates a bear market (signal: 1). When this happens it's called a [Death Cross](https://www.investopedia.com/terms/d/deathcross.asp) \ No newline at end of file +Inversely, if it's the fast moving average which is above the slow moving average this indicates a bear market (signal: 1). When this happens it's called a [Death Cross](https://www.investopedia.com/terms/d/deathcross.asp) + +This evaluator will always produce a value of `0` except right after a golden or death cross +is found, in this case a `-1` or `1` value will be produced.