w1ld3r / crypto-signal

The #1 Automated Technical Analysis (TA) & Algo. Trading tool for Coinbase, Bittrex, Binance, and more! (Track over 500+ coins)
http://cryptosignal.dev
MIT License
76 stars 37 forks source link

[BUG] conditionals - not working #19

Closed onradr closed 3 years ago

onradr commented 3 years ago

MY SETTINGS: indicators: stoch_rsi:

conditionals:

i can take notifications without conditionals but with this settings i cant. i put some loggers on your code in notification.py on "notify_conditional" and i see the vales always changed together cold-cold, hot-hot and x always stay on "0", cause of that the code can not enter this if "if x == nb_conditions and x != 0:" and i cant recieve any notification. Have you any idea of bugfix about that @w1ld3r

Thanks for your help mate!

w1ld3r commented 3 years ago

Hello @onradr, If it's the first stoch_rsi indicator defined in your config file, you have to replace stoch_rsi: 1 by stoch_rsi: 0. The value after the indicator name is the index of the indicator. For example, you can define multiple stoch_rsi indicators with different candle_period and in conditionals you can have:

- label: "Time to Buy"
    hot:
        - stoch_rsi: 0
        - stoch_rsi: 1
        - stoch_rsi: 2
- label: "Time to Sell"
    cold:
        - stoch_rsi: 2
onradr commented 3 years ago

Now I understand your logic. Thanks mate!

My last question about notifications is prices. I can't get the price in conditional notifications, can you help me about this? I am sending the example I tried below.

I have one indicator enabled like this (other indicators and informants are enabled=false ) ;

  stoch_rsi:
    - enabled: true
      alert_enabled: true
      alert_frequency: always
      signal:
        - stoch_rsi
      hot: 30
      cold: 70
      candle_period: 1m
      period_count: 14
      mute_cold: false

and i have one informants like your readme file;

  ohlcv:
    - enabled: true
      signal:
        - high
        - low
        - close
      candle_period: 1m
      period_count: 14

and my conditions are like this;

  - label: "Buy"
    hot:
      - stoch_rsi: 0

  - label: "Sell"
    cold:
      - stoch_rsi: 0

and my telegram template is like this;

template: "{{market}} {{status}}! {{ '\n' }} Price: {{ price_value.close }}"

If I run the app, i took this error;

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "app.py", line 100, in run
    self.behaviour.run(self.market_data, self.settings['output_mode'])
  File "/app/behaviour.py", line 74, in run
    self.notifier.notify_all(new_result)
  File "/app/notification.py", line 153, in notify_all
    self.notify_conditional(exchange, market_pair, _messages)
  File "/app/notification.py", line 202, in notify_conditional
    self.notify_telegram([new_message], None)
  File "/app/notification.py", line 307, in notify_telegram
    formatted_messages.append(message_template.render(message))
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 2, in top-level template code
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 471, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'price_value' is undefined
w1ld3r commented 3 years ago

Have you tried this ?

onradr commented 3 years ago

yes i do @w1ld3r, same error as before. i use your develop branch, could this be the cause of the error?

Starting Worker-1
Starting default analyzer...
Using the following exchange(s): ['binance']
Getting data for ['XRP/USDT']
Beginning analysis of binance
Beginning analysis of XRP/USDT
XRP/USDT:

indicators:     stoch_rsi #0: 23.45299231
informants:     ohlcv #0: 1.59140000/1.59000000/1.59030000
crossovers:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "app.py", line 100, in run
    self.behaviour.run(self.market_data, self.settings['output_mode'])
  File "/app/behaviour.py", line 74, in run
    self.notifier.notify_all(new_result)
  File "/app/notification.py", line 153, in notify_all
    self.notify_conditional(exchange, market_pair, _messages)
  File "/app/notification.py", line 202, in notify_conditional
    self.notify_telegram([new_message], None)
  File "/app/notification.py", line 307, in notify_telegram
    formatted_messages.append(message_template.render(message))
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 471, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'analysis' is undefined
onradr commented 3 years ago

by the way, without conditionals prices is working @w1ld3r

w1ld3r commented 3 years ago

Can you send the error message when using {{prices}}.

w1ld3r commented 3 years ago

@onradr, PLease pull the last modification. I've made a fix allowing the use of {{prices}} in the notifier template.

onradr commented 3 years ago

it's works mate, thank you for bug fixing.