diff --git a/src/ichimoku-cloud.cpp b/src/ichimoku-cloud.cpp index 34e9fc0..9c2ca10 100644 --- a/src/ichimoku-cloud.cpp +++ b/src/ichimoku-cloud.cpp @@ -76,8 +76,6 @@ Rcpp::List ichimoku_cloud( // ----- -using namespace Rcpp; - // Helper function to calculate the middle point of high and low over a period std::vector calculate_midpoint(const std::vector& high, const std::vector& low, int period) { std::vector result(high.size(), NA_REAL); @@ -92,7 +90,11 @@ std::vector calculate_midpoint(const std::vector& high, const st // Helper function to shift a vector forward (into the future) std::vector shift_vector(const std::vector& vec, int shift) { std::vector result(vec.size(), NA_REAL); - std::copy(vec.begin(), vec.end() - shift, result.begin() + shift); + if (shift >= 0) { + std::copy(vec.begin(), vec.end() - shift, result.begin() + shift); + } else { + std::copy(vec.begin() - shift, vec.end(), result.begin()); + } return result; }