Hello all! I want to create an algorithm that translates data from OHLC to TPO chart. Can anyone help me with an algorithm or pseudocode for this problem?
picture for example:
My data is in this format (start, end, open, high, low, close and volume):
I read them into the vector of structures (My examples will be using c++, but I think they are simple, so you can use your language too and understand what's going on here):
Now that I have the data, I can start translating it into TPO And I had a lot of problems with that. First, what structure to use to store the (for example, daily) graph of TPO. I decided that map<double, string> (the first one is used to store the price, and the second one is used to store the symbols) would work for me. Also the map is very easy to output, here is the output code:
The second problem I encountered was what to do about the price. For example, if the price in the first hour went:
And in the second hour the price went:
How do I combine them?
We know that 219.5 is very close to 219 and they could be combined, how do I solve this? Should I use a quantizer?
Thx!
picture for example:
My data is in this format (start, end, open, high, low, close and volume):
Code:
1443182400,1443185999,239.99,239.99,237.36,237.45,11501
1443186000,1443189599,237.45,237.05,236.08,236.08,22625
1443189600,1443193199,236.08,236.52,236.1,236.34,17434
1443193200,1443196799,236.34,236.13,235.44,235.71,26900
1443196800,1443200399,235.71,236.01,235.46,235.75,29200
I read them into the vector of structures (My examples will be using c++, but I think they are simple, so you can use your language too and understand what's going on here):
Code:
#include <iostream>
#include <chrono>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
using namespace std;
struct TOHCLV
{
string symbol;
double open;
double high;
double low;
double close;
double volume;
};
const vector<string> TPO_Chars = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X" };
vector<TOHCLV> fromSourceDataToVec(string fileName)
{
vector<TOHCLV> data;
string symbol = "BTC";
ifstream inFile(fileName);
if (inFile.is_open())
{
string line;
while (getline(inFile, line))
{
stringstream ss(line);
string timestart, timeend;
string open, high, low, close, volume;
getline(ss, timestart, ',');
getline(ss, timeend, ',');
getline(ss, open, ',');
getline(ss, high, ',');
getline(ss, low, ',');
getline(ss, close, ',');
getline(ss, volume, ',');
TOHCLV nData = { symbol , stod(open), stod(high), stod(low), stod(close), stod(volume) };
data.push_back(nData);
}
}
inFile.close();
return data;
}
Now that I have the data, I can start translating it into TPO And I had a lot of problems with that. First, what structure to use to store the (for example, daily) graph of TPO. I decided that map<double, string> (the first one is used to store the price, and the second one is used to store the symbols) would work for me. Also the map is very easy to output, here is the output code:
Code:
void showTPOInConsole(map<double, string> tpo)
{
cout << "\n\t TPO_CHART \n\t" << endl;
for (const auto& p : tpo)
{
cout << p.first << " \t" << p.second << endl;
}
}
The second problem I encountered was what to do about the price. For example, if the price in the first hour went:
Code:
{219,"A"},
{220, "A"},
{221, "A"},
And in the second hour the price went:
Code:
{219.5, "B"},
{220,"B"},
{220.8,"B"},
{222,"B"},
{223,"B"},
How do I combine them?
We know that 219.5 is very close to 219 and they could be combined, how do I solve this? Should I use a quantizer?
Thx!