Hi Dmitriy
I install all libraries but when i try to run this python rogram i get this error:
runfile('C:/Users/rogerio/ título1.py', wdir='C:/Users/rogerio')
Traceback (most recent call last):
File "C:\Users\rogerio\sem título1.py", line 20, in <module>
rsi=tl.RSI(rates['close'])
TypeError: 'NoneType' object is not subscriptable
I am using this source code
# -------------------------------------------------------#
# Data clustering model #
# -------------------------------------------------------#
# Import Libraries
import numpy as np
import matplotlib.pyplot as plt
import MetaTrader5 as mt5
from talib import abstract as tl
import sklearn.cluster as cluster
from datetime import datetime as dt
# Connect to the MetaTrader 5 terminal
if not mt5.initialize():
print("initialize() failed, error code =",mt5.last_error())
quit()
# Downloading quotes
rates=mt5.copy_rates_range('EURUSD',mt5.TIMEFRAME_H1,dt(2006,1,1),dt(2022,1,1))
mt5.shutdown()
# Calculate indicator values
rsi=tl.RSI(rates['close'])
cci=tl.CCI(rates['high'],rates['low'],rates['close'])
macd,macdsignal,macdhist=tl.MACD(rates['close'])
# Group the training sample
data=np.array([rates['close']-rates['open'],rates['high']-rates['close'],rates['close']-rates['low'],rsi,cci,macd,macdsignal,macdhist]).T
s=data.shape[0]
data=np.hstack([data[40+k:s-20+k] for k in range(0,20)])
# Perform clustering with a different number of clusters
R=range(50,1000,50)
KM = (cluster.KMeans(n_clusters=k).fit(data) for k in R)
distance=(k.transform(data) for k in KM)
dist = (np.min(D, axis=1) for D in distance)
avgWithinSS = [sum(d) / data.shape[0] for d in dist]
# Plotting the model training results
plt.plot(R, avgWithinSS)
plt.xlabel('$Clasters$')
plt.title('Loss dynamic')
# Display generated graphs
plt.show()
Thans for help
Rogerio
Hi Dmitriy
I install all libraries but when i try to run this python rogram i get this error:
runfile('C:/Users/rogerio/ título1.py', wdir='C:/Users/rogerio')
Traceback (most recent call last):
File "C:\Users\rogerio\sem título1.py", line 20, in <module>
rsi=tl.RSI(rates['close'])
TypeError: 'NoneType' object is not subscriptable
I am using this source code
# -------------------------------------------------------#
# Data clustering model #
# -------------------------------------------------------#
# Import Libraries
import numpy as np
import matplotlib.pyplot as plt
import MetaTrader5 as mt5
from talib import abstract as tl
import sklearn.cluster as cluster
from datetime import datetime as dt
# Connect to the MetaTrader 5 terminal
if not mt5.initialize():
print("initialize() failed, error code =",mt5.last_error())
quit()
# Downloading quotes
rates=mt5.copy_rates_range('EURUSD',mt5.TIMEFRAME_H1,dt(2006,1,1),dt(2022,1,1))
mt5.shutdown()
# Calculate indicator values
rsi=tl.RSI(rates['close'])
cci=tl.CCI(rates['high'],rates['low'],rates['close'])
macd,macdsignal,macdhist=tl.MACD(rates['close'])
# Group the training sample
data=np.array([rates['close']-rates['open'],rates['high']-rates['close'],rates['close']-rates['low'],rsi,cci,macd,macdsignal,macdhist]).T
s=data.shape[0]
data=np.hstack([data[40+k:s-20+k] for k in range(0,20)])
# Perform clustering with a different number of clusters
R=range(50,1000,50)
KM = (cluster.KMeans(n_clusters=k).fit(data) for k in R)
distance=(k.transform(data) for k in KM)
dist = (np.min(D, axis=1) for D in distance)
avgWithinSS = [sum(d) / data.shape[0] for d in dist]
# Plotting the model training results
plt.plot(R, avgWithinSS)
plt.xlabel('$Clasters$')
plt.title('Loss dynamic')
# Display generated graphs
plt.show()
Thans for help
Rogerio
Hello Rogerio.
Do you have install TA-Lib : Technical Analysis Library?
- TA-LIB.org
- ta-lib.org

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Neural networks made easy (Part 14): Data clustering has been published:
It has been more than a year since I published my last article. This is quite a lot time to revise ideas and to develop new approaches. In the new article, I would like to divert from the previously used supervised learning method. This time we will dip into unsupervised learning algorithms. In particular, we will consider one of the clustering algorithms—k-means.
As you can see, unsupervised learning algorithms can be used to solve various problems. But how can they be used in trading? Let's think. Graphical analysis methods almost always involve certain chart patterns: Double Top / Double Bottom, Head and Shoulders, Flag, various harmonic patterns, etc. Furthermore, there are a lot of smaller patterns consisting of 1-3 candlesticks. But when we try to describe a particular pattern in mathematical language, have to deal with a large number of conventions and tolerances. This complicates their use in algorithmic trading. Even when a human trader determines the patterns, there is a lot of subjectivity. That is why, when analyzing the same chart, different traders find identify patterns on it, which often have opposite directed predictive movements. Well, perhaps this is the underlying rule of trading as a whole. Some make profit, others lose. In the trading process, no new commodity-material values are created, while the money supply remains unchanged. It only moves from one wallet to another. So, how can we avoid loss?
Let's once again take a look at the chart patterns mentioned above. Yes, they all have their variations. But at the same time, each pattern has its own specific structure, which identifies it against the general price movement chart. So, what if we use unsupervised data clustering algorithms to let the model identify all possible variations in the data over a certain time period. Since we use unsupervised learning, there is no need to label the data, as well as the time period can be quite large. However, do not forget that an increase in the history time period increases model training costs.
Author: Dmitriy Gizlyk