臭宝很深情 发表于 2025-8-17 13:45:34

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);

zyyhg 发表于 2025-8-17 15:03:51

555555
页: 1 2 3 4 5 6 7 8 [9]
查看完整版本: 编写竹节图