Skip to content

Instantly share code, notes, and snippets.

View yongghongg's full-sized avatar
🏠
Working from home

Yonghong Tan yongghongg

🏠
Working from home
View GitHub Profile
Trade Win Loss Success Rate(%)
CDL_HIKKAKEMOD 1115 532 583 47.71
CDL_BREAKAWAY 169 80 89 47.34
CDL_3WHITESOLDIERS 1500 693 807 46.20
CDL_INVERTEDHAMMER 23128 10636 12492 45.99
CDL_STICKSANDWICH 3334 1526 1808 45.77
CDL_GAPSIDESIDEWHITE 4837 2189 2648 45.26
CDL_DOJISTAR 18886 8534 10352 45.19
CDL_3LINESTRIKE 1194 539 655 45.14
CDL_GRAVESTONEDOJI 22785 10228 12557 44.89
Trade Win Loss Success Rate(%)
CDL_HIKKAKEMOD 1115 532 583 47.71300448430493
CDL_BREAKAWAY 169 80 89 47.337278106508876
CDL_3WHITESOLDIERS 1500 693 807 46.2
CDL_INVERTEDHAMMER 23128 10636 12492 45.98754756139744
CDL_STICKSANDWICH 3334 1526 1808 45.770845830833835
CDL_GAPSIDESIDEWHITE 4837 2189 2648 45.255323547653504
CDL_DOJISTAR 18886 8534 10352 45.18691093932013
CDL_3LINESTRIKE 1194 539 655 45.142378559463985
CDL_GRAVESTONEDOJI 22785 10228 12557 44.88918147904323
final_result_df = pd.DataFrame()
# read from local data
for symbol in os.listdir('price_data/'):
df = pd.read_csv(f'price_data/{symbol}')
if df.empty:
continue
df.replace('', np.nan, inplace=True)
df.dropna(inplace=True)
df.ta.cdl_pattern(name="all", append=True)
import pandas as pd
import numpy as np
from datetime import datetime
import yfinance as yf
import math
import matplotlib.pyplot as plt
def Supertrend(df, atr_period, multiplier):
high = df['High']
# we are using mplfinance to help us visualize the indicator
import mplfinance as mpf
# to make the visualization better by only taking the last 100 rows of data
df = df[-100:]
# extract only ['Open', 'High', 'Close', 'Low'] from df
ohcl = df[['Open', 'High', 'Close', 'Low']]
# add colors for the 'value bar'
# import required libraries
import pandas as pd
import yfinance as yf
import numpy as np
import math
# get stock prices
df = yf.download('AAPL', start='2020-01-01', threads= False)
# parameter setup
import requests
from bs4 import BeautifulSoup
def get_stock_list():
# this is the website we're going to scrape from
url = "https://www.malaysiastock.biz/Stock-Screener.aspx"
response = requests.get(url, headers={'User-Agent':'test'})
soup = BeautifulSoup(response.content, "html.parser")
table = soup.find(id = "MainContent2_tbAllStock")
# return the result (only ticker code) in a list
import email
# you can add this part of code at the end of part 2
# remember: screened_list contains the result of the screening
# configure email and message
msg = email.message_from_string(", ".join(screened_list))
msg['From'] = 'YOUR_EMAIL@gmail.com'
msg['To'] = 'YOUR_EMAIL@gmail.com'
msg['Subject'] = "EMA Bounce Result for Today!"
s = smtplib.SMTP("smtp.gmail.com",587)
import requests
from bs4 import BeautifulSoup
import yfinance as yf
def get_stock_list():
# this is the website we're going to scrape from
url = "https://www.malaysiastock.biz/Stock-Screener.aspx"
response = requests.get(url, headers={'User-Agent':'test'})
soup = BeautifulSoup(response.content, "html.parser")
table = soup.find(id = "MainContent2_tbAllStock")
# function to check for EMA Bounce
def check_bounce_EMA(df):
candle1 = df.iloc[-1]
candle2 = df.iloc[-2]
cond1 = candle1['EMA18'] > candle1['EMA50'] > candle1['EMA100']
cond2 = candle1['STOCH_%K(5,3,3)'] <= 30 or candle1['STOCH_%D(5,3,3)'] <= 30
cond3 = candle2['Low'] < candle2['EMA50'] and \
candle2['Close'] > candle2['EMA50'] and \
candle1['Low'] > candle1 ['EMA50']
return cond1 and cond2 and cond3