Skip to content

Commit

Permalink
Merge pull request #1232 from Drakkar-Software/dev
Browse files Browse the repository at this point in the history
Dev merge
  • Loading branch information
GuillaumeDSM authored Apr 19, 2024
2 parents 1b146b9 + ea38f73 commit bbb3a12
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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)
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.
38 changes: 26 additions & 12 deletions Evaluator/TA/trend_evaluator/trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,45 @@ 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,
time_frame=time_frame))

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
Expand Down
3 changes: 2 additions & 1 deletion Services/Interfaces/web_interface/models/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bbb3a12

Please sign in to comment.