How did I do ? (is there a reward
)
df <- data.frame(
row = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L),
Open = c(
1.5972, 1.5975, 1.5972, 1.5984,
1.5988, 1.5996, 1.5983, 1.5974, 1.5977, 1.5997, 1.6019,
1.6041
),
High = c(
1.5982, 1.5979, 1.5994, 1.5999,
1.5999, 1.6, 1.5985, 1.5981, 1.5998, 1.602, 1.6047,
1.6047
),
Low = c(
1.5964, 1.5959, 1.5971, 1.5981,
1.5983, 1.5979, 1.5962, 1.5962, 1.597, 1.5992, 1.6014,
1.6005
),
Close = c(
1.5978, 1.5973, 1.5982, 1.5986,
1.5994, 1.5982, 1.5972, 1.5975, 1.5997, 1.6014, 1.6041,
1.6012
)
)
df$buy_price_origin_row <- NA
df$buy_price <- NA
df$sell_high_price_row <- NA
df$pos_difference <- NA
processprices <- function(df) {
first <- TRUE
for (row in 1:(nrow(df) - 1)) {
if (first) {
buy_price_candidate <- df[row, "Open"]
first <- FALSE
}
for (innerloop in (row + 1):(nrow(df) - 1)) {
if (df[innerloop, "High"] - buy_price_candidate > 0.001) {
df[row, "buy_price"] <- buy_price_candidate
df[row, "buy_price_origin_row"] <- row
df[row, "sell_high_price_row"] <- innerloop
df[row, "sell_high_price"] <- df[innerloop, "High"]
df[row, "pos_difference"] <- df[innerloop, "High"] - buy_price_candidate
first <- TRUE
break
}
}
}
return(df)
}
processprices(df)