Summarize Times and Sales

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

Summarize Times and Sales

Postby SP » 08 Aug 2013

In contrast with the built in functionality "Aggregate Similar Ticks" this version also resets if we have the same price but the traded volume changes from traded at bid to traded at ask and vice versa.

Code: Select all

{Summarize Times and Sales based on the Breakdown by "Ask Traded vs Bid Traded" functionality. Version 1 by SP for Multicharts forum.

In contrast with the built in functionality "Aggregate Similar Ticks" this version also resets if we have the same price but the traded volume
changes from traded at bid to traded at ask and vice versa.

Chart Settings
- Open a Cumulative Delta Chart, Breakdown by "Ask Traded vs Bid Traded" , Break on Session unchecked, Build Volume On "Trade Volume, Data Range "1 Day Back"
- Recommended is to use a 1 min chart

Known bugs:
- As it uses the quote field last for the price data there is no 100 % accuracy
- Starts correct with the first price change
}
input:

Rows               ( 30 ),          // 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
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
VisualSum      ( true ),     // Shows the summarized volume as histogram based on the multiplier   
Multiplier      ( 5 ),        // Use higher settings for deeper markets like the ES, Bonds, FESX
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
 
var:
MyDecimalPlaces    ( 0 ),
ii                ( 0 ),
Delay             ( 0 ),
TextHighVal       ( 0 ),
TextLowVal       ( 0 ),
MyRows           ( 0 ),
rowz             ( rows+1),
MyPlottime        ( 0 ),
time.string       (" "),
Price.txt          (" "),
//TypeOfTrade       (" "),
intrabarpersist TypeOfTradeNum    ( 0 ),
intrabarpersist prevTypeOfTradeNum ( 0 ),
intrabarpersist NumOfTrades      ( 0 ),
intrabarpersist MyPrice       ( 0 ),
intrabarpersist prevMyPrice    ( 0 ),
intrabarpersist AClose       ( 0 ),
intrabarpersist prevAClose       ( 0 ),
intrabarpersist Trade.Size       ( 0 ),
intrabarpersist CumTradeSize   ( 0 ),
intrabarpersist BidAskColor       ( 0 ),
intrabarpersist SalesSumStars       ( "" );

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

once
begin
   MyRows = Maxlist (Rows, 100 );
     for ii=0 to rows
     begin
          ConsolVB.txt[ii]   = text_new_self_s(d,time_s,c,"text string");
      text_setstyle      ( ConsolVB.txt[ii],1,0);
      text_setcolor      ( ConsolVB.txt[ii],getbackgroundcolor);
      text_setfontname   ( ConsolVB.txt[ii],Text.Font);
   end; //for ii=0 to rows
   
   If Auto.Decimals = true then
      MyDecimalPlaces = Log(PriceScale) / Log(10) else MyDecimalPlaces = Dec.Places;     
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  (ConsolVB.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   (ConsolVB.txt[0],date,MyPlottime ,TextHighVal);   
    end; //If   (GetAppInfo (18) = 1   and ComputerDateTime > Delay ) then

   // Price string
     MyPrice = Last; 
     AClose = Close;
   // TradeSize
     Trade.Size= absvalue (AClose - prevAClose );
     if AClose >prevAClose then TypeOfTradeNum = 1   else TypeofTradeNum =  -1;
     
     If TypeOfTradeNum <>prevTypeOfTradeNum or MyPrice <>prevMyPrice then CumTradeSize = 0;
     If TypeOfTradeNum <>prevTypeOfTradeNum or MyPrice <>prevMyPrice then NumOfTrades = 0;
     
     CumTradeSize = CumTradeSize + Trade.Size;
     NumOfTrades  = NumOfTrades +1;
     
     //set the colors based on at bid or at ask
     if TypeOfTradeNum = 1 then BidAskColor=Ask.Color else BidAskColor=Bid.Color;
     
     if CumTradeSize <= Multiplier                       then  SalesSumStars    = "      *" else
     if CumTradeSize >  Multiplier     and CumTradeSize <=  2*Multiplier     then  SalesSumStars    = "     **" else
     if CumTradeSize >  2*Multiplier     and CumTradeSize <=  4*Multiplier     then  SalesSumStars    = "    ***" else
     if CumTradeSize >  4*Multiplier     and CumTradeSize <=  6*Multiplier     then  SalesSumStars    = "   ****" else
     if CumTradeSize >  6*Multiplier     and CumTradeSize <=  10*Multiplier     then  SalesSumStars    = "  *****" else
     if CumTradeSize >  10*Multiplier     and CumTradeSize <=  20*Multiplier     then  SalesSumStars    = " ******" else
                                               SalesSumStars    = "*******" ;   
     
     
   If (TypeOfTradeNum <>prevTypeOfTradeNum or MyPrice <>prevMyPrice ) then
   begin
   
     // update the rows and colors
     for ii = MyRows  downto 1
     begin
          ConsolVB.str[ii]      = ConsolVB.str[ii-1];
          ConsolVB.col[ii]      = ConsolVB.col[ii-1];
          ConsolVB.block[ii]    = ConsolVB.block[ii-1];
     end; //for ii = MyRows  downto 1
    end;         
     //price string
     
     Price.txt   = numtostr (Last,MyDecimalPlaces);
 
     // fill the first array with the latest values   
     ConsolVB.str[0]      = Price.txt + Spaces(3)+numtostr (CumTradeSize ,0)+Spaces(5 - StrLen(numtostr (CumTradeSize ,0)))
                    +" ("+numtostr(NumOfTrades,0)+") "+ Spaces(5 - StrLen(numtostr (NumOfTrades,0))) ;//+TypeofTrade;
     ConsolVB.block[0]    = Trade.Size;
     ConsolVB.col[0]      = BidAskColor;
       
     if Time.Setting>0 then
     begin
   
      if Time.Setting>1 then
         time.string = FormatTime ("HH:mm:ss",computerdatetime) else 
         time.string = FormatTime ("mm:ss",computerdatetime);

      ConsolVB.str[0]= time.string +Spaces(2)+ ConsolVB.str[0] ;   
   end; //if Time.Setting>0 then
   if VisualSum then ConsolVB.str[0]= SalesSumStars    +Spaces(2)+ ConsolVB.str[0] ;   

   // set text strings, locations, color

      for ii=1 to MyRows
      begin   
         text_setsize       (ConsolVB.txt[0],    text.size);   
         text_setstring     (ConsolVB.txt[ii],   " "+ConsolVB.str[ii-1]+ "  ") ;
         text_setcolor      (ConsolVB.txt[ii],   ConsolVB.col[ii-1]);
         Text_SetLocation_s (ConsolVB.txt[ii],   d, MyPlottime, TextHighVal-((TextHighVal-TextLowVal)/rowz)*(ii+1));
         
      end; //for ii=1 to MyRows
     
      prevAClose       = Aclose;   
      prevMyPrice       = MyPrice ;
      prevTypeOfTradeNum    = TypeOfTradeNum ;
//end;   

end; //LastBarOnChart_s



Last edited by SP on 08 Aug 2013, edited 1 time in total.

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

Re: Summarize Times and Sales

Postby SP » 08 Aug 2013

T+S Summarize
Image
Attachments
T+S Summarize.jpg
T+S Summarize
T+S Summarize.jpg (83.5 KiB) Viewed 1203 times


Return to “User Contributed Studies and Indicator Library”