40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <algorithm>
|
|
|
|
#include "helpers.h"
|
|
#include "argh.h"
|
|
|
|
int main(int argc, const char* argv[])
|
|
{
|
|
argh::parser args;
|
|
args.add_params({ "l", "low" });
|
|
args.add_params({ "h", "high" });
|
|
args.add_params({ "s", "signal" });
|
|
|
|
args.parse(argc, argv);
|
|
|
|
unsigned low, high, s;
|
|
|
|
args({"l", "low"}, 12) >> low;
|
|
args({"h", "high"}, 26) >> high;
|
|
args({"s", "signal"}, 9) >> s;
|
|
|
|
unsigned max = std::max({ low, high, s });
|
|
buffer<double> prices(max);
|
|
buffer<double> macd(max);
|
|
buffer<double> signal(max);
|
|
|
|
|
|
double price;
|
|
std::cout << "no,price,macd,signal,delta" << std::endl;
|
|
for (int i = 0; std::cin >> price; i++) {
|
|
prices.add(price);
|
|
double value = ema<double>(prices.begin(), prices.begin() + low) - ema<double>(prices.begin(), prices.begin() + high);
|
|
macd.add(value);
|
|
signal.add(ema<double>(macd.begin(), macd.begin() + s));
|
|
|
|
std::cout << i << "," << prices[0] << "," << macd[0] << "," << signal[0] << "," << prices[1] - prices[0] << std::endl;
|
|
}
|
|
}
|
|
|