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: 13 times
Been thanked: 36 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: 66
Joined: Thu Nov 01, 2018 1:50 pm
Has thanked: 37 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 309 times
Capture.JPG
Capture.JPG (112.73 KiB) Viewed 312 times

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

Re: Demo strategies: QuotesDelta Indicator

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

Anyone?

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

Re: Demo strategies: QuotesDelta Indicator

Post by AndreyR » 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: 66
Joined: Thu Nov 01, 2018 1:50 pm
Has thanked: 37 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: 66
Joined: Thu Nov 01, 2018 1:50 pm
Has thanked: 37 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

 

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

Re: Demo strategies: QuotesDelta Indicator

Post by AndreyR » 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: 66
Joined: Thu Nov 01, 2018 1:50 pm
Has thanked: 37 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!

Post Reply