Dec 5, 2017 at 5:38pm UTC
Looking for max value in vector member range.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
struct Data
{
double open, high, low, close;
};
void hhv (vector<Data> &matrix, double range)
{
for (unsigned int i{0}; i < matrix.size(); i++)
{
double most{0};
for (unsigned int h{i}; h < i + range; h++)
{
most = max_element(matrix[h].high, matrix[h + range].high);
}
}
}
If any more info is needed, love to provide it. Thanks for the help.
Last edited on Dec 5, 2017 at 5:39pm UTC
Dec 5, 2017 at 5:50pm UTC
Something like this, with range as an int:
max_element(matrix.begin(), matrix.begin()+range, [](Data const lhs, Data const rhs){return lhs.high > rhs.high});
Haven't tested it; just wrote it down. Something like that. It specifies the range over which to search, and the function to use to determine if one Data is bigger than the other.
Dec 5, 2017 at 6:10pm UTC
Ok. That makes sense. The code doesn't run as is, but it gives me the idea I need to fix the issue. I really appreciate it. Thanks!