From 8389773f7753137fe18a86260eb61236a25f38e2 Mon Sep 17 00:00:00 2001 From: fasiondog Date: Tue, 30 Nov 2021 01:28:43 +0800 Subject: [PATCH] fixed LLV/LLVBARS/HHVBARS --- hikyuu_cpp/hikyuu/indicator/imp/IHhvbars.cpp | 29 +++++++++---------- hikyuu_cpp/hikyuu/indicator/imp/IHighLine.cpp | 2 +- hikyuu_cpp/hikyuu/indicator/imp/ILowLine.cpp | 24 +++++++-------- .../hikyuu/indicator/imp/ILowLineBars.cpp | 28 ++++++++---------- xmake.lua | 3 ++ 5 files changed, 40 insertions(+), 46 deletions(-) diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IHhvbars.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IHhvbars.cpp index 487412662..afb46e3d3 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IHhvbars.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IHhvbars.cpp @@ -63,29 +63,26 @@ void IHhvbars::_calculate(const Indicator& ind) { _set(i - pre_pos, i); } - for (size_t i = start_pos; i < total - 1; i++) { + for (size_t i = start_pos; i < total; i++) { size_t j = i + 1 - n; if (pre_pos < j) { pre_pos = j; max = ind[j]; - } - if (ind[i] >= max) { - max = ind[i]; - pre_pos = i; - } - _set(i - pre_pos, i); - } + for (size_t j = pre_pos + 1; j <= i; j++) { + if (ind[j] >= max) { + max = ind[j]; + pre_pos = j; + } + } - start_pos = total - n; - max = ind[start_pos]; - pre_pos = start_pos; - for (size_t i = start_pos; i < total; i++) { - if (ind[i] >= max) { - pre_pos = i; - max = ind[i]; + } else { + if (ind[i] >= max) { + max = ind[i]; + pre_pos = i; + } } + _set(i - pre_pos, i); } - _set(total - pre_pos - 1, total - 1); } Indicator HKU_API HHVBARS(int n) { diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IHighLine.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IHighLine.cpp index 2d6623ef8..cfc6b1773 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IHighLine.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IHighLine.cpp @@ -71,7 +71,7 @@ void IHighLine::_calculate(const Indicator& ind) { pre_pos = j; max = ind[j]; for (size_t j = pre_pos + 1; j <= i; j++) { - if (ind[j] > max) { + if (ind[j] >= max) { max = ind[j]; pre_pos = j; } diff --git a/hikyuu_cpp/hikyuu/indicator/imp/ILowLine.cpp b/hikyuu_cpp/hikyuu/indicator/imp/ILowLine.cpp index 14613c474..48488e94b 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/ILowLine.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/ILowLine.cpp @@ -70,22 +70,20 @@ void ILowLine::_calculate(const Indicator& ind) { if (pre_pos < j) { pre_pos = j; min = ind[j]; - } - if (ind[i] <= min) { - min = ind[i]; - pre_pos = i; + for (size_t j = pre_pos + 1; j <= i; j++) { + if (ind[j] <= min) { + min = ind[j]; + pre_pos = j; + } + } + } else { + if (ind[i] <= min) { + min = ind[i]; + pre_pos = i; + } } _set(min, i); } - - startPos = total - n; - min = ind[startPos]; - for (size_t i = startPos; i < total; i++) { - if (ind[i] <= min) { - min = ind[i]; - } - } - _set(min, total - 1); } Indicator HKU_API LLV(int n = 20) { diff --git a/hikyuu_cpp/hikyuu/indicator/imp/ILowLineBars.cpp b/hikyuu_cpp/hikyuu/indicator/imp/ILowLineBars.cpp index 346c78b60..bfcccdc2d 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/ILowLineBars.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/ILowLineBars.cpp @@ -63,29 +63,25 @@ void ILowLineBars::_calculate(const Indicator& ind) { _set(i - pre_pos, i); } - for (size_t i = start_pos; i < total - 1; i++) { + for (size_t i = start_pos; i < total; i++) { size_t j = i + 1 - n; if (pre_pos < j) { pre_pos = j; min = ind[j]; - } - if (ind[i] <= min) { - min = ind[i]; - pre_pos = i; + for (size_t j = pre_pos + 1; j <= i; j++) { + if (ind[j] <= min) { + min = ind[j]; + pre_pos = j; + } + } + } else { + if (ind[i] <= min) { + min = ind[i]; + pre_pos = i; + } } _set(i - pre_pos, i); } - - start_pos = total - n; - min = ind[start_pos]; - pre_pos = start_pos; - for (size_t i = start_pos; i < total; i++) { - if (ind[i] <= min) { - pre_pos = i; - min = ind[i]; - } - } - _set(total - pre_pos - 1, total - 1); } Indicator HKU_API LLVBARS(int n) { diff --git a/xmake.lua b/xmake.lua index edf590319..6a06fe3b7 100644 --- a/xmake.lua +++ b/xmake.lua @@ -4,6 +4,9 @@ set_xmakever("2.5.4") set_project("hikyuu") add_rules("mode.debug", "mode.release") +if not is_plat("windows") then + add_rules("mode.coverage") +end -- version set_version("1.1.9", {build="%Y%m%d%H%M"})