Hello,
I am programming with Python the MACD and EMA 50 Strategy. I have already a CSV File where i have stored over 12.000 Stocks which i can use to test the code. My Problem is that i am new to Python and i need help to programm this Strategy.
The Strategy: When the Graphline is over the EMA 50 line and the MACD slower line crosses the MACD faster line over the 75 mark border in the MACD histogramm the stock should trigger buy. It should sell again after 10% win or 5% loss.
When the Graphline is under the EMA 50 line and the MACD faster line crosses the MACD lower line under the 25 mark border in the MACD histogram the stock should trigger sell. It should sell again after 10% win or 5% loss.
The result should be printed
This is my code so far:
from os import listdir
import pandas
import talib
path = "/Path/"
files = listdir(path)
data = pandas.read_csv(path + files[6])
upper, middle, lower = talib.BBANDS(data['Close'], matype=talib.MA_Type.T3)
data['UpperBBand'] = upper
data = data.dropna()
data = data.reset_index(drop=True)
data['Buy'] = (data["Close"] > data['UpperBBand']).astype('int')
data['Price_5_Days'] = data['Close'].shift(periods=-4)
data['Return'] = (data['Price_5_Days'] - data['Close']) / data['Close']
data['Yearly_Return'] = data['Return'] / 5 * 250
trades = data[data['Buy'] == 1]
trades['Yearly_Return'].describe()
I am programming with Python the MACD and EMA 50 Strategy. I have already a CSV File where i have stored over 12.000 Stocks which i can use to test the code. My Problem is that i am new to Python and i need help to programm this Strategy.
The Strategy: When the Graphline is over the EMA 50 line and the MACD slower line crosses the MACD faster line over the 75 mark border in the MACD histogramm the stock should trigger buy. It should sell again after 10% win or 5% loss.
When the Graphline is under the EMA 50 line and the MACD faster line crosses the MACD lower line under the 25 mark border in the MACD histogram the stock should trigger sell. It should sell again after 10% win or 5% loss.
The result should be printed
This is my code so far:
from os import listdir
import pandas
import talib
path = "/Path/"
files = listdir(path)
data = pandas.read_csv(path + files[6])
upper, middle, lower = talib.BBANDS(data['Close'], matype=talib.MA_Type.T3)
data['UpperBBand'] = upper
data = data.dropna()
data = data.reset_index(drop=True)
data['Buy'] = (data["Close"] > data['UpperBBand']).astype('int')
data['Price_5_Days'] = data['Close'].shift(periods=-4)
data['Return'] = (data['Price_5_Days'] - data['Close']) / data['Close']
data['Yearly_Return'] = data['Return'] / 5 * 250
trades = data[data['Buy'] == 1]
trades['Yearly_Return'].describe()