Demo strategies: QuotesDelta Indicator

Custom indicators, trading strategies, data export and recording and more...
mdtrader
Posts: 39
Joined: Sat Oct 27, 2018 4:05 pm
Location: germany
Has thanked: 12 times
Been thanked: 41 times

Re: Demo strategies: QuotesDelta Indicator

Post by mdtrader » Mon Dec 17, 2018 2:45 pm

V 7.0.0 build 53

Tags:

SuperDriveGuy
Posts: 67
Joined: Thu Nov 01, 2018 1:50 pm
Has thanked: 38 times
Been thanked: 9 times

Re: Demo strategies: QuotesDelta Indicator

Post by SuperDriveGuy » Fri Aug 16, 2019 1:29 pm

Hi Serg,
  Is it possible to export the Quotes data in the same way that I can export the trades data to a csv. Basically it would be interesting to see the effect of Quotes being added and pulled with Time/Price/Size, exactly like the trades data. It is being displayed in the Quotes delta column, so I guess that since this data is being generated, it will be possible to access this data and export it?

  Also, as an addition it might be great if one can access this data programmatically? so maybe write to a file oneself or do calculations.

  A limit on the number of levels will be good idea otherwise with MBO, this will be crazy file sizes.

  I am aware of the Quotes Delta indicator and its code, But that sums up ALL the quotes(up to a limit level), whereas here one is interested in individual quotes being added or pulled. I have tried this another platform but the incoming data is not granular enough to record all(most) of the quotes.


  TIA
Attachments
Capture2.JPG
Capture2.JPG (78.18 KiB) Viewed 22543 times
Capture.JPG
Capture.JPG (112.73 KiB) Viewed 22546 times

SuperDriveGuy
Posts: 67
Joined: Thu Nov 01, 2018 1:50 pm
Has thanked: 38 times
Been thanked: 9 times

Re: Demo strategies: QuotesDelta Indicator

Post by SuperDriveGuy » Thu Aug 22, 2019 8:29 am

Anyone?

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 Aug 22, 2019 3:14 pm

Hi SuperDriveGuy,
currently, it is impossible to export the Quotes data from the Quotes Data Column.
Sorry if I am getting it wrong, since the code you attached is able(?) to calculate individual level deltas you can turn that output into whatever you want.

SuperDriveGuy
Posts: 67
Joined: Thu Nov 01, 2018 1:50 pm
Has thanked: 38 times
Been thanked: 9 times

Re: Demo strategies: QuotesDelta Indicator

Post by SuperDriveGuy » Thu Aug 22, 2019 5:40 pm

Hi AndreyR,
  Thanks for your reply.

   Sorry, maybe I explained it wrong.

  The code(copied below too), sums up individual adds/pulls upto the number of levels defined. I need the individual pull and add, same as displayed in the time&sales window

--------------
public long getInterval()
      {
        return Intervals.INTERVAL_100_MILLISECONDS;
      }
      
      public void onDepth(boolean isBid, int price, int size)
      {
        TreeMap<Integer, Integer> halfBook = isBid ? book.bids : book.asks;
        int bestPrice = halfBook.isEmpty() ? price : ((Integer)halfBook.firstKey()).intValue();
        int priceLevel = isBid ? bestPrice - price : price - bestPrice;
        
        int prevSize = book.onDepth(isBid, price, size);
        
        if ((limitNumPriceLevels.booleanValue()) && (priceLevel >= maxPriceLevels.intValue())) {
          return;
        }
        
        if (snapshotCompleted) {
          int delta = size - prevSize;
          if (isBid) {
            bidDeltaSize += delta;
            bidDeltaCount += 1;
          } else {
            askDeltaSize += delta;
            askDeltaCount += 1;
          }
          int lastBestPrice = isBid ? lastBidPrice : lastAskPrice;
          bestPrice = halfBook.isEmpty() ? price : ((Integer)halfBook.firstKey()).intValue();
          if ((resetOnPriceChange.booleanValue()) && (bestPrice != lastBestPrice)) {
            if (isBid) {
              lastBidPrice = bestPrice;
              bidDeltaSize = 0;
              bidDeltaCount = 0;
            } else {
              lastAskPrice = bestPrice;
              askDeltaSize = 0;
              askDeltaCount = 0;
            }
          }
        }
      }
      
      public void onSnapshotEnd()
      {
        snapshotCompleted = true;
      }
-----------------------

Thanks

SuperDriveGuy
Posts: 67
Joined: Thu Nov 01, 2018 1:50 pm
Has thanked: 38 times
Been thanked: 9 times

Re: Demo strategies: QuotesDelta Indicator

Post by SuperDriveGuy » Fri Aug 23, 2019 7:53 am

Hi AndreyR,
    I have taken the output from Time&Sales and changed it to reflect how it would look when the data is derived from the Quotes being added or pulled.

TIME,B/S,PRICE,DELTA
09:38:17:344,S,11785.0,1
09:38:17:417,B,11786.0,1
09:38:18:509,S,11785.0,1
09:38:18:510,S,11785.0,1
09:38:19:066,B,11786.0,-4
09:38:19:756,S,11786.0,1
09:38:20:380,B,11785.5,1
09:38:20:483,B,11786.0,1
09:38:20:860,B,11785.5,-1
09:38:21:218,S,11785.0,1
09:38:23:562,B,11785.0,1
09:38:23:563,B,11785.0,1
09:38:24:055,S,11784.5,-2
09:38:24:157,S,11784.0,1

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 » Fri Aug 23, 2019 12:49 pm

This should work for you. Yor output file will be at your C: drive (change the code if you need to).
Add TimeListener to implemented interfaces.
Add these fields to your class

Code: Select all

    long t;
    File output = new File("C:\\qd-" + System.currentTimeMillis() + ".csv" );
    PrintWriter pw;
some lines to your initialize method

Code: Select all

        try {
            pw = new PrintWriter(output);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
implement a method for the TimeListener interface

Code: Select all

    @Override
    public void onTimestamp(long t) {
        this.t = t;        
    }
create a method to write a csv

Code: Select all

    void writeToCsv(Object... args) {
        for (Object arg : args) {
            pw.print(arg.toString());
            pw.append(';');
        }
        pw.print('\n');
    }
and add these in the end of your onDepth method

Code: Select all

        if (snapshotCompleted) {
            String side = isBid? "BID" : "ASK";
            writeToCsv(Instant.ofEpochMilli(t/1_000_000), side, price, (size - prevSize));
        }
add this to onStop() method

Code: Select all

pw.close();

SuperDriveGuy
Posts: 67
Joined: Thu Nov 01, 2018 1:50 pm
Has thanked: 38 times
Been thanked: 9 times

Re: Demo strategies: QuotesDelta Indicator

Post by SuperDriveGuy » Fri Aug 23, 2019 3:43 pm

You are the man!

Thank you!

feseanobi12
Posts: 2
Joined: Sat Apr 18, 2020 8:37 am

Re: Demo strategies: QuotesDelta Indicator

Post by feseanobi12 » Sat Apr 18, 2020 1:23 pm

Serg wrote:
Tue Dec 04, 2018 4:15 pm
Hi,
I added a checkbox that makes it reset on every price change, you can download it here. Personally, I don't find this mode very useful for chart trading, but it's up to you.

Hi Serg, 
Thanks for the awesome QuotesDelta Indicator. Can I ask a favour. Can you please provide a very high level summarised explanation of how to interpret the plot from Quotes Count Delta indicator with the 'reset when best price changes'  active and how to interpret the plot when the reset best price is NOT checked. Just wanted a different perspective to interpreting the plot generated by this indicator. Thanks a lot for this, much appreciated.

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:32 pm

Dear Serg

I worked with this indicator and have some confusion in calculation of bid, ask and Delta
I even add bid and ask lines to graph

Looks like bidDelta and Delta very alike in both scenarios  - buyers dominate or sales dominate

Not sure how to insert screenshot to this msg

Best AG

Post Reply