void AggregateBars(int targetPeriod, int sourcePeriod) {
int sourceBars = targetPeriod / sourcePeriod;
for(int day = 0; day < 10; day++) { // 处理最近10个周期
int startShift = day * sourceBars;
double aggOpen = iOpen(NULL, sourcePeriod, startShift + sourceBars - 1);
double aggHigh = 0;
double aggLow = 1000000;
double aggClose = iClose(NULL, sourcePeriod, startShift);
for(int i = 0; i < sourceBars; i++) {
int shift = startShift + i;
aggHigh = MathMax(aggHigh, iHigh(NULL, sourcePeriod, shift));
aggLow = MathMin(aggLow, iLow(NULL, sourcePeriod, shift));
}
Print(TimeToStr(iTime(NULL, sourcePeriod, startShift)),
" > O:", aggOpen, " H:", aggHigh, " L:", aggLow, " C:", aggClose);
}
}
// 调用:将1小时数据合成为4小时图
AggregateBars(PERIOD_H4, PERIOD_H1); |