python-tradingview-ta icon indicating copy to clipboard operation
python-tradingview-ta copied to clipboard

SyntaxError: invalid syntax

Open shanmugam023 opened this issue 4 years ago • 24 comments

Hi,

Thanks for your code. I am getting below error while running below command kindly check and let me know. Thanks for advance " from tradingview_ta import * Traceback (most recent call last): File "", line 1, in File "/opt/rh/rh-python35/root/usr/lib/python3.5/site-packages/tradingview_ta/init.py", line 1, in from .main import TA_Handler, TradingView, Analysis, Interval, Exchange, get_multiple_analysis, version File "/opt/rh/rh-python35/root/usr/lib/python3.5/site-packages/tradingview_ta/main.py", line 289 exchange_symbol = f"{self.exchange}:{self.symbol}"

shanmugam023 avatar Jul 23 '21 05:07 shanmugam023

Hi @shanmugam023,

I cannot reproduce the issue without a clear, concise, and detailed description. Please reply with:

  • The version of tradingview-ta
  • Your operating system (Windows, Mac, Linux, etc)

Edit: This issue seems to be caused by outdated Python installation. Tradingview-ta uses f-strings that were added in Python 3.6. Consider updating your Python installation as Python 3.5 has reached end-of-life.

folfcoder avatar Jul 23 '21 05:07 folfcoder

Yes sure

  1. tradingview-ta-3.2.6

  2. Linux (CentOS release 6.10)

  3. Python 3.5.1

shanmugam023 avatar Jul 23 '21 05:07 shanmugam023

@shanmugam023, please update your Python to 3.6 or newer. I will update the python_requires in setup.py soon. Thanks for informing me. Please let me know if you have any other questions.

folfcoder avatar Jul 23 '21 05:07 folfcoder

Thank you so much for your help :)

shanmugam023 avatar Jul 23 '21 06:07 shanmugam023

Sorry fo disturbing. Now it's working fine. but i can see only analysis.summary "RECOMMENDATION': 'SELL', 'BUY': 2, 'SELL': 14, 'NEUTRAL': 10}", I want "analysis.indicators" from your script. Anything i want to upgrade the Package ?

shanmugam023 avatar Jul 23 '21 12:07 shanmugam023

You don't need to upgrade anything. Just replace summary with indicators, or use this example:

from tradingview_ta import TA_Handler, Interval, Exchange

tesla = TA_Handler(
    symbol="TSLA",
    screener="america",
    exchange="NASDAQ",
    interval=Interval.INTERVAL_1_DAY
)
analysis = tesla.get_analysis()
print(analysis.indicators)

image

folfcoder avatar Jul 23 '21 12:07 folfcoder

Great Thank you so much :)

shanmugam023 avatar Jul 23 '21 14:07 shanmugam023

Hi,

Sorry disturbing again I have one doubt if i want to check multiple coin indicator output at the same time what should i do?

Example: symbol="SXPUSDT,ICPUSDT", --> Is it correct way ?

shanmugam023 avatar Jul 23 '21 15:07 shanmugam023

No, please read the documentation: https://python-tradingview-ta.readthedocs.io/en/latest/usage.html#retrieving-multiple-analysis.

So, your code would be something like this:

from tradingview_ta import *
analysis = get_multiple_analysis(screener="crypto", interval=Interval.INTERVAL_1_HOUR, symbols=["BINANCE:SXPUSDT", "BINANCE:ICPUSDT"])

You can then iterate through analysis and read the indicators.

for key, value in analysis.items():
    print(key)
    print(value.indicators)

folfcoder avatar Jul 23 '21 16:07 folfcoder

Thank you so much for your quick help :)

shanmugam023 avatar Jul 23 '21 16:07 shanmugam023

Hey sorry again 👍 , I have created a one file and add all the symbols in that file and then i have mentioned in symbols= filelocation but it's not working for me.

shanmugam023 avatar Jul 23 '21 18:07 shanmugam023

symbols requires a list of symbols, not file location. Your code should read the file and parse it into a list. These should work:

  1. Create a symbols.txt file.
  2. Fill it with something like this.
BINANCE:BTCUSDT
BINANCE:XLMUSDT
BINANCE:SXPUSDT
BINANCE:ICPUSDT
  1. Code:
from tradingview_ta import *
with open("symbols.txt", "r") as f:
    # Read the file, split it into a list, delete empty strings.
    symbols = [x for x in f.read().splitlines() if x != ""]

# symbols should look like this:
# ['BINANCE:BTCUSDT', 'BINANCE:XLMUSDT', 'BINANCE:SXPUSDT', 'BINANCE:ICPUSDT']
    
analysis = get_multiple_analysis(screener="crypto", interval=Interval.INTERVAL_1_HOUR, symbols=symbols)

for key, value in analysis.items():
    print(key)
    print(value.indicators)

folfcoder avatar Jul 24 '21 00:07 folfcoder

Great !!!! Your are genius !!!

shanmugam023 avatar Jul 24 '21 01:07 shanmugam023

Hi,

Sorry disturbing again, Actually i got the below output perfectly, But i can see lot of values comes but i need only RSI, Stock RSI, EMA 20,50,200 and then i need to compare the EMA 20 and EMA 50 value --> Is it possible ?

BINANCE:BTCUSDT {'Recommend.Other': 0.09090909, 'Recommend.All': 0.37878788, 'Recommend.MA': 0.66666667, 'RSI': 56.70139501, 'RSI[1]': 55.20397798, 'Stoch.K': 52.64805406, 'Stoch.D': 56.18619977, 'Stoch.K[1]': 53.35542157, 'Stoch.D[1]': 61.8838906, 'CCI20': 36.72781225, 'CCI20[1]': 16.44030541, 'ADX': 40.93073801, 'ADX+DI': 23.49621099, 'ADX-DI': 11.90507464, 'ADX+DI[1]': 23.91573156, 'ADX-DI[1]': 12.11763758, 'AO': 300.66276471, 'AO[1]': 382.42258823, 'Mom': 193.22, 'Mom[1]': 116.58, 'MACD.macd': 196.13664864, 'MACD.signal': 233.84162816, 'Rec.Stoch.RSI': 0, 'Stoch.RSI.K': 16.37209078, 'Rec.WR': 0, 'W.R': -46.99540511, 'Rec.BBPower': 1, 'BBPower': -19.40792452, 'Rec.UO': 0, 'UO': 49.68326132, 'close': 34354.07, 'EMA5': 34374.81758978, 'SMA5': 34382.026, 'EMA10': 34362.5768332, 'SMA10': 34433.698, 'EMA20': 34243.11684956, 'SMA20': 34251.9575, 'EMA30': 34081.35153038, 'SMA30': 34141.735, 'EMA50': 33736.79972229, 'SMA50': 33685.1996, 'EMA100': 33063.34236701, 'SMA100': 32903.851, 'EMA200': 32550.12849332, 'SMA200': 31944.43425, 'Rec.Ichimoku': 0, 'Ichimoku.BLine': 34233.505, 'Rec.VWMA': 1, 'VWMA': 34265.84375132, 'Rec.HullMA9': 1, 'HullMA9': 34298.56644444, 'Pivot.M.Classic.S3': 25175.47, 'Pivot.M.Classic.S2': 28833.9, 'Pivot.M.Classic.S1': 30306.23, 'Pivot.M.Classic.Middle': 32492.33, 'Pivot.M.Classic.R1': 33964.66, 'Pivot.M.Classic.R2': 36150.76, 'Pivot.M.Classic.R3': 39809.19, 'Pivot.M.Fibonacci.S3': 28833.9, 'Pivot.M.Fibonacci.S2': 30231.42026, 'Pivot.M.Fibonacci.S1': 31094.80974, 'Pivot.M.Fibonacci.Middle': 32492.33, 'Pivot.M.Fibonacci.R1': 33889.85026, 'Pivot.M.Fibonacci.R2': 34753.23974, 'Pivot.M.Fibonacci.R3': 36150.76, 'Pivot.M.Camarilla.S3': 30772.49175, 'Pivot.M.Camarilla.S2': 31107.84783333, 'Pivot.M.Camarilla.S1': 31443.20391667, 'Pivot.M.Camarilla.Middle': 32492.33, 'Pivot.M.Camarilla.R1': 32113.91608333, 'Pivot.M.Camarilla.R2': 32449.27216667, 'Pivot.M.Camarilla.R3': 32784.62825, 'Pivot.M.Woodie.S3': 26290.925, 'Pivot.M.Woodie.S2': 28655.4625, 'Pivot.M.Woodie.S1': 29949.355, 'Pivot.M.Woodie.Middle': 32313.8925, 'Pivot.M.Woodie.R1': 33607.785, 'Pivot.M.Woodie.R2': 35972.3225, 'Pivot.M.Woodie.R3': 37266.215, 'Pivot.M.Demark.S1': 29570.065, 'Pivot.M.Demark.Middle': 32124.2475, 'Pivot.M.Demark.R1': 33228.495, 'open': 34293.14, 'P.SAR': 34788.44, 'BB.lower': 33803.51361837, 'BB.upper': 34700.40138163, 'AO[2]': 459.43738235, 'volume': 176.023929} BINANCE:XLMUSDT

shanmugam023 avatar Jul 25 '21 13:07 shanmugam023

My Goal is if EMA 20 value higher then EMA 50 i will get email alert with Coin details (Include RSI, Stock RSI, EMA 20,50,200 )

shanmugam023 avatar Jul 25 '21 13:07 shanmugam023

Sure, it's possible. Let's assume that

indicators = {'Recommend.Other': 0.09090909, 'Recommend.All': 0.37878788, 'Recommend.MA': 0.66666667, 'RSI': 56.70139501, 'RSI[1]': 55.20397798, 'Stoch.K': 52.64805406, 'Stoch.D': 56.18619977, 'Stoch.K[1]': 53.35542157, 'Stoch.D[1]': 61.8838906, 'CCI20': 36.72781225, 'CCI20[1]': 16.44030541, 'ADX': 40.93073801, 'ADX+DI': 23.49621099, 'ADX-DI': 11.90507464, 'ADX+DI[1]': 23.91573156, 'ADX-DI[1]': 12.11763758, 'AO': 300.66276471, 'AO[1]': 382.42258823, 'Mom': 193.22, 'Mom[1]': 116.58, 'MACD.macd': 196.13664864, 'MACD.signal': 233.84162816, 'Rec.Stoch.RSI': 0, 'Stoch.RSI.K': 16.37209078, 'Rec.WR': 0, 'W.R': -46.99540511, 'Rec.BBPower': 1, 'BBPower': -19.40792452, 'Rec.UO': 0, 'UO': 49.68326132, 'close': 34354.07, 'EMA5': 34374.81758978, 'SMA5': 34382.026, 'EMA10': 34362.5768332, 'SMA10': 34433.698, 'EMA20': 34243.11684956, 'SMA20': 34251.9575, 'EMA30': 34081.35153038, 'SMA30': 34141.735, 'EMA50': 33736.79972229, 'SMA50': 33685.1996, 'EMA100': 33063.34236701, 'SMA100': 32903.851, 'EMA200': 32550.12849332, 'SMA200': 31944.43425, 'Rec.Ichimoku': 0, 'Ichimoku.BLine': 34233.505, 'Rec.VWMA': 1, 'VWMA': 34265.84375132, 'Rec.HullMA9': 1, 'HullMA9': 34298.56644444, 'Pivot.M.Classic.S3': 25175.47, 'Pivot.M.Classic.S2': 28833.9, 'Pivot.M.Classic.S1': 30306.23, 'Pivot.M.Classic.Middle': 32492.33, 'Pivot.M.Classic.R1': 33964.66, 'Pivot.M.Classic.R2': 36150.76, 'Pivot.M.Classic.R3': 39809.19, 'Pivot.M.Fibonacci.S3': 28833.9, 'Pivot.M.Fibonacci.S2': 30231.42026, 'Pivot.M.Fibonacci.S1': 31094.80974, 'Pivot.M.Fibonacci.Middle': 32492.33, 'Pivot.M.Fibonacci.R1': 33889.85026, 'Pivot.M.Fibonacci.R2': 34753.23974, 'Pivot.M.Fibonacci.R3': 36150.76, 'Pivot.M.Camarilla.S3': 30772.49175, 'Pivot.M.Camarilla.S2': 31107.84783333, 'Pivot.M.Camarilla.S1': 31443.20391667, 'Pivot.M.Camarilla.Middle': 32492.33, 'Pivot.M.Camarilla.R1': 32113.91608333, 'Pivot.M.Camarilla.R2': 32449.27216667, 'Pivot.M.Camarilla.R3': 32784.62825, 'Pivot.M.Woodie.S3': 26290.925, 'Pivot.M.Woodie.S2': 28655.4625, 'Pivot.M.Woodie.S1': 29949.355, 'Pivot.M.Woodie.Middle': 32313.8925, 'Pivot.M.Woodie.R1': 33607.785, 'Pivot.M.Woodie.R2': 35972.3225, 'Pivot.M.Woodie.R3': 37266.215, 'Pivot.M.Demark.S1': 29570.065, 'Pivot.M.Demark.Middle': 32124.2475, 'Pivot.M.Demark.R1': 33228.495, 'open': 34293.14, 'P.SAR': 34788.44, 'BB.lower': 33803.51361837, 'BB.upper': 34700.40138163, 'AO[2]': 459.43738235, 'volume': 176.023929}

The variable indicators is a dictionary that you can access with keys:

rsi = indicators["RSI"]
stoch_rsi = indicators["Stoch.RSI.K"]
ema20 = indicators["EMA20"]
ema50 = indicators["EMA50"]
ema200 = indicators["EMA200"]

You can compare EMA20 and EMA50 with this code:

if indicators["EMA20"] > indicators["EMA50"]:
    # Send email here
    server.sendmail(sender_email, receiver_email, message)

Python has a built-in smtplib module that you can use to send emails. Maybe this tutorial would help you: https://realpython.com/python-send-email/.

Good luck with your project and let me know if you have any difficulties.

folfcoder avatar Jul 25 '21 14:07 folfcoder

Again Great. Thank you so much :)

shanmugam023 avatar Jul 25 '21 14:07 shanmugam023

Sorry i couldn't find the "indicators" Varible could you share steps to access the indicators dictionay.

shanmugam023 avatar Jul 25 '21 14:07 shanmugam023

Sorry sorry i got it Thank you so much:)

shanmugam023 avatar Jul 25 '21 15:07 shanmugam023

Hi Brian,

Sorry for distrbing some times i am facing below error

Traceback (most recent call last): File "1DAY_Chart.py", line 8, in analysis = get_multiple_analysis(screener="crypto", interval=Interval.INTERVAL_1_DAY, symbols=symbols) File "/usr/local/lib/python3.6/site-packages/tradingview_ta/main.py", line 363, in get_multiple_analysis final[analysis["s"]] = calculate(indicators=indicators, indicators_key=indicators_key, screener=screener, symbol=analysis["s"].split(":")[1], exchange=analysis["s"].split(":")[0], interval=interval) File "/usr/local/lib/python3.6/site-packages/tradingview_ta/main.py", line 90, in calculate recommend_oscillators = Compute.Recommend(indicators[0]) File "/usr/local/lib/python3.6/site-packages/tradingview_ta/technicals.py", line 213, in Recommend if value >= -1 and value < -.5: TypeError: '>=' not supported between instances of 'NoneType' and 'int

Below is the code

#!/usr/bin/python3.6 x=' '; from tradingview_ta import * with open("1DAY_Coin.txt", "r") as f: # Read the file, split it into a list, delete empty strings. symbols = [x for x in f.read().splitlines() if x != ""]

analysis = get_multiple_analysis(screener="crypto", interval=Interval.INTERVAL_1_DAY, symbols=symbols)

for key, value in analysis.items(): rsi = value.indicators["RSI"] stoch_rsi = value.indicators["Stoch.RSI.K"] ema20 = value.indicators["EMA20"] ema50 = value.indicators["EMA50"] ema200 = value.indicators["EMA200"] if value.indicators["EMA20"] > value.indicators["EMA50"]: # Send email here print('COIN NAME:', key) print('RSI VALUES:', rsi) print('STOCK RSI VALUES:', stoch_rsi) print('EMA20 VALUES is:', ema20) print('EMA50 VALUES IS:', ema50) print('1HOURS BUY ALERT!!!!') print(x)

shanmugam023 avatar Jul 31 '21 04:07 shanmugam023

Hi @shanmugam023,

Usually, TypeError: '>=' not supported between instances of 'NoneType' and 'int is caused by certain symbols (see #55). Can you reply with the 1DAY_Coin.txt file?

folfcoder avatar Jul 31 '21 04:07 folfcoder

1DAY_Coin.txt

Yes sure. Kindly check from the attachment

shanmugam023 avatar Jul 31 '21 05:07 shanmugam023

I checked the file, and this issue is similar to #55. This is caused by BINANCE:DEXEUSDT, which does not have a 1 day analysis.

image

You can remove that line or update to tradingview-ta v3.2.7. I highly recommend updating to v3.2.7 using pip install -U tradingview-ta. However you still won't get that analysis.

Also, I noticed that some coins does not have the EMA50, which caused your code to crash:

image

I formatted and fixed your code to support v3.2.7 and to avoid the crash:

from tradingview_ta import *
with open("1DAY_Coin.txt", "r") as f:
    # Read the file, split it into a list, delete empty strings.
    symbols = [x for x in f.read().splitlines() if x != ""]

analysis = get_multiple_analysis(screener="crypto", interval=Interval.INTERVAL_1_DAY, symbols=symbols)

for key, value in analysis.items():
    if value != None:
        rsi = value.indicators["RSI"]
        stoch_rsi = value.indicators["Stoch.RSI.K"]
        ema20 = value.indicators["EMA20"]
        ema50 = value.indicators["EMA50"]
        ema200 = value.indicators["EMA200"]
        if ema20 and ema50:
            if value.indicators["EMA20"] > value.indicators["EMA50"]:
                # Send email here
                print('COIN NAME:', key)
                print('RSI VALUES:', rsi)
                print('STOCK RSI VALUES:', stoch_rsi)
                print('EMA20 VALUES is:', ema20)
                print('EMA50 VALUES IS:', ema50)
                print('1HOURS BUY ALERT!!!!')
                print()

P.S. You don't need the x variable, so I removed it.

folfcoder avatar Jul 31 '21 05:07 folfcoder

Hi Brian,

Thank you so much. It's working after update the package :)

shanmugam023 avatar Jul 31 '21 05:07 shanmugam023