MACD计算代码
参数设置为12,23.9
struct Macd
{
Macd():m12(0.0f),m26(0.0f),diff(0.0f),dea(0.0f),bar(0.0f),index(-1){}
float m12;
float m26;
float diff;
float dea;
float bar;
int index;
void update(float value)
{
index ++;
if(index == 0)
{
m12 = value;
m26 = value;
}
else
{
m12 = m12 + (value - m12) * 2.0f/13.0f;
m26 = m26 + (value - m26) * 2.0f/27.0f;
diff = m12 - m26;
if(index == 1)
dea = 0.2*diff;
else
dea = dea*0.8 + diff*0.2;
bar = 2 * (-dea + diff);
std::cout<<diff<<" "<<dea<<" "<<bar<<std::endl;
}
}
};
炒股的同学可以加入蜗牛选股群:297919841 验证码为来自博客园