Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 If statement implemation
#1
Im trying to implement an if statement that turns the RSI values digits RED when the values is greater or equal to 70 and when its less or equal
30 it turns green. please help me implement this code into my program.

import pandas as pd
import requests
from bs4 import BeautifulSoup


def start():
    indices = ["us-30", "nasdaq-composite", "us-spx-500"]


    def get_rsi(tick):
        page = requests.get('https://www.investing.com/indices/' + tick + "-technical", headers={"user-agent": "Chrome"})
        soup = BeautifulSoup(page.content, 'html.parser')
        summary = soup.find(id="techStudiesInnerWrap")
        name = soup.find("td", class_="first left symbol", string="RSI(14)")
        value = name.find_next('td')
        action = value.find_next('td')
        return  name.text, value.text, action.span.text

    name_list=[]
    rsi_list=[]
    action_list=[]

    for index in indices:
        name,rsi,action = get_rsi(index)
        name_list.append(name)
        rsi_list.append(rsi)
        action_list.append(action)
        
            
    rsi_action = {"INDEX": indices,"NAME":name_list,"RSI":rsi_list,"ACTION":action_list}
    df=pd.DataFrame.from_dict(rsi_action, orient='index')
    print(df.transpose())
    print("--------------------------------------------------------\n")
    print("--------------------------------------------------------\n")
    
while True:
    start()
    time.sleep(2)
Output:
INDEX NAME RSI ACTION 0 us-30 RSI(14) 53.956 Neutral 1 nasdaq-composite RSI(14) 57.699 Buy 2 us-spx-500 RSI(14) 56.590 Buy
buran wrote May-23-2020, 04:00 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
Are you asking how to test the value, or how to print colored text?
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)