MACD data problems

I don’t know the reason but there is an error appearing while I play my code in R.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># Pobieranie danych
filename <- "https://stooq.pl/q/d/l/?s=eat&d1=20190101&d2=202312310&i=d"
amrest <- read.csv(filename)
# Konwersja daty
amrest$Data <- as.Date(amrest$Data)
# Sortowanie danych po dacie
amrest <- amrest[order(amrest$Data),]
# Wybieranie odpowiednich kolumn (bez wolumenu)
amrest <- amrest[,c(1:5)]
colnames(amrest) <- c("Date", "Open", "High", "Low", "Close")
# Zmiana na format xts
amrest_xts <- xts(amrest[,-1], order.by = amrest$Date)
# Sprawdzanie, czy xts jest prawidłowo utworzony
print(head(amrest_xts))
print(tail(amrest_xts))
# Obliczanie MACD
macd_data <- MACD(Cl(amrest_xts), nFast=12, nSlow=26, nSig=9, maType="EMA")
# Sprawdzanie, czy MACD został poprawnie obliczony
print(head(macd_data))
print(tail(macd_data))
# Łączenie danych z MACD
amrest_xts <- merge(amrest_xts, macd_data)
# Generowanie sygnałów kupna i sprzedaży
signal <- Lag(ifelse(amrest_xts$macd > amrest_xts$signal, 1, -1))
signal[is.na(signal)] <- 0
# Sygnały kupna i sprzedaży na przecięciach
buy_signal <- ifelse(signal == 1 & Lag(signal) == -1, 1, 0)
sell_signal <- ifelse(signal == -1 & Lag(signal) == 1, 1, 0)
# Dodawanie sygnałów do danych xts
amrest_xts$buy_signal <- buy_signal
amrest_xts$sell_signal <- sell_signal
# Wybieranie ostatnich 100 obserwacji do wykresu świecowego
amrest_xts_short <- tail(amrest_xts, 100)
# Wykres świecowy z zaznaczonymi sygnałami
candleChart(amrest_xts_short, multi.col=TRUE, theme='white', subset='last 3 months', TA=NULL)
addMACD()
# Dodawanie sygnałów na wykresie
addTA(amrest_xts_short$buy_signal, col='green', type='p', pch=24, cex=1.5, on=1)
addTA(amrest_xts_short$sell_signal, col='red', type='p', pch=25, cex=1.5, on=1)
# Dodanie pogrubionego tytułu
mtext("Amrest - MACD Strategy", side=3, line=0.9, cex=1.25, font=2)
# Wykres z Simple Moving Average
chartSeries(amrest_xts_short, theme='white', TA="addSMA()", subset='last 3 months')
mtext("Amrest - SMA", side=3, line=0.9, cex=1.25, font=2)
</code>
<code># Pobieranie danych filename <- "https://stooq.pl/q/d/l/?s=eat&d1=20190101&d2=202312310&i=d" amrest <- read.csv(filename) # Konwersja daty amrest$Data <- as.Date(amrest$Data) # Sortowanie danych po dacie amrest <- amrest[order(amrest$Data),] # Wybieranie odpowiednich kolumn (bez wolumenu) amrest <- amrest[,c(1:5)] colnames(amrest) <- c("Date", "Open", "High", "Low", "Close") # Zmiana na format xts amrest_xts <- xts(amrest[,-1], order.by = amrest$Date) # Sprawdzanie, czy xts jest prawidłowo utworzony print(head(amrest_xts)) print(tail(amrest_xts)) # Obliczanie MACD macd_data <- MACD(Cl(amrest_xts), nFast=12, nSlow=26, nSig=9, maType="EMA") # Sprawdzanie, czy MACD został poprawnie obliczony print(head(macd_data)) print(tail(macd_data)) # Łączenie danych z MACD amrest_xts <- merge(amrest_xts, macd_data) # Generowanie sygnałów kupna i sprzedaży signal <- Lag(ifelse(amrest_xts$macd > amrest_xts$signal, 1, -1)) signal[is.na(signal)] <- 0 # Sygnały kupna i sprzedaży na przecięciach buy_signal <- ifelse(signal == 1 & Lag(signal) == -1, 1, 0) sell_signal <- ifelse(signal == -1 & Lag(signal) == 1, 1, 0) # Dodawanie sygnałów do danych xts amrest_xts$buy_signal <- buy_signal amrest_xts$sell_signal <- sell_signal # Wybieranie ostatnich 100 obserwacji do wykresu świecowego amrest_xts_short <- tail(amrest_xts, 100) # Wykres świecowy z zaznaczonymi sygnałami candleChart(amrest_xts_short, multi.col=TRUE, theme='white', subset='last 3 months', TA=NULL) addMACD() # Dodawanie sygnałów na wykresie addTA(amrest_xts_short$buy_signal, col='green', type='p', pch=24, cex=1.5, on=1) addTA(amrest_xts_short$sell_signal, col='red', type='p', pch=25, cex=1.5, on=1) # Dodanie pogrubionego tytułu mtext("Amrest - MACD Strategy", side=3, line=0.9, cex=1.25, font=2) # Wykres z Simple Moving Average chartSeries(amrest_xts_short, theme='white', TA="addSMA()", subset='last 3 months') mtext("Amrest - SMA", side=3, line=0.9, cex=1.25, font=2) </code>
# Pobieranie danych
filename <- "https://stooq.pl/q/d/l/?s=eat&d1=20190101&d2=202312310&i=d"
amrest <- read.csv(filename)

# Konwersja daty
amrest$Data <- as.Date(amrest$Data)

# Sortowanie danych po dacie
amrest <- amrest[order(amrest$Data),]

# Wybieranie odpowiednich kolumn (bez wolumenu)
amrest <- amrest[,c(1:5)] 
colnames(amrest) <- c("Date", "Open", "High", "Low", "Close")

# Zmiana na format xts
amrest_xts <- xts(amrest[,-1], order.by = amrest$Date)

# Sprawdzanie, czy xts jest prawidłowo utworzony
print(head(amrest_xts))
print(tail(amrest_xts))

# Obliczanie MACD
macd_data <- MACD(Cl(amrest_xts), nFast=12, nSlow=26, nSig=9, maType="EMA")

# Sprawdzanie, czy MACD został poprawnie obliczony
print(head(macd_data))
print(tail(macd_data))

# Łączenie danych z MACD
amrest_xts <- merge(amrest_xts, macd_data)

# Generowanie sygnałów kupna i sprzedaży
signal <- Lag(ifelse(amrest_xts$macd > amrest_xts$signal, 1, -1))
signal[is.na(signal)] <- 0

# Sygnały kupna i sprzedaży na przecięciach
buy_signal <- ifelse(signal == 1 & Lag(signal) == -1, 1, 0)
sell_signal <- ifelse(signal == -1 & Lag(signal) == 1, 1, 0)

# Dodawanie sygnałów do danych xts
amrest_xts$buy_signal <- buy_signal
amrest_xts$sell_signal <- sell_signal

# Wybieranie ostatnich 100 obserwacji do wykresu świecowego
amrest_xts_short <- tail(amrest_xts, 100)

# Wykres świecowy z zaznaczonymi sygnałami
candleChart(amrest_xts_short, multi.col=TRUE, theme='white', subset='last 3 months', TA=NULL)
addMACD()

# Dodawanie sygnałów na wykresie
addTA(amrest_xts_short$buy_signal, col='green', type='p', pch=24, cex=1.5, on=1)
addTA(amrest_xts_short$sell_signal, col='red', type='p', pch=25, cex=1.5, on=1)

# Dodanie pogrubionego tytułu
mtext("Amrest - MACD Strategy", side=3, line=0.9, cex=1.25, font=2)

# Wykres z Simple Moving Average
chartSeries(amrest_xts_short, theme='white', TA="addSMA()", subset='last 3 months')
mtext("Amrest - SMA", side=3, line=0.9, cex=1.25, font=2)

The error is

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Error in seq.default(x@yrange[1], x@yrange[2], length.out = length(x.range)) :
'from' must be a finite number
In addition: Warning messages:
1: In min(x[, 1]) : no non-missing arguments to min; returning Inf
2: In max(x[, 1]) : no non-missing arguments to max; returning -Inf
3: In periodicity(x) : can not calculate periodicity of empty object
4: In periodicity(x) : can not calculate periodicity of empty object
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -In
</code>
<code>Error in seq.default(x@yrange[1], x@yrange[2], length.out = length(x.range)) : 'from' must be a finite number In addition: Warning messages: 1: In min(x[, 1]) : no non-missing arguments to min; returning Inf 2: In max(x[, 1]) : no non-missing arguments to max; returning -Inf 3: In periodicity(x) : can not calculate periodicity of empty object 4: In periodicity(x) : can not calculate periodicity of empty object 5: In min(x) : no non-missing arguments to min; returning Inf 6: In max(x) : no non-missing arguments to max; returning -In </code>
Error in seq.default(x@yrange[1], x@yrange[2], length.out = length(x.range)) : 
  'from' must be a finite number
In addition: Warning messages:
1: In min(x[, 1]) : no non-missing arguments to min; returning Inf
2: In max(x[, 1]) : no non-missing arguments to max; returning -Inf
3: In periodicity(x) : can not calculate periodicity of empty object
4: In periodicity(x) : can not calculate periodicity of empty object
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -In

It is for my project. Actually I study finance and economy, however I have a subject of R coding for the Stock Market analyzing. The task was to analyze the Stock market ticket “Amrest” (Polish market) with MACD (Moving Average Convergence Divergence). I was trying that code generating by AI Chat-GPT3.5, and it was failed.

New contributor

Edward Almanov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật