if(ok &&
sql_query.size() > 0) {
unsigned char index_tick_date = record.indexOf("TICK_DATE");
unsigned char index_tick_time = record.indexOf("TICK_TIME");
unsigned char index_open = record.indexOf("OPEN");
unsigned char index_high = record.indexOf("HIGH");
unsigned char index_low = record.indexOf("LOW");
unsigned char index_close = record.indexOf("CLOSE");
unsigned char index_volume = record.indexOf("VOLUME");
int row = sql_query.size();
int date_prev = -1;
int time_prev = -1, time_weekly_prev = -1, time_monthly_prev = -1;
float open_daily_prev, open_weekly_prev, open_monthly_prev;
float high_daily_prev, high_weekly_prev, high_monthly_prev;
float low_daily_prev, low_weekly_prev, low_monthly_prev;
float close_daily_prev, close_weekly_prev, close_monthly_prev;
float volume_daily_prev, volume_weekly_prev, volume_monthly_prev;
bool init_daily, init_weekly, init_monthly;
unsigned char minutes_counter = 0;
init_daily = init_weekly = init_monthly = true;
while(sql_query.next()) {
QString date_str
= sql_query.
value(index_tick_date
).
toDate().
toString("yyyyMMdd");
int date = date_str.toInt();
QString time_str
= sql_query.
value(index_tick_time
).
toTime().
toString("hhmm");
int time = time_str.toInt();
float open = sql_query.value(index_open).toFloat();
float high = sql_query.value(index_high).toFloat();
float low = sql_query.value(index_low).toFloat();
float close = sql_query.value(index_close).toFloat();
float volume = sql_query.value(index_volume).toInt();
if(time_prev == -1) {
time_prev = time;
time_monthly_prev = time;
time_weekly_prev = time_str.left(2).toInt() * 100;
}
if(date_prev == -1)
date_prev = date;
if(init_daily) {
init_daily = false;
open_daily_prev = open_weekly_prev = open_monthly_prev = open;
high_daily_prev = high_weekly_prev = high_monthly_prev = high;
low_daily_prev = low_weekly_prev = low_monthly_prev = low;
close_daily_prev = close_weekly_prev = close_monthly_prev = close;
volume_daily_prev = volume_weekly_prev = volume_monthly_prev = close;
}
// Daily checks
// one minute resolution data
{
if(time == time_prev) {
high_daily_prev = ::max(high, high_daily_prev);
low_daily_prev = ::min(low, low_daily_prev);
close_daily_prev = close;
volume_daily_prev += volume;
} else if(time > time_prev || date > date_prev) {
// Process Data Here
// DoSomething()
createOHLCData(date_prev, time_prev, open_daily_prev, high_daily_prev, low_daily_prev, close_daily_prev, id_element_price[INDEX_DAILY]);
createVolumeData(date_prev, time_prev, volume_daily_prev, id_element_volume[INDEX_DAILY]);
// Weekly checks
// One hour resolution data
{
// 60 minutes in one hour
if(((time_weekly_prev/100) < (time/100)) ||
date > date_prev ||
init_weekly) {
if(!init_weekly) {
// Process weekly data here
// DoSomething()
createOHLCData(date_prev, time_weekly_prev, open_weekly_prev, high_weekly_prev, low_weekly_prev, close_weekly_prev, id_element_price[INDEX_WEEKLY]);
createVolumeData(date_prev, time_weekly_prev, volume_weekly_prev, id_element_volume[INDEX_WEEKLY]);
minutes_counter = 0;
time_weekly_prev = time_str.left(2).toInt() * 100;
} else { init_weekly = false; }
open_weekly_prev = open_daily_prev;
high_weekly_prev = high_daily_prev;
low_weekly_prev = low_daily_prev;
close_weekly_prev = close_daily_prev;
volume_weekly_prev = volume_daily_prev;
} else {
high_weekly_prev = ::max(high_daily_prev, high_weekly_prev);
low_weekly_prev = ::min(low_daily_prev, low_weekly_prev);
close_weekly_prev = close_daily_prev;
volume_weekly_prev += volume_daily_prev;
}
}
// Monthly checks
// One day resolution
{
// 60 minutes in one hour
if(date > date_prev ||
init_monthly) {
if(!init_monthly) {
// Process monthly data here
// DoSomething()
createOHLCData(date_prev, time_monthly_prev, open_monthly_prev, high_monthly_prev, low_monthly_prev, close_monthly_prev, id_element_price[INDEX_MONTHLY]);
createVolumeData(date_prev, time_monthly_prev, volume_monthly_prev, id_element_volume[INDEX_MONTHLY]);
date_prev = date;
time_monthly_prev = time;
} else { init_monthly = false; }
open_monthly_prev = open_daily_prev;
high_monthly_prev = high_daily_prev;
low_monthly_prev = low_daily_prev;
close_monthly_prev = close_daily_prev;
volume_monthly_prev = volume_daily_prev;
} else {
high_monthly_prev = ::max(high_daily_prev, high_monthly_prev);
low_monthly_prev = ::min(low_daily_prev, low_monthly_prev);
close_monthly_prev = close_daily_prev;
volume_monthly_prev += volume_daily_prev;
}
}
open_daily_prev = open;
high_daily_prev = high;
low_daily_prev = low;
close_daily_prev = close;
volume_daily_prev = volume;
}
time_prev = time;
}
}
if(row >= 1) {
createOHLCData(date_prev, time_prev, open_daily_prev, high_daily_prev, low_daily_prev, close_daily_prev, id_element_price[INDEX_DAILY]);
createVolumeData(date_prev, time_prev, volume_daily_prev, id_element_volume[INDEX_DAILY]);
createOHLCData(date_prev, time_weekly_prev, open_weekly_prev, high_weekly_prev, low_weekly_prev, close_weekly_prev, id_element_price[INDEX_WEEKLY]);
createVolumeData(date_prev, time_weekly_prev, volume_weekly_prev, id_element_volume[INDEX_WEEKLY]);
createOHLCData(date_prev, time_monthly_prev, open_monthly_prev, high_monthly_prev, low_monthly_prev, close_monthly_prev, id_element_price[INDEX_MONTHLY]);
createVolumeData(date_prev, time_monthly_prev, volume_monthly_prev, id_element_volume[INDEX_MONTHLY]);
}
}
if(ok &&
sql_query.size() > 0) {
QSqlRecord record = sql_query.record();
unsigned char index_tick_date = record.indexOf("TICK_DATE");
unsigned char index_tick_time = record.indexOf("TICK_TIME");
unsigned char index_open = record.indexOf("OPEN");
unsigned char index_high = record.indexOf("HIGH");
unsigned char index_low = record.indexOf("LOW");
unsigned char index_close = record.indexOf("CLOSE");
unsigned char index_volume = record.indexOf("VOLUME");
int row = sql_query.size();
int date_prev = -1;
int time_prev = -1, time_weekly_prev = -1, time_monthly_prev = -1;
float open_daily_prev, open_weekly_prev, open_monthly_prev;
float high_daily_prev, high_weekly_prev, high_monthly_prev;
float low_daily_prev, low_weekly_prev, low_monthly_prev;
float close_daily_prev, close_weekly_prev, close_monthly_prev;
float volume_daily_prev, volume_weekly_prev, volume_monthly_prev;
bool init_daily, init_weekly, init_monthly;
unsigned char minutes_counter = 0;
init_daily = init_weekly = init_monthly = true;
while(sql_query.next()) {
QString date_str = sql_query.value(index_tick_date).toDate().toString("yyyyMMdd");
int date = date_str.toInt();
QString time_str = sql_query.value(index_tick_time).toTime().toString("hhmm");
int time = time_str.toInt();
float open = sql_query.value(index_open).toFloat();
float high = sql_query.value(index_high).toFloat();
float low = sql_query.value(index_low).toFloat();
float close = sql_query.value(index_close).toFloat();
float volume = sql_query.value(index_volume).toInt();
if(time_prev == -1) {
time_prev = time;
time_monthly_prev = time;
time_weekly_prev = time_str.left(2).toInt() * 100;
}
if(date_prev == -1)
date_prev = date;
if(init_daily) {
init_daily = false;
open_daily_prev = open_weekly_prev = open_monthly_prev = open;
high_daily_prev = high_weekly_prev = high_monthly_prev = high;
low_daily_prev = low_weekly_prev = low_monthly_prev = low;
close_daily_prev = close_weekly_prev = close_monthly_prev = close;
volume_daily_prev = volume_weekly_prev = volume_monthly_prev = close;
}
// Daily checks
// one minute resolution data
{
if(time == time_prev) {
high_daily_prev = ::max(high, high_daily_prev);
low_daily_prev = ::min(low, low_daily_prev);
close_daily_prev = close;
volume_daily_prev += volume;
} else if(time > time_prev || date > date_prev) {
// Process Data Here
// DoSomething()
createOHLCData(date_prev, time_prev, open_daily_prev, high_daily_prev, low_daily_prev, close_daily_prev, id_element_price[INDEX_DAILY]);
createVolumeData(date_prev, time_prev, volume_daily_prev, id_element_volume[INDEX_DAILY]);
// Weekly checks
// One hour resolution data
{
// 60 minutes in one hour
if(((time_weekly_prev/100) < (time/100)) ||
date > date_prev ||
init_weekly) {
if(!init_weekly) {
// Process weekly data here
// DoSomething()
createOHLCData(date_prev, time_weekly_prev, open_weekly_prev, high_weekly_prev, low_weekly_prev, close_weekly_prev, id_element_price[INDEX_WEEKLY]);
createVolumeData(date_prev, time_weekly_prev, volume_weekly_prev, id_element_volume[INDEX_WEEKLY]);
minutes_counter = 0;
time_weekly_prev = time_str.left(2).toInt() * 100;
} else { init_weekly = false; }
open_weekly_prev = open_daily_prev;
high_weekly_prev = high_daily_prev;
low_weekly_prev = low_daily_prev;
close_weekly_prev = close_daily_prev;
volume_weekly_prev = volume_daily_prev;
} else {
high_weekly_prev = ::max(high_daily_prev, high_weekly_prev);
low_weekly_prev = ::min(low_daily_prev, low_weekly_prev);
close_weekly_prev = close_daily_prev;
volume_weekly_prev += volume_daily_prev;
}
}
// Monthly checks
// One day resolution
{
// 60 minutes in one hour
if(date > date_prev ||
init_monthly) {
if(!init_monthly) {
// Process monthly data here
// DoSomething()
createOHLCData(date_prev, time_monthly_prev, open_monthly_prev, high_monthly_prev, low_monthly_prev, close_monthly_prev, id_element_price[INDEX_MONTHLY]);
createVolumeData(date_prev, time_monthly_prev, volume_monthly_prev, id_element_volume[INDEX_MONTHLY]);
date_prev = date;
time_monthly_prev = time;
} else { init_monthly = false; }
open_monthly_prev = open_daily_prev;
high_monthly_prev = high_daily_prev;
low_monthly_prev = low_daily_prev;
close_monthly_prev = close_daily_prev;
volume_monthly_prev = volume_daily_prev;
} else {
high_monthly_prev = ::max(high_daily_prev, high_monthly_prev);
low_monthly_prev = ::min(low_daily_prev, low_monthly_prev);
close_monthly_prev = close_daily_prev;
volume_monthly_prev += volume_daily_prev;
}
}
open_daily_prev = open;
high_daily_prev = high;
low_daily_prev = low;
close_daily_prev = close;
volume_daily_prev = volume;
}
time_prev = time;
}
}
if(row >= 1) {
createOHLCData(date_prev, time_prev, open_daily_prev, high_daily_prev, low_daily_prev, close_daily_prev, id_element_price[INDEX_DAILY]);
createVolumeData(date_prev, time_prev, volume_daily_prev, id_element_volume[INDEX_DAILY]);
createOHLCData(date_prev, time_weekly_prev, open_weekly_prev, high_weekly_prev, low_weekly_prev, close_weekly_prev, id_element_price[INDEX_WEEKLY]);
createVolumeData(date_prev, time_weekly_prev, volume_weekly_prev, id_element_volume[INDEX_WEEKLY]);
createOHLCData(date_prev, time_monthly_prev, open_monthly_prev, high_monthly_prev, low_monthly_prev, close_monthly_prev, id_element_price[INDEX_MONTHLY]);
createVolumeData(date_prev, time_monthly_prev, volume_monthly_prev, id_element_volume[INDEX_MONTHLY]);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks