Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get History tab data #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added MT5 files/MT5R.ex5
Binary file not shown.
Binary file added MT5 files/MT5R.mq5
Binary file not shown.
40 changes: 40 additions & 0 deletions R/Source_MT5.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,46 @@ MT5.AccountInfo <- function()
return(sRequest)
}


#' MT5GetClosedEntries
#' @description get the list of closed entries from the MT5 History tab
#' @details The Package MT5R does not include the functionality to extract the history data from Metatrader5. this function provides so.
#'
#' @export
#'
#' @examples
#' MT5.GetClosedEntries ()
MT5.GetClosedEntries <- function()
{
sRequest <- MT5.Connect("H0")
df_final <- data.frame(sSymbol = character(),
PositionID = integer(),
iCmd = integer(),
fVolume = numeric(),
fProfit = numeric(),
Ticket = integer(),
Date = character())
if (is.null(sRequest)) {
return(df_final)
}
for (i in seq_len(base::length(sRequest))) {
Linha <- utils::read.table(text = sRequest[i], sep = "?")
df <- data.frame(sSymbol = as.character(Linha[1][[1]]),
PositionID = as.integer(Linha[2][[1]]),
iCmd = as.integer(Linha[3][[1]]),
fVolume = as.numeric(Linha[4][[1]]),
fProfit = as.numeric(Linha[5][[1]]),
Ticket = as.numeric(Linha[6][[1]]),
Date = as.character(Linha[7][[1]]))
df_final <- rbind(df_final, df)
}
if (base::dim(df_final)[1] > 0) {
df_final$sSymbol <- as.character(df_final$sSymbol)
}
return(df_final)
}


#' Order book
#'
#' @description
Expand Down