RS_Average (Function)
The RS_Average function has been designed for use with intraday charts only, and *must* be called in conjunction with the RS_DailyDataArray function. The RS_DailyDataArray function extracts daily data from intraday data and makes it available to subsequently called functions like RS_Average that use that daily data.
This function returns the simple average of the most recent NumDays elements in the RowToAvg row of the DataArray.
Syntax
RS_Average(RowToAvg, NumDays, Offset, DataArray, Index)
Returns (Double)
The simple average of the most recent NumDays elements in the RowToAvg row within the DataArray. Note that DataArray is typically an output parameter of the RS_DailyDataArray function.
Parameters
|
Name |
Type |
Description |
|
RowToAvg |
Numeric |
Specifies the row of the DataArray that contains the daily data to be averaged. Should be a whole number in the 1-to-12 range. |
|
NumDays |
Numeric |
The number of days to be used in the function calculation. Should be <= MaxNumDays (see DataArray parameter below). |
|
Offset |
Numeric |
This should be a non-negative whole number. If this is 0, the most recent NumDays, not including the current day, will be used; if this is 1, the most recent NumDays, not counting the current day or the previous day, will be used; and so on. (Note: Make sure to pass in NumDays + Max Offset into the NumDays input for the RS_DailyDataArray function.) |
|
DataArray |
Numeric |
An array that contains the daily data to be used. This is an output of the RS_DailyDataArray function, and in input to the RS_Average function. (Note: The calling routine must declare the size of this array as 12-by-MaxNumDays, with MaxNumDays >= NumDays + Max Offset.) |
|
Index |
Numeric |
The number of the DataArray column in which the data for the current day is being loaded. This is an output of the RS_DailyDataArray function, and an input to the RS_Average function. |
Remarks
This approach is intended primarily for use with RadarScreen indicators, where only one data stream can be used; in charting, similar calculations can be performed more easily using a multi-data approach.
Example
inputs: NumDays(3), RowToAvg(6), Offset( 0 );
variables: NumDaysPlusOffset(NumDays + Offset), Index(0);
arrays: DataArray[12,100](0), SubArray[3](0);
Value1 = RS_DailyDataArray(NumDaysPlusOffset, DataArray, Index, SubArray);
if CurrentBar = 1 or Date <> Date[1] then
Value2 = RS_Average(RowToAvg, NumDays, Offset, DataArray, Index);
Plot1(Value2) ;