24 lines
633 B
C++
24 lines
633 B
C++
#include <iterator>
|
|
#include "decider.h"
|
|
|
|
macd_decider::macd_decider(std::size_t limit)
|
|
: prices(limit, .0), macd(limit, .0), signal(limit, .0), limit(limit) {}
|
|
|
|
void macd_decider::process(double price)
|
|
{
|
|
count++;
|
|
prices.add(price);
|
|
macd.add(ema<double>(prices.begin(), prices.begin() + 12) - ema<double>(prices.begin(), prices.begin() + 26));
|
|
signal.add(ema<double>(macd.begin(), macd.begin() + 9));
|
|
}
|
|
|
|
void macd_decider::reset(double price)
|
|
{
|
|
prices = buffer<double>(limit, price);
|
|
signal = buffer<double>(limit, .0);
|
|
macd = buffer<double>(limit, .0);
|
|
|
|
count = 0;
|
|
start_price = price;
|
|
}
|