2019-03-20 02:47:02 +08:00
|
|
|
/*
|
|
|
|
* LowLine.cpp
|
|
|
|
*
|
|
|
|
* Created on: 2016年4月2日
|
|
|
|
* Author: fasiondog
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LowLine.h"
|
|
|
|
|
|
|
|
namespace hku {
|
|
|
|
|
|
|
|
LowLine::LowLine() : IndicatorImp("LLV", 1) {
|
|
|
|
setParam<int>("n", 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
LowLine::~LowLine() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LowLine::check() {
|
|
|
|
int n = getParam<int>("n");
|
|
|
|
if (n < 1) {
|
|
|
|
HKU_ERROR("Invalid param[n] ! (n >= 1) " << m_params
|
|
|
|
<< " [HighLine::calculate]");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LowLine::_calculate(const Indicator& data) {
|
|
|
|
size_t total = data.size();
|
|
|
|
|
|
|
|
int n = getParam<int>("n");
|
|
|
|
|
|
|
|
m_discard = data.discard() + n - 1;
|
2019-03-23 18:54:10 +08:00
|
|
|
if (m_discard >= total) {
|
|
|
|
m_discard = total;
|
|
|
|
return;
|
|
|
|
}
|
2019-03-20 02:47:02 +08:00
|
|
|
|
|
|
|
size_t pos = m_discard + 1 - n;
|
|
|
|
price_t min = 0;
|
|
|
|
for (size_t i = m_discard; i < total; ++i) {
|
|
|
|
size_t j = i + 1 - n;
|
|
|
|
if (pos > j) {
|
|
|
|
j = pos;
|
|
|
|
} else {
|
|
|
|
min = data[j];
|
|
|
|
}
|
|
|
|
for (; j <= i; ++j) {
|
|
|
|
if (data[j] < min) {
|
|
|
|
min = data[j];
|
|
|
|
pos = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_set(min, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Indicator HKU_API LLV(int n =20) {
|
|
|
|
IndicatorImpPtr p = make_shared<LowLine>();
|
|
|
|
p->setParam<int>("n", n);
|
|
|
|
return Indicator(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
Indicator HKU_API LLV(const Indicator& ind, int n =20) {
|
|
|
|
return LLV(n)(ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace hku */
|