BarBuilder API not returning correct OHLC values of BAR

Custom indicators, trading strategies, data export and recording and more...
trades4x
Posts: 9
Joined: Sat Jul 13, 2019 8:52 pm
Has thanked: 3 times
Been thanked: 1 time

BarBuilder API not returning correct OHLC values of BAR

Post by trades4x » Wed Aug 28, 2019 8:10 pm

BarBuilder is ot returning correct OHLC values for ES futures, ES price is in the range of 2860 - 2890 on a given day but the  values of OHLC are returnning as:
**********************************************************************************************************************

20190828 19:15:00.019(UTC) INFO: onBar time: 20190828 19:15:00.000000000. OHLC: 11550, 11552, 11549, 11552. Volume Buy Sell: 303, 183
20190828 19:16:00.004(UTC) INFO: onBar time: 20190828 19:16:00.000000000. OHLC: 11552, 11555, 11550, 11554. Volume Buy Sell: 606, 418
20190828 19:17:00.030(UTC) INFO: onBar time: 20190828 19:17:00.000000000. OHLC: 11554, 11556, 11548, 11549. Volume Buy Sell: 826, 1508
20190828 19:18:00.004(UTC) INFO: onBar time: 20190828 19:18:00.000000000. OHLC: 11549, 11551, 11546, 11548. Volume Buy Sell: 864, 1522
20190828 19:18:16.158(UTC) INFO: Synthesize: ES bid bid iceberg 100
20190828 19:18:16.158(UTC) INFO: Preprocessed text:E S bid bid iceberg 100
20190828 19:18:25.719(UTC) INFO: Synthesize: ES bid bid iceberg 200

***********************************************************************************************************************

Here is the code of BarBuilder from demo recorder project:

package com.bookmap.api.simple.demo.recorders;

import velox.api.layer1.annotations.Layer1ApiVersion;
import velox.api.layer1.annotations.Layer1ApiVersionValue;
import velox.api.layer1.annotations.Layer1SimpleAttachable;
import velox.api.layer1.annotations.Layer1StrategyName;
import velox.api.layer1.common.Log;
import velox.api.layer1.data.InstrumentInfo;
import velox.api.layer1.data.TradeInfo;
import velox.api.layer1.simplified.Api;
import velox.api.layer1.simplified.Bar;
import velox.api.layer1.simplified.CustomModule;
import velox.api.layer1.simplified.HistoricalDataListener;
import velox.api.layer1.simplified.InitialState;
import velox.api.layer1.simplified.Intervals;
import velox.api.layer1.simplified.TimeListener;
import velox.api.layer1.simplified.TradeDataListener;

@Layer1SimpleAttachable
@Layer1StrategyName("Bar Builder")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION1)
public class BarBuilder extends DataRecorderBase implements CustomModule, TradeDataListener, TimeListener, HistoricalDataListener {

    protected Long barTime = null;
    protected final long barInterval = Intervals.INTERVAL_1_MINUTE;
    private Bar bar = new Bar();

    @Override
    public void onTimestamp(long t) {
        if (barTime == null || barTime > t) {
            barTime = barInterval * (t / barInterval);
        }
        while (barTime + barInterval < t) {
            barTime += barInterval;
            onBar();
            bar.startNext();
        }
    }

    @Override
    public void onTrade(double price, int size, TradeInfo tradeInfo) {
        bar.addTrade(tradeInfo.isBidAggressor, size, price);
        writeObjects(getDateTime(barTime), tradeInfo.isBidAggressor ? "Buy" : "Sell", price, size);
    }

    @Override
    public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
    }

    protected void onBar() {
        String datetime = getDateTime(barTime);
        String info = String.format("onBar time: %s. OHLC: %.0f, %.0f, %.0f, %.0f. Volume Buy Sell: %d, %d", datetime,
                bar.getOpen(), bar.getHigh(), bar.getLow(), bar.getClose(), bar.getVolumeBuy(), bar.getVolumeSell());
        Log.info(info);
    }

    @Override
    protected String getFilename() {
        return "Volume_" + System.currentTimeMillis() + ".txt";
    }
}

 

AndreyR
Posts: 161
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 10 times
Been thanked: 37 times

Re: BarBuilder API not returning correct OHLC values of BAR

Post by AndreyR » Thu Aug 29, 2019 11:51 am

Hi trades4x,
Bookmap consumes prices in pips (or ticks, interchangeable in this context). If the pips for this symbol is 0.25 the 2860-2890 range becomes 11440-11560
(2860/0.25 = 11440...).
To get regular prices you've got to multiply prices by pips.
You can get pips for this symbol from the InstrumentInfo object in the initialize method.
Multiply every value you get from Bar by pips and you'll have regular prices.

trades4x
Posts: 9
Joined: Sat Jul 13, 2019 8:52 pm
Has thanked: 3 times
Been thanked: 1 time

Re: BarBuilder API not returning correct OHLC values of BAR

Post by trades4x » Sun Sep 01, 2019 3:35 am

thanks so much

Post Reply