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