Market Depth Ratio - EasyLanguage

Discussion in 'App Development' started by Python4Trade, Jun 29, 2018.

  1. Hi everyone!


    I would like to create an indicator for TradeStation that plots the BID - ASK ratio for minimum 6 levels.

    BID ratio formula (same for ASK): (Total volume available at the 6 bid levels / Total volume at BID and ASK for the 6 levels) *100

    So nothing innovative here but it is very interesting to see where the liquidity is (at the BID or at the ASK).

    As you can see, there are two codes. 1st one is not working and is using the MarketDepth Provider. 2nd one is the BID-ASK ratio that only consider the best BID and best ASK but is working.

    Hope someone can help me!

    Cheers


    Code:
    Inputs:
        HighBID(60),
        HighASK(80),
        int asklevel1(0),
        int asklevel2(1),
        int asklevel3(2),
        int asklevel4(3),
        int asklevel5(4),
        int asklevel6(5),
        int bidlevel1(0),
        int bidlevel2(1),
        int bidlevel3(2),
        int bidlevel4(3),
        int bidlevel5(4),
        int bidlevel6(5);
       
    Input:
        string iSymbol1( symbol );
    
    method void DOM_Updated( elsystem.Object sender, tsdata.marketdata.MarketDepthUpdatedEventArgs args )
    begin
        PlotOutputs();
    End;
    
    method void PlotOutputs()
    
    vars:
        tsdata.marketdata.AggregateMarketQuote amQuote1, {----------BIDS---------}
        tsdata.marketdata.AggregateMarketQuote amQuote2,
        tsdata.marketdata.AggregateMarketQuote amQuote3,
        tsdata.marketdata.AggregateMarketQuote amQuote4,
        tsdata.marketdata.AggregateMarketQuote amQuote5,
        tsdata.marketdata.AggregateMarketQuote amQuote6,
        tsdata.marketdata.AggregateMarketQuote amQuote7, {----------ASKS---------}
        tsdata.marketdata.AggregateMarketQuote amQuote8,
        tsdata.marketdata.AggregateMarketQuote amQuote9,
        tsdata.marketdata.AggregateMarketQuote amQuote10,
        tsdata.marketdata.AggregateMarketQuote amQuote11,
        tsdata.marketdata.AggregateMarketQuote amQuote12;
       
    
    begin
        If (DOM.Bids.Count > 0 and DOM.Asks.Count > 0) then
        begin
       
            { gets the Bid info for the specified levels }
            amQuote1 = DOM.BidLevels[bidlevel1];
            amQuote2 = DOM.BidLevels[bidlevel2];
            amQuote3 = DOM.BidLevels[bidlevel3];
            amQuote4 = DOM.BidLevels[bidlevel4];
            amQuote5 = DOM.BidLevels[bidlevel5];
            amQuote6 = DOM.BidLevels[bidlevel6];
           
            { Getting the BID sizes for all levels }
            Value1 = (amQuote1.TotalSize);
            Value2 = (amQuote2.TotalSize);
            Value3 = (amQuote3.TotalSize);
            Value4 = (amQuote4.TotalSize);
            Value5 = (amQuote5.TotalSize);
            Value6 = (amQuote6.TotalSize);
           
            { Compute the total size of these 6 BID levels }
            Value20 = (Value1 + Value2 + Value3 + Value4 + Value5 + Value6);
           
            { gets the Ask info for the specified level }
            amQuote7 = DOM.askLevels[asklevel1];
            amQuote8 = DOM.askLevels[asklevel2];
            amQuote9 = DOM.askLevels[asklevel3];
            amQuote10 = DOM.askLevels[asklevel4];
            amQuote11 = DOM.askLevels[asklevel5];
            amQuote12 = DOM.askLevels[asklevel6];
           
            { Getting the ASK sizes for all levels }
            Value7 = (amQuote7.TotalSize);
            Value8 = (amQuote8.TotalSize);
            Value9 = (amQuote9.TotalSize);
            Value10 = (amQuote10.TotalSize);
            Value11 = (amQuote11.TotalSize);
            Value12 = (amQuote12.TotalSize);
           
            { Compute the total size of these 6 ASK levels }
            Value30 = (Value7 + Value8 + Value9 + Value10 + Value11 + Value12);
           
            {Total shares on each side of the book }
            Value40 = (Value20 + Value30);
           
            {BID ratio}
            Value50 = ( Value20 / Value40 ) * 100;
           
            {ASK Ratio}
            Value60 = ( Value30 / Value40 ) * 100;
           
           
           
    Plot1( Value50, "BID Ratio" );
    Plot2( Value60, "ASK Ratio" );
           
           
           
        end;
    End;


    Code:
    Inputs:
        HighBID(60),
        HighASK(80);
    
    Value1 = BidSize;
    Value2 = AskSize;
    
    Value3 = (Value1 + Value2); {Total contracts on BID + ASK}
    Value4 = (Value1 / Value3)*100; {Bid value compared to total size}
    Value5 = (Value2 / Value3)*100; {Ask value compared to total size}
    
    Plot1( Value4 );
    Plot2( Value5 );
    Plot3( HighBID );
    Plot4( HighASK );
     
  2. MarkBrown

    MarkBrown

    I'm not sure that tradestation has this actual data available?
     
  3. Of course it has, you can access depth of market for stocks, futures...
     
  4. MarkBrown

    MarkBrown

    there use to be a old problem that you could chart the data visually but when calling it in a indicator the data is different and not accurate. maybe that is fixed now but make sure, the chart / quote data is the same as the indicator is displaying. in fact i gave up on what your doing many years ago.
     
  5. That's interesting, also why the DOM data would be different in reality than in my indicator?
     
  6. MarkBrown

    MarkBrown

    example they use actual volume in the quote fields but when called by a indicator they send tick data which is only representative of volume.