1. 首页
  2. 易语言 - EasyLanguage
  3. 关于“量”Understanding Volume

关于“量”Understanding Volume

本文描述一切关于量的概念、用法和实例。

EasyLanguage Keywords for ‘volume’ and volume related data

  •    Volume
  •    Ticks
  •    UpTicks
  •    DownTicks
  •    DailyVolume
  •    DailyVolumeDn
  •    DailyVolumeUC
  •    DailyVolumeUp
  •    PrevVolume
  •    DailyTrades
  •    DailyTradesDn
  •    DailyTradesUC
  •    DailyTradesUp
  •    PutVolume
  •    CallVolume
  •    OpenInt
  •    PutOpenInt
  •    CallOpenInt
  •    CurrentOpenInt
  •    PrevOpenInt

When executed in EasyLanguage code, each volume related keyword returns a value from the TradeStation market database.  The ‘meaning’ of the returned value depends upon the environment the code runs within and the configuration of that environment.  For example, the keyword volume returns ‘Total Volume for a bar’ when used in the RadarScreen environment.  In a chart environment, the keyword returns ‘total volume’, ‘up volume’, or ‘up ticks’ depending on the bar interval, and ‘For volume, use’ settings.  The following chart outlines the various combinations of settings, keywords and environments:

EasyLanguage keyword ‘uptick’: definition

A tick is an uptick if the last tick on a single tick chart was lower than this tick. If the tick price was the same on the previous tick, then it will be an uptick if the most recent previous tick that is not equal to the current tick price was lower.

The keyword “Ticks” with “Trade Vol” selected shows the number of contracts traded over all transactions during the bar.
The keyword “Ticks” with “Tick Count” selected shows the number of transactions occurring during the bar and ignores the number of contracts traded.

In EasyLanguage, “ticks” = “upticks” + “downticks”. It is sometimes convenient to think of ticks as the number of “prints” (reported trades) on the tape, within a given period of time– without regard to the size (volume) of any of those prints. An “uptick” connotes a higher trade price, relative to the one before it; and a “downtick” connotes a lower trade price, relative to the one before it. A series of prints all at the same price will be counted all as upticks, if the first in the series was a “true” uptick relative to the print before it. Similarly, they will all be counted as downticks, if the first in that series was a “true” downtick relative to the trade before it. “Tick” – used in this context and in EasyLanguage – says nothing about the magnitude of a price change.

One important caveat to keep in mind: If you set your chart on the ‘Format/Symbol/Settings’ page to use ‘Trade Vol’ rather than ‘Tick Count’, these keywords will return VOLUME (UP VOLUME and DOWN VOLUME), not Uptick count and Downtick count.

Finally – and no doubt this is an additional source of confusion – the word “tick” is sometimes used by traders referring to the “minimum price movement” of a given security. Hence if a trader says “I got out 10 ticks below the high of the day”, he is probably saying he got out 10 “minimum price movements” from the day’s high – whatever a minimum price movement is for the given security he is trading. For IBM, 1 “tick” in this sense is .01 (1/100) and for the E-mini it is .25 (1/4). …If it is this you are trying to express in EasyLanguage, you would use ‘MinMove / PriceScale’.

Relationship between UpTicks / DownTicks return values and the Time & Sales window

The keywords UpTicks/DownTicks return ‘UpVolume’/’DownVolume’ when ‘For volume, use:’ is set to Volume.

“UpVolume” is defined as the volume of all ticks where:

  • the price is greater than the previous tick, or
  • the price is the same as the previous tick, and that tick was counted as an uptick

Similarly, “DownVolume” is defined as the volume of all ticks where:

  • the price is less than the previous tick, or
  • the price is the same as the previous tick, and that tick was counted as a downtick

Counting all ticks that were traded at or above the ask as “buys” and all ticks that were traded at or below the bid as “sells” produces results that generally agree with Up Volume and Down Volume, but those criteria do not completely match the definition of Up Volume and Down Volume. Therefore, you cannot reasonably expect the numbers you are getting for buys and sells to match Up Volume and Down Volume. You can identify upticks and downticks in the Time & Sales window by formatting the window, formatting the trade colors, and selecting the Trends tab in the “Conditional” section. Enable trends coloring and then select the colors you want to use for up and down trends. The Time & Sales window will then mark the first in every series of upticks and downticks.

Up and Down Volume are dependent solely on trade price movement and nothing else. To explain the definition further, consider the following series of trades:

100, 101, 101, 101, 103, 102, 101, 101, 101

The first four trades following the initial trade are all considered upticks, because the trade price is higher than the last trade that was different in price. The last four trades are all considered downticks, because the trade price is lower than the last trade that was different in price. Therefore, the volume of the four upticks are counted in Up Volume, and the volume of the four downticks are counted in Down Volume. It does not matter if you would consider one of the upticks to be a sell or one of the downticks to be a buy, as Up and Down Volume are not meant to indicate these. The Up and Down Volume indicators completely match what they were intended to reflect in the Time & Sales window – the trends, as explained previously.

The color scheme displayed in ‘time and sales’ is not reflected in ‘UpTicks/DownTicks’. The keywords UpTicks/DownTicks are calculated by comparing the prior trade to the current trade. If the current trade is higher than the prior trade, the shares are reported in ‘UpTicks’. If the current trade is lower than the prior trade, the shares are reported in ‘DownTicks’. If the current trade is equal to the prior trade price, the trade is added to whatever sum the prior trade was summed in. In contrast, the ‘Time and Sales’ window can color a trade based on a comparison to the bid/ask.

Here is an example ‘minute’. The UpTicks/DownTicks total match that shown in a 1 minute chart of IBM for 9:50 AM (9:49:01 to 9:50:00).

Here is the same minute in a ‘Time and Sales’ window:

Note that the ‘Time and Sales’ presentation does not carry over into the values returned by ‘UpTicks’ and ‘DownTicks’.

‘Tick volume’ in RadarScreen 

The keyword ‘Ticks’ works much differently in RadarScreen versus Charting. In Charting, ‘Ticks’ will return either ‘the total number of shares/contracts traded’, or the ‘total number of trades (regardless the volume)’. In RadarScreen, ‘Ticks’ always returns the ‘total number of shares/contracts traded.’ To obtain ‘total trades’ for a bar, DailyTrades much be used. Following is an example:

MyDailyTrades = DailyTrades ;
MyTicks = DailyTrades – MyDailyTrades[1] ;

Plotting ‘up volume’ in RadarScreen

In RadarScreen, UpTicks returns the total volume of the bar. DownTicks returns 0. You can not use these keywords to determine the up and down bar volumes.

Instead, you can perform a calculation using the DailyVolumeUP and DailyVolumeDN quote fields which return the current up and down daily volume totals of a symbol.

The code needs to keep track of changes to these values when a bar updates. The difference between the current value at the end of a bar and the last bar’s ending value is the bar’s up or down volume.

The indicator code is:

value1 = DailyVolumeUP;
value2 = DailyVolumeDN;
plot1(DailyVolumeUP – value1[1],”UPBarVolume”);
plot2(DailyVolumeDN – value2[1],”DNBarVolume”);
value3 = close;

The line value3 = close is necessary to make RadarScreen update the indicator at the appropriate bar interval. Without a call to at least one ‘historical data’ keyword, the RadarScreen has no way to produce ‘end of bar’ events via EasyLanguage.

Computing the volume average that works correctly for intraday within RadarScreen 

Code example 

Plot1(volume,"volume"); 
plot2(ticks,"ticks"); 
plot3(upticks,"upticks"); 
plot4(downticks,"downticks"); 
if date<> date[1] then 
	begin 
	value1 = volume ; 
	value2 = ticks ; 
	value3 = upticks ; 
	value4 = downticks ; 
	value5 = OpenInt ; 
	end 
else 
	begin 
	value1 = volume + value1 ; 
	value2 = ticks + value2 ; 
	value3 = upticks + value3 ;  
	value4 = downticks + value4 ; 
	value5 = OpenInt + value5 ; 
	end ; 
print(date," ",time," ",plot1," ",plot2," ",plot3," ",plot4," ",OpenInt," ", 
	value1," ",value2, " ",value3, " ", value4," ",value5);

After inserting the code in a RadarScreen (without ‘additional bars’), we can compare the output to the same code on a chart:

The RadarScreen result is simply one line. It reports only one volume number regardless the volume keyword.

When compared to the chart output, one can see that RadarScreen is reporting “this bar’s volume’ regardless the keyword.

To get a ‘daily’ sum that matches the chart output, the indicator’s ‘additional bars’ setting must be larger than 1 day. In this case, we are using 5 minute bars, so 78 additional bars are required. When added, the above code produces a line for each additional bar. The last 3 have been pasted into Excel:

Thus, to get an ‘average’ intrabar volume, use ‘ticks’ on both RadarScreen and Charting, both will return intrabar volume. If the average is ‘simple,’ RadarScreen needs at least the ‘length’ number of additional bars. If the average is ‘exponential’, there needs to be 3 times the ‘Length’ additional bars.

It is important to remember the difference between keywords in RadarScreen and Charting. The above Excel screen shots show the results for ‘keywords’. In RadarScreen, all volume related keywords return ‘this bar volume’. In Charting, daily bars use ‘Volume’ for ‘this bar volume’, but ‘Ticks’ (not volume) returns ‘this bar volume’ on intraday charts.

Volume numbers and Indices 

The daily volume included with $INDU is the NYSE Total Volume (divided by 1000).

The daily volume included with $DJI is the Dow Jones 30 Total Volume (divided by 100).

$INDU & $DJI have identical price data.

S&P 500 daily volume is included with $inx or $spx.x

Volume for $INX can be displayed on daily, weekly, or monthly charts and is updated on an end-of-day basis. Trade volume for $INX cannot be displayed on intraday charts.

Indices sometimes will not represent volume data in the ‘volume keywords’. If this is the case, the volume is often displayed in one or more independent symbols. For example, the $COMPX volume is available when the symbol $TVOLQ is loaded.

Matching daily and intraday volume calculations

Consider the following code:

{ code to show accumulated day volume bar-by-bar}
vars: barnum(0), //bar number
tv(0); //total volume

if barstatus(1)=2 then
   begin
   if date<>date[1] then
       begin
       //new day
       barnum=0;//reset barnumber
       tv=0;//reset volume
       end;
   barnum=barnum+1;
   tv=tv+ticks;//accumulate volume
   print(“barnum:”,barnum:4:0,” v:”,ticks:8:0,//bar volume” tv:”,tv:10:0);//day volume so far
   end;

When the results of these calculations are compared to daily reports, they don’t match.

The difference results from settlement and handling of form T trades which dribble in after the market closes. Intraday data is simply a record of what was reported during the time period in question. Daily data is ‘corrected’.

Intraday and tick charts ignore ‘Form-T report’ and ‘after market’ trading. Daily charts incorporate them. Form T trades can appear in ‘Time and Sales’ at any time, but in this context, we want to focus on the influx of Form-T trades after the market closes. Additionally, ‘after market’ trades can take place on ECNs. They won’t show up on regular session intraday bars, but they will show up in the daily chart.

Consider this example, AFFX at the close on 6/21/05 (chart times are for Texas):

Note that the intraday chart has a close of 51.65. The daily chart has a close of 51.76.

Now, look at a tick chart which includes the post-session Form T trades. I’ve drawn horizontal lines to display the intrabr and daily closes. The purple ticks show up as ‘after market’ trades, though most have a bar-end-time of 15:00, which is ‘within the session’. I’ve drawn a verical trendline through the last 15:00 tick.

To really figure out the situation, we need to see the ‘time and sales’ for the relevant session end (Florida time):

If you look carefully at the time and sales, it seems the ‘real’ close was 51.65 or 51. 64. At 4:00:02, after the last 60 min bar close, there is a 51.76 ‘at ask’ trade. The 51.76 trade shows up on the daily chart.

Matching the cum=cum+ticks to DAILYVOLUME bars 

The quote field ‘DailyVolume’ comes from the same server that produces daily data-streams. That is why they match. Intraday data comes from a different server (and database).

Both servers provide a representation of the trading volume for a given time period, but neither datastream (database) is without data corrections (data busts, Form-T trades, late reports, etc).

Alerting for trades > a certain amount of volume 

You can use the keyword “TradeVolume” to obtain the size of the last trade.

Here’s an indicator written using this keyword that you can use in RadarScreen. The input “AlertVal” sets a threshold, and any trade size greater than AlertVal will trigger the alert. An alert message will be displayed with the symbol name and size of the trade that triggered the alert.

Be sure to enable alerts for this indicator from the Format > Properties window in the EasyLanguage PowerEditor, or by right clicking on the column heading and selecting the desired “Enable alerts” option once the indicator is applied to a RadarScreen quotes page.

inputs:  
     AlertVal( 100 ) ; 
 
variables: 
     Str("") ; 
 
Plot1( TradeVolume ) ; 
 
Str = "TradeSize of " + GetSymbolName + " is " + NumtoStr( TradeVolume, 0 ); 
 
if TradeVolume > AlertVal then 
     Alert(Str) ;

Computing the ‘Average Intraday Volume for a specific ‘Time of Day’

This indicator plots the cumulative intraday volume through the time of each bar (VolSum) and the average cumulative intraday volume through the same time of day (VolSumAvg). This allows the user to compare the day’s volume up to the current time with the average volume of the last N days through the same time of day. An input allows the user to set the number of days of data to average into the VolSumAvg.SD VolSum & Avg

Input: DaysToAvg(3); 
Vars: LenOfDay(0), BarsPerDay(0), VolSumToAvg(0), VolSum(0), VolSumAvg(0); 
 
If BarType = 1 then begin 
	 
	LenOfDay = TimeToMinutes(Sess1EndTime) - TimeToMinutes(Sess1StartTime); 
	BarsPerDay = LenOfDay/BarInterval; 
	VolSumToAvg = 0; 
 
	If Date <> Date[1] then 
		VolSum = Ticks 
	else 
		VolSum = VolSum + Ticks; 
		 
	For Value1 = 1 to DaysToAvg begin 
		VolSumToAvg = VolSumToAvg + VolSum[BarsPerDay*Value1]; 
	end; 
 
	VolSumAvg = VolSumToAvg / DaysToAvg; 
	 
	Plot1(VolSum, "VolSum"); 
	If BarNumber > BarsperDay * DaysToAvg then 
		Plot2(VolSumAvg, "VolSumAvg"); 
 
end;

DaysToAvg
Default = 3
This is the number of days of intraday data, each through the same time of day as the current bar, which will be included in the average.

Plot Descriptions:
The histogram (Plot1, VolSum) is the cumulative volume for the day through that bar. The line (Plot2, VolSumAvg) is the average of the last DaysToAvg days volume through the same time on each of those days.

Notes:
MaxBarsBack should be left on Auto-detect and will equal DaysToAvg x the number of bars per day + 1. Plot1, VolSum, will begin plotting following MaxBarsBack + 1 bars; Plot2, VolSumAvg, will not begin plotting until the day that is 2 x DaysToAvg + 1. Therefore, a very long DaysToAvg will require significant data before calculating and plotting the VolSumAvg.

This indicator was written using Time references to establish the VolSumAvg. The indicator will not be accurate on any symbol that has intraday periods with no trades, and on those few days a year when exchanges close early and on the days immediately following.

Another solution involves the use of arrays:

input: 
	Length(30), 
	StartTime(830) ; 
Array:  
	ThisMinute[400](0), 
	PrevMinute[400](0); 
variables: 
	StartMinute(TimeToMinutes(StartTime)), 
	CurrentMinute(0) ; 
 
CurrentMinute = TimeToMinutes(Time); 
PrevMinute[CurrentMinute - StartMinute] = ThisMinute [CurrentMinute - StartMinute]; 
ThisMinute[CurrentMinute - StartMinute] = PrevMinute[CurrentMinute - StartMinute]*(1 - 1/Length) 
	+ 1/length * Ticks; 
print(CurrentMinute ,StartMinute); 
if CurrentBar > 390*Length then 
	begin 
	Plot1(ThisMinute[CurrentMinute-StartMinute],"AvgVol"); 
	Plot2(Ticks,"Vol"); 
	end ;

Obtaining Volume data via DLL accessing the iEasyLanguage object 

double dMyDLLDouble = 0; //global variable 
 
int __stdcall SetdMyDLLDouble //Set method ( IEasyLanguageObject * ELObjP ) { 
	dMyDLLDouble = ELObjP->UpTicksMD[dataDefault]->AsDouble[0] 
		+ ELObjP->DownTicksMD[dataDefault]->AsDouble[0] ;   
	return 1; 
}

This code also provides an example of how the MD (multi-data) properties can be accessed within a user DLL. The key to this is that the format of the value returned by the property must be specified in the property call. In general, the syntax a call to an MD property is:

ELObjP->PropertyNameMD[enDataStream]->Format[BarsBack]

Thus, for example, the following expression could be used to return the value of the Close of Data2 five bars ago, as a double-precision value:

ELObjP->CloseMD[data2]->AsDouble[5]

Obtaining ‘pre-split’ volume values 

Not at this time.

更新于 2020年5月18日

这篇文章对您有帮助吗?

相关的话题

留言评论