Python Forum
Python Talib MACD EMA50 Strategy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Talib MACD EMA50 Strategy
#1
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()
Reply
#2
(Oct-21-2020, 11:51 AM)fatih Wrote: I am programming with Python the MACD and EMA 50 Strategy.

Please, post your code so far. Use python tags. If you get any error - post the full traceback, in error tags. Then ask specific questions.
See BBcode help for more info.

Also, please, don't start multiple threads for same problem.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020