public synchronized List<TrendBar> getHistory(long from, Long to) {
        List<TrendBar> result = new ArrayList<TrendBar>();
        int currentPeriodIdx = getTrendBarIdx(from);

        TrendBar previousTrendBar = null;
        while (currentPeriodIdx < completedTrendBars.size()
                && (to == null || completedTrendBars.get(currentPeriodIdx).getStartTime() < to)) {

            TrendBar currentTrendBar = completedTrendBars.get(currentPeriodIdx);

            if (previousTrendBar != null) {
                long endTime = currentTrendBar.getStartTime();
                addEmptyTrendBars(result, previousTrendBar, endTime);
            }

            result.add(currentTrendBar);

            previousTrendBar = currentTrendBar;
            currentPeriodIdx++;
        }
        if (!result.isEmpty()) {
            long limit = to == null ? periodStartTime : Math.min(to, periodStartTime);
            addEmptyTrendBars(result, result.get(result.size() - 1), limit);
        }
        return result;
    }