Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bid"

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
SP
Posts: 453
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 283 times

Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bid"

Postby SP » 18 Nov 2012

With the new Breakdown functionality, it is now possible to get a better Times&Sales using Bid and Ask.

Code: Select all

{Times and Sales for MC 8.5 by SP

V1 : 17.10.2012

The code uses the new Breakdown by "Ask Traded vs Bid Traded" functionality.
It uses 2 datastreams:
- A Cumulative Delta chart with Resolution 1 Tick and  Breakdown by: "Ask Traded vs Bid Traded" and Build Volume on: "Trade Volume" and "Break on Session" checked and
  Data Range: 1 Days back as data 1   
- A Regular chart with Resolution 1 Tick as data 2

}
input:

AskBid.DataSeries   ( 1 ),
Price.DataSeries   ( 2 ),

SizeFilter      ( 0 ),         // Trades less than the size filter are filtered out

Rows            ( 40 ),          // Number of rows displayed, max of 100

Auto.Decimals      ( true ),      
Dec.Places      ( 2 ),           // Decimalplaces for price data, only used if Auto.Decimals is set to false

Show.Header      ( false ),   // Show the header above the trade size

Show.Block      ( true ),      // Draw a border on block levels
Block.AlertTradeSize( 500 ),     // Minimum trade size required to issue a block alert

Show.TradeType      ( false ),

Info            ( "Set Time.Setting to 0 in fast markets "),
Time.Setting      ( 1 ),          // Setting=1 to drop hours, setting=2 to show full time, setting=0 no time

Text.Size         ( 8 ),      
Text.Font         ( "CONSOLAS" ),// Use monospaced (non-proportional) font like Consolas, Lucida Console, Courier
Seconds.Delay      ( 2 ),      // Calc the text position only every Seconds.Delay seconds

Ask.Color         ( green ),     // Color for trades at Ask
Bid.Color         ( red ),       // Color for trades at Bid
Heading.Color      ( yellow ) ;    // Color for header

var: 
MyDecimalPlaces ( 0 ),
ii          ( 0 ),
Delay       ( 0 ),
TextHighVal    ( 0 ),
TextLowVal    ( 0 ),
MyRows        ( 0 ),
rowz          ( rows+1),
MyPlottime     ( 0 ),
time.string    (" "),
Price.txt       (" "),
TypeOfTrade    (" "),
Trade.Size    ( 0 ),
BidAskColor    ( 0 );

array:
TimesSales.txt      [101](0),
TimesSales.str      [101](" --- "),
TimesSales.block    [101](0), 
TimesSales.col      [101](getbackgroundcolor);

once
begin
   MyRows = Maxlist (Rows, 100 );
     for ii=0 to rows
     begin
          TimesSales.txt[ii]   = text_new_s(d,time_s,c,"text string");
      text_setstyle      ( TimesSales.txt[ii],1,0);
      text_setcolor      ( TimesSales.txt[ii],getbackgroundcolor);
      text_setfontname   ( TimesSales.txt[ii],Text.Font);
    end; //for ii=0 to rows
    
    If Auto.Decimals = true then
      MyDecimalPlaces = Log(PriceScale) / Log(10) else MyDecimalPlaces = Dec.Places;
   
      If Show.Header then
      begin   
       text_setstring      (TimesSales.txt[0], "TIMES & SALES "+ getsymbolname+newline+
                               "SIZE FILTER: "+numtostr ( SizeFilter,0)+Spaces(2)+
                               ifftext (Show.Block,"BLOCK SIZE : "+numtostr ( Block.AlertTradeSize,0),"")+Spaces(2)+NewLine+
                                       Ifftext (Time.Setting>0,"# TIME / ","")+
                                       "# PRICE / # VOL " +
                                       ifftext(Show.TradeType, " / # TYPE ","")  +Spaces(4) );
       text_setcolor      (TimesSales.txt[0],heading.color);
       text_setsize      (TimesSales.txt[0],text.size);
       text_setlocation_s   (TimesSales.txt[0],d,time_s , GetAppInfo( aiHighestDispValue ));
       text_setfontname   (TimesSales.txt[0],Text.Font);
      end; //If Show.Header then
end; //once begin

 
if LastBarOnChart_s  and GetAppInfo(aiRealTimeCalc) = 1 then
begin
   // calculate the text position once and then only every Seconds.Delay
   Once   
   begin
      Delay           = ComputerDateTime+(Seconds.Delay*0.0000115740) ;
      MyPlottime        = intportion (MinutesToTime ((GetAppInfo (7))*60*24)*100);
      TextHighVal       = GetAppInfo( aiHighestDispValue );
      TextLowVal       = GetAppInfo( ailowestdispvalue );
      text_setlocation_s   (TimesSales.txt[0],date,MyPlottime ,TextHighVal);   
     end; //Once
   

   If   (ComputerDateTime > Delay ) then    
   begin
      Delay           = ComputerDateTime+(Seconds.Delay*0.0000115740) ;
      MyPlottime        = intportion (MinutesToTime ((GetAppInfo (7))*60*24)*100);
      TextHighVal       = GetAppInfo( aiHighestDispValue );
      TextLowVal       = GetAppInfo( ailowestdispvalue );
      text_setlocation_s   (TimesSales.txt[0],date,MyPlottime ,TextHighVal);   
    end; //If   (GetAppInfo (18) = 1   and ComputerDateTime > Delay ) then

     Trade.Size= absvalue (close data( AskBid.DataSeries )); // TradeSize
     
if Trade.Size >= SizeFilter then
begin
     //set the colors based on at bid or at ask
     if close data(AskBid.DataSeries) >0 then BidAskColor=Ask.Color else BidAskColor=Bid.Color;
     
     //set the trade type based on at bid or at ask
     if Show.TradeType then
     begin
        
        if close data(AskBid.DataSeries) >0 then TypeofTrade = "Ask Trade"    else TypeofTrade =  "Bid Trade";
   end; //if Show.TradeType then
   
     // update the rows and colors
     for ii = MyRows  downto 1
     begin
          TimesSales.str[ii]      = TimesSales.str[ii-1];
          TimesSales.col[ii]      = TimesSales.col[ii-1];
          TimesSales.block[ii]     = TimesSales.block[ii-1];
     end; //for ii = MyRows  downto 1
             
     //price string
     Price.txt   = numtostr (close data(Price.DataSeries),MyDecimalPlaces); 
 
     // fill the first array with the latest values   
     TimesSales.str[0]      = Price.txt + Spaces(3)+numtostr (Trade.Size,0)+Spaces(5 - StrLen(numtostr (Trade.Size,0))) +TypeofTrade; 
     TimesSales.block[0]    = Trade.Size;
     TimesSales.col[0]      = BidAskColor;
       
     if Time.Setting>0 then
     begin 
   
      if Time.Setting>1 then
         time.string = FormatTime ("HH:mm:ss",el_timetodatetime_s (time_s)) else
         time.string = FormatTime ("mm:ss",el_timetodatetime_s (time_s));

      TimesSales.str[0]= time.string +Spaces(2)+ TimesSales.str[0] ;   
   end; //if Time.Setting>0 then
 
   // set text strings, locations, color

      for ii=1 to MyRows 
      begin   
         text_setsize      (TimesSales.txt[0],      text.size);   
         text_setstring      (TimesSales.txt[ii],   " "+TimesSales.str[ii-1]+ "  ") ;
         text_setcolor      (TimesSales.txt[ii],   TimesSales.col[ii-1]);
         Text_SetLocation_s    (TimesSales.txt[ii],     d, MyPlottime, TextHighVal-((TextHighVal-TextLowVal)/rowz)*(ii+1));
         
         if Show.Block and     TimesSales.block[ii-1]>=Block.AlertTradeSize then
            Text_Setborder (TimesSales.txt[ii], true) else
            Text_Setborder (TimesSales.txt[ii], false) ;
      end; //for ii=1 to MyRows
      
end; //if Trade.Size >= SizeFilter then       

end; //LastBarOnChart_s


Attachments
T+S TEST1.png
T+S TEST1.png (67.02 KiB) Viewed 1728 times

User avatar
TJ
Posts: 7157
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2042 times

Re: Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bi

Postby TJ » 24 Nov 2012

Well done! Thanks for sharing.

dvk1970
Posts: 2
Joined: 16 Aug 2012

Re: Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bi

Postby dvk1970 » 29 Nov 2012

I compiled it in the editor and it gives errors. What am I doing wrong or should the code be tweaked?

User avatar
TJ
Posts: 7157
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2042 times

Re: Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bi

Postby TJ » 29 Nov 2012

dvk1970 wrote:I compiled it in the editor and it gives errors. What am I doing wrong or should the code be tweaked?

Please post a screen shot of your error message. There are many possibilities for error, without the error message, there is no way to know what is wrong.

Which version of MultiCharts are you using?
Who is your datafeed?

dominiquedru
Posts: 1
Joined: 30 Nov 2012

Re: Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bi

Postby dominiquedru » 30 Nov 2012

hello compilation error.
ifftext unconnu function.
thank you for your help.

http://sendbox.fr/pro/co2y02yelrmc/ScreenShot001.gif.html

SP
Posts: 453
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 283 times

Re: Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bi

Postby SP » 30 Nov 2012

Attached the pla for V2.

Added input UseData2asPrice. If set to false the study only uses one datastream getting the price from the "last" quote field. With this option the study only gets live data, no historical values.

Make sure to decrease the Bar Spacing as much as possible to reduce the text moving around.
Attachments
t+s.pla
(20.95 KiB) Downloaded 519 times

User avatar
arnie
Posts: 1593
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 511 times

Re: Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bi

Postby arnie » 18 Dec 2012

Beautiful work SP.

Have you ever thought create the option to aggregate similar ticks?

SP
Posts: 453
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 283 times

Re: Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bi

Postby SP » 18 Dec 2012

arnie,

take a look a this thread:
viewtopic.php?f=5&t=11196

I will post a updated version for Volume Breakdown too when the next beta is out.

SP
Posts: 453
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 283 times

Re: Times&Sales for MC 8.5 using Breakdown "Ask Traded vs Bi

Postby SP » 16 Jul 2013

MC 8.7 changed the plot and calculation of Cumulative Delta 1 Tick Charts, it is no longer plotted as histogram oscillating around Zero like at the picture in post #1.

If you still want to use the code at post #6 (even if MC 8.7 now has a native Times and Sales) you need to change all lines with
close data(AskBid.DataSeries)
to
close - close [1]


Return to “User Contributed Studies and Indicator Library”