Demo strategies: QuotesDelta Indicator

Custom indicators, trading strategies, data export and recording and more...
agan1337
Posts: 10
Joined: Tue Dec 10, 2019 9:31 pm
Been thanked: 1 time

Re: Demo strategies: QuotesDelta Indicator

Post by agan1337 » Thu May 28, 2020 9:43 pm

This is screenshot where you can see BidDelta (green) and Delta(pink) almost together
Red is a askDelta

Best 

AG
Attachments
Capture.JPG
Capture.JPG (137.23 KiB) Viewed 8104 times

Tags:

agan1337
Posts: 10
Joined: Tue Dec 10, 2019 9:31 pm
Been thanked: 1 time

Re: Demo strategies: QuotesDelta Indicator

Post by agan1337 » Tue Jun 02, 2020 4:44 pm

Hi

I try to see OrderID for MBO 

I add MarketbyOrderDepthListener and use proper method

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

import java.awt.Color;

import com.bookmap.api.simple.demo.utils.data.OrderBookBase;

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.data.InstrumentInfo;
import velox.api.layer1.layers.utils.OrderBook;
import velox.api.layer1.messages.indicators.Layer1ApiUserMessageModifyIndicator.GraphType;
import velox.api.layer1.simplified.Api;
import velox.api.layer1.simplified.Bar;
import velox.api.layer1.simplified.BarDataListener;
import velox.api.layer1.simplified.CustomModule;
import velox.api.layer1.simplified.DepthDataListener;
import velox.api.layer1.simplified.Indicator;
import velox.api.layer1.simplified.InitialState;
import velox.api.layer1.simplified.Intervals;
import velox.api.layer1.simplified.MarketByOrderDepthDataListener;
import velox.api.layer1.simplified.SnapshotEndListener;

@Layer1SimpleAttachable
@Layer1StrategyName("MBO Order ID2")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION1)
public class MBOOrderID2 implements CustomModule, BarDataListener,  SnapshotEndListener,
                                    MarketByOrderDepthDataListener , DepthDataListener{


    protected final OrderBookBase book = new OrderBookBase();
    private int bidSUM = 0;
    private int askSUM = 0;
    private boolean snapshotCompleted = false;
**** public void send(java.lang.String orderId,
            boolean isBid,
            int price,
            int size)
    {
         int prevSize = book.onDepth(isBid, price, size);
         if (snapshotCompleted) 
                   {
                        int delta = size - prevSize;
                
                       if (isBid) 
                        {
                           bidSUM += delta;
                           
                           
                
                        } else {
                            askSUM += delta;
                        }
                       System.out.println( orderId);
                       
                    }
         
         
         
    }***********

Indicator works, but I can not get output - nothing in log

How I can see my output value

Thank you

AG
 

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: Demo strategies: QuotesDelta Indicator

Post by Andry API support » Thu Jun 04, 2020 10:57 am

Hi AG!
What instrument were you subscribed to?

jamin1981
Posts: 4
Joined: Wed Apr 21, 2021 1:51 am
Been thanked: 4 times

Re: Demo strategies: QuotesDelta Indicator

Post by jamin1981 » Wed Apr 21, 2021 10:49 am

Hi Serg, all

Awesome indicator!

I have a couple of questions. Is it possible to have an option for chart range/session range so values are shown for chart range. And also, it is possible to measure only stacking and have a filter for size? I think this may be helpful. 

Many thanks!!

 

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: Demo strategies: QuotesDelta Indicator

Post by Andry API support » Thu Apr 29, 2021 9:05 am

Hi!
1) QuotesDelta example is written using Simplified API. Unfortunately, Simplified API will not support reporting chart ranges to a custom module. It is just designed for limited scope of actions. Please use Core API if you need chart ranges to be reported to your module. Here are examples written with Core API. If you have never used Core API we would recomment to start with markers demo.
2) this is onDepth method from the original QuotesDelta module

Code: Select all

    @Override
    public void onDepth(boolean isBid, int price, int size) {
        int prevSize = book.onDepth(isBid, price, size);
        if (snapshotCompleted) {
            int delta = size - prevSize;
            if (isBid) {
                bidDelta += delta;
            } else {
                askDelta += delta;
            }
        }
    }
If you need stacking only (I recognize it as adding liquidity only and not reacting to decreasing liquidity) you may want to add delta only if is > 0.

Code: Select all

    @Override
    public void onDepth(boolean isBid, int price, int size) {
        int prevSize = book.onDepth(isBid, price, size);
        if (snapshotCompleted) {
            int delta = size - prevSize;
            
            if (delta > 0){
                if (isBid) {
                    bidDelta += delta;
                } else {
                    askDelta += delta;
                }
            }
        }
    }
You can add some other conditions for adding delta (size change value?).

Code: Select all

    @Override
    public void onDepth(boolean isBid, int price, int size) {
        int prevSize = book.onDepth(isBid, price, size);
        if (snapshotCompleted) {
            int delta = size - prevSize;
            
            if (delta >= 100){//delta is a size change so here we are filtering out deltas below 100

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: Demo strategies: QuotesDelta Indicator

Post by Andry API support » Fri Apr 30, 2021 10:55 am

So, with literally zero coding knowledge except some visual basic on a C64 when I think I managed to edit the Quotes Delta 5 to be just stacking, I think :slight_smile: I used this version as wanted to be able to edit the depth levels too. I notice though that when I try this for the size, it fires off on random times I have not defined. Did I do something wrong here? - snippet from the code, highlights are my amends
a link to the image
Getting unexpected results is pretty common in programming. You need to figure out what data causes the wrong behavior. The simplest way to do it is to write some extra info to your log and to study the log once the incorrect behavior is reproduced. In your case, you may want to add this line inside the if (delta > ...) { block so you know what exactly it is triggererd by.

Code: Select all

Log.info("delta " + delta + " isBid " + " price " + price + " size " + size );
As soon as the unexpected behavior is reached you can get your latest log file (log_....._common.txt) at (Windows) C:\Bookmap\Logs\ or a user folder for Linux or Mac.
Just for your information, price and size you are getting in the onDepth method are specified in pips/sizeMultiplier. To get the price(size) you need to multiply(divide) the price(size) by pips(sizeMultiplier) respectively. You can get the pips or minSize values from InstrumentInfo info in your module's initialize method.

Post Reply