From 547d779aea6d6bbe1593834365480d7264c16fb0 Mon Sep 17 00:00:00 2001 From: dereckmezquita Date: Mon, 8 Jul 2024 16:44:49 -0500 Subject: [PATCH] Need to revise so it predicts into the future. --- src/ichimoku-cloud.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; }