61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <algorithm>
|
|
#include <string>
|
|
|
|
#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.add_params({ "o", "output" });
|
|
|
|
args.parse(argc, argv);
|
|
|
|
unsigned low, high, s;
|
|
std::string output;
|
|
|
|
args({"l", "low"}, 12) >> low;
|
|
args({"h", "high"}, 26) >> high;
|
|
args({"s", "signal"}, 9) >> s;
|
|
args({"o", "output"}, "./intersections.csv") >> output;
|
|
|
|
double price;
|
|
std::cin >> price;
|
|
|
|
unsigned max = std::max({ low, high, s });
|
|
buffer<double> prices(max, price);
|
|
buffer<double> macd(max);
|
|
buffer<double> signal(max);
|
|
|
|
std::cout << "no,price,macd,signal,delta" << std::endl;
|
|
|
|
std::ofstream intersections(output);
|
|
intersections << "no,x,action" << std::endl;
|
|
int i = 0, j = 0;
|
|
do {
|
|
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));
|
|
|
|
if (sign(macd[0] - signal[0]) != sign(macd[1] - signal[1])) {
|
|
// zamiana
|
|
double x1 = i+1, x2 = i;
|
|
double y1 = macd[1], y2 = macd[0];
|
|
double y3 = signal[1], y4 = signal[0];
|
|
|
|
double a = abs(y2 - y1), b = abs(y4 - y3);
|
|
double x = (a * x2 + b * x1) / (a + b);
|
|
intersections << ++j << "," << x << "," << (macd[0] - signal[0] > 0 ? "buy" : "sell") << std::endl;
|
|
}
|
|
|
|
std::cout << ++i << "," << prices[0] << "," << macd[0] << "," << signal[0] << "," << prices[0] - prices[1] << std::endl;
|
|
} while(std::cin >> price);
|
|
}
|
|
|