Collecting and Plotting Ticks v2

The program below shows how you can collect tick-based data and display it in its own pane.

Note: There was an error in the earlier version that is fixed, v2 only collect ticks if the Total Volume for the day changes. Feel free to report any further problems (on the main list or by private email please).

The example shows Last, Bid and Ask price. You can repeat the four lines that plot each price as often as you like to add other types of tick-based data. A typical chart looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function TickArray2( Ticker, TickPriceName, NumTicks, Reset )
{
Tickprice = GetRTDataForeign( TickPriceName, Ticker );
PrevVolume = Nz( StaticVarGet( "~TotalVolume_" + TickPriceName ) );
TotVol = GetRTDataForeign( "TotalVolume", Ticker );
StaticVarSet( "~TotalVolume_" + TickPriceName, TotVol );
 
if ( TotVol > PrevVolume )
{
InIndicator = Status( "Action" ) == 1;
StaticVarSet( "LastQuotePrice", TickPrice );
TA = Null;                                             // Clear Output array
NumTicks = Min( BarCount - 2, NumTicks ); // Stay in array size
for ( n = NumTicks; n >= 0; n-- )
{
T = StaticVarGet( TickPriceName + ( n - 1 ) );
StaticVarSet( TickPriceName + n, T );
TA[ BarCount - 1 - n] = T;     // Fill return array
}
StaticVarSet( TickPriceName + 0, TickPrice );
TA[BarCount-1] = TickPrice;
}
else
{
TA = Null;                                                // Clear Output array
NumTicks = Min( BarCount - 2, NumTicks );     // Stay in array size
for ( n = NumTicks; n >= 0; n-- )
{
T = StaticVarGet( TickPriceName + n );
TA[ BarCount - 1 - n] = T;     // Fill return array
}
}
return TA;
}
 
function TickArraysReset( TickPriceName )
{
global NumTicks;
StaticVarSet( "Init"+TickPricename, 1 );
for ( n = NumTicks; n >= 0; n-- ) StaticVarRemove( TickPriceName  + n );
}
 
GraphXSpace = 20;
TickerName = Name();
Clear        = ParamTrigger( "Clear Tick Charts", "CLEAR" );
NumTicks    = Param( "Tick-Array Length", 20, 3, 1000, 1 );
 
TickPriceName = "Last";
if ( IsNull( StaticVarGet( "Init"+TickPriceName ) ) OR Clear ) TickArraysReset( TickPriceName );
TA = TickArray2( TickerName, TickPriceName, NumTicks, Clear);
Plot( TA, TickPriceName, 1, 1);
 
TickPriceName = "Bid";
if ( IsNull( StaticVarGet( "Init"+TickPriceName ) ) OR Clear ) TickArraysReset( TickPriceName );
TA = TickArray2( TickerName, TickPriceName, NumTicks, Clear);
Plot( TA, TickPriceName, 4, 1);
 
TickPriceName = "Ask";
if ( IsNull( StaticVarGet( "Init"+TickPriceName ) ) OR Clear ) TickArraysReset( TickPriceName );
TA = TickArray2( TickerName, TickPriceName, NumTicks, Clear);
Plot( TA, TickPriceName, 5, 1);
1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 4.10 out of 5)
Loading ... Loading ...

Comments are closed.