Page 1 of 1

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

Posted: 18 Nov 2012
by SP
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


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

Posted: 24 Nov 2012
by TJ
Well done! Thanks for sharing.

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

Posted: 29 Nov 2012
by dvk1970
I compiled it in the editor and it gives errors. What am I doing wrong or should the code be tweaked?

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

Posted: 29 Nov 2012
by TJ
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?

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

Posted: 30 Nov 2012
by dominiquedru
hello compilation error.
ifftext unconnu function.
thank you for your help.

http://sendbox.fr/pro/co2y02yelrmc/Scre ... 1.gif.html

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

Posted: 30 Nov 2012
by SP
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.

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

Posted: 18 Dec 2012
by arnie
Beautiful work SP.

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

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

Posted: 18 Dec 2012
by SP
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.

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

Posted: 16 Jul 2013
by SP
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]