General time series functions
Time series.AboveLine
[Values;Slopes;Period]→Time series
Values (time series): a time series of end points of a straight line.
Slopes (time series): a time series of straight line slopes (difference per period).
Period (number).
Result: The AboveLine
function checks whether all values in a time series lie above a geometric line. The line is given at each point in time by its respective end points and gradients. The result is a Boolean time series.
Time series.all
[period]→Time series
Period (number).
Result: The All
function returns "True" if all values in<period>are "True" (as a time series).
Corresponds to: Count[$period]=$period
Time series.AllTimeHigh
[start date]→Time series
Start date (date).
Result: The AllTimeHigh
function returns the time series of the total maxima from the start date. By default, the start date is the left-hand edge of the chart.
Time series.AllTimeLow
[start date]→Time series
Start date (date).
Result: The AllTimeLow
function returns the time series of the total minima from the start date. By default, the start date is the left-hand edge of the chart.
Time series.BelowLine
[Values;Slopes;Period]→Time series
Values (time series): a time series of end points of a straight line.
Slopes (time series): a time series of straight line slopes (difference per period).
Period (number).
Result: The BelowLine
function checks whether all values of a time series in a period are below a geometric line. The line is given at each point in time by its respective end points and gradients. The result is a Boolean time series.
Time series.betaFactor
[time series;date;period]→number
Date (date).
Period (number).
Result: The BetaFactor
function returns the beta factor between the two time series over<period>periods at<date>.
Time series.BetaFactorZR
[Time series;Period]→Time series
Period (number).
Result: The function returns the beta factor between the two time series over <period> periods as a time series.
Time series.BorderLine
[Period;Above]→Multiline time series(Value, Gradient, Offset1,Offset2)
Period (number).
Above (Boolean[True]).
Result: The BorderLine
function calculates a geometric straight line at each point in time that lies on two peaks within a time period. A multiline time series is supplied which contains the following sub-series:
- Y-values of the straight line
- Gradients of the straight line
- In each case the offset to the first (more recent) peak
- The offset to the second peak in each case
Time_series.breaks
[line;top_to_bottom;Yoffset]→Time_series
Line (number|time series): Comparative value(s).
Top_to_Bottom (Boolean[False]): For "true" breakthroughs from top to bottom, otherwise from bottom to top.
Yoffset (percentage [0]): Tolerance, i.e. time series must be at least <Yoffset> above or below the line.
Result: The Breaks
function provides a Boolean time series that shows whether the time series breaks through the line at any point in time.
Condition:Time series.ConsecutiveCount
[period]→Time series
Period (number).
Result: The ConsecutiveCount
function evaluates the length of uninterrupted sequences of "true" or "false" values in truth value time series. The result is a time series that provides the length of the past value chain. The sign indicates whether it was a "true" chain (>0) or a "false" chain (<0). The evaluation is limited to one period, i.e. for longer chains the maximum length corresponding to the period is shown.
Time series.count
[period]→Time series
Period (number).
Result: The Count
function returns the time series that contains the number of values of the predecessor at each point in time within the<period>last periods that are different from zero (="True").
TimeSeries.CrossesLine
[Values;Slopes;Period;Top_to_Bottom]→TimeSeries
Values (time series): a time series of end points of a straight line.
Slopes (time series): a time series of straight line slopes (difference per period).
Period (number).
Top_to_Bottom (Boolean[False]).
Result: The CrossesLine
function checks whether the values of a time series cross a geometric line that is given at each point in time by their respective end points and slopes. The result is a Boolean time series.
Time series.cumulate
[start date]→Time series
Start date (date).
Result: The Cumulate
function returns the time series that contains the sum of all values of the predecessor since <start date> at each point in time. By default, the <start date> is the left-hand edge of the chart.
Time series.cut
[Period;Share;Above]→Time series
Period (number).
Share (number): A percentage (0..1).
Above (Boolean[False]).
Result: The Cut
function returns "False" for<above>: A time series that provides a (minimum) value for each point in time from the <period> previous periods, so that many values of the period are smaller according to the required proportion. For <above>="True" vice versa, i.e. a lower limit is provided.
Example: The Cut
function can be used, for example, to cut off statistical outliers or peaks:
$z:=Close;
$z.Min
[$z.Cut
[30;0,95]
Time series.GapDown→Time series
Result: The GapDown
function returns a condition time series that indicates a downward gap (GapDown). A downward gap occurs when the current high is below the previous period's low. The low consolidations of the input time series are used as a basis, so that the function is used in the combination Prices.GapDown
, for example.
Time series.GapUp→Time series
Result: The GapUp
function provides a condition time series that displays an upward gap (GapUp). An upward gap occurs when the current low is above the previous period high. The high consolidations of the input time series are used as a basis, so that the function is used in the combination Prices.GapUp
, for example.
Time series.GreaterAll
[Comparator;Period;YReplacement]→Time series
Comparator (number[0]): Comparative figure.
Period (number[0]).
YOffset (number[0]): Tolerance. Factor by which the result is multiplied.
Result: The GreaterAll
function returns the "Greater" function (>) for time series in the<period>.
Time series.GreaterEqualAll
[Comparator;Period;YReplacement]→Time series
Comparator (number[0]): Comparative figure.
Period (number[0]).
YOffset (number[0]): Tolerance. Factor by which the result is multiplied.
Result: The GreaterEqualAll
function returns the "GreaterEqual" function (>=) for time series in the<period>.
Time series.correlation
[Time series;Date;Period]→Number
Date (date).
Period (number).
Result: The Correlation
function returns the correlation value between the two time series over<period>periods at<date>as a percentage with a base of 1 (i.e. a number between -1 and 1).
Time series.LessAll
[Comparator;Period;YReplacement]→Time series
Comparator (number[0]): Comparative figure.
Period (number[0]).
YOffset (number[0]): Tolerance. Factor by which the result is multiplied.
Result: The function returns the "smaller" function (<) for time series in the <period>.
Time series.LessEqualAll
[Comparator;Period;YReplacement]→Time series
Comparator (number[0]): Comparative figure.
Period (number[0]).
YOffset (number[0]): Tolerance. Factor by which the result is multiplied.
Result: The LessEqualAll
function returns the "less equal" function (<=) for time series in the<period>.
Time series.LRSlope
[period]→Time series
Period (number).
Result: The LRSlope
function provides the time series of the absolute period slopes of the regression line over the last<period>values.
Time series.MA
[period;method]→Time series
Time series.GD
[Period;Method;XVset;Yset]→Time series
Period (number).
Method (GD type [linear]).
XVset (number[0]): Number of periods by which the result is to be shifted.
YShift (percentage [0]): Factor by which the result is to be multiplied.
Result: The MA
and GD
functions provide the moving average of the time series over<period>periods according to the corresponding method.
Value:Number.MakeZ
[Interval]→Time series
Interval (number): The consolidation period for the time series: 1=daily, 7=weekly (Monday-Friday), 30=monthly (1st-31st), other N=N-day period; see also Securities.Close
in the section Query course time series.
Result: The MakeZ
function returns a generated constant time series for the value and interval.
Function.MapZ
[Forward;ForwardRemove;CommonTimes;TimeSeries;OtherTimeSeries]→TimeSeries
Effect: The MapZ
function executes a function for all values of one or more time series and compiles the results back into a time series. The evaluation is carried out once for each period, starting with the oldest values. How many periods are included is determined by the required results period, e.g. the display period in a chart.
Time series, OtherTime series[Time series]: Up to 10 time series in total, but at least one time series evaluated in parallel. MapZ
transfers values of the type NumberWithTime to the function; the timestamp contains the date of the current period.
Function: A function that maps a number of numerical parameters corresponding to the number of time series parameters back to a number (Booleans and date values are also permitted as results).
Fast forward (number[0]): Number of periods to be provided by the time series parameters for the calculation of the time series in addition to the required result period. For example, when calculating a 25-period average, 24 periods would be required to obtain the first correct average value.
RemoveLead (Boolean[True]): Determines whether the results of the calculation in the lead time period should be excluded from the result.
CommonTimes (Boolean[True]): In the event that several time series are evaluated, this parameter determines whether only periods in which all time series parameters contain values should be evaluated (CommonTimes="True"). In the other case, all time points of all time series are analyzed together. For those time series that currently have value gaps, an n/a value is passed to the function. It is then the task of the evaluation function to carry out special handling, e.g. with the 'Default' function.
Result: The MapZ
function provides the time series of the evaluation results.
Example 1: MapZ(#Plus;;;_;High;Low) adds the high and low time series of a security, i.e. returns High+Low.
Example 2: The main purpose of MapZ
is the combination with anonymous functions that carry an internal state. For example, it enables the calculation of an exponential moving average using the formula:
$gd:=NA; $w:=0,2; $Timeseries:=Close; #[]($gd:=(1-$w)$gd.Default
[object]+ $wobject;$gd).MapZ
[10000;No;_;$Timeseries]
Time series.MaximalDrawDown
[period]→Time series
Period (number): Period specifies the number of values taken into account, i.e. the last <period>-1 periods are taken into account.
Result: The MaximalDrawDown
function returns the time series that indicates the maximum loss in percent at any point in time at any entry time within the period.
Time series.maximum
[From;To]→NumberwithTime
From (date [beginning of year from <to>]).
Until (date [current date]).
Result: The Maximum
function returns the maximum of the time series values between<From>and<To>.
Time series.minimum
[From;To]→NumberwithTime
From (date [beginning of year <to>]).
Until (date [current date]).
Result: The Minimum
function returns the minimum of the time series values between<From>and<To>.
TimeSeries.NegativeElasticity
[TimeSeries2;Date;Periods]→Number
Date (date).
Periods (number).
Result: The NegativeElasticity
function provides the negative elasticity (with regard to the return ratio to the benchmark).
Time series.NewHigh
[period:number]→Time series
Result: The NewHigh
function returns a 0/1-value time series that indicates whether the time series argument (high consolidation) has reached a new period high.
Time series.NewLow
[period:number]→Time series
Result: The NewLow
function returns a 0/1-value time series that indicates whether the time series argument (low consolidation) has reached a new period low.
Time series.norm
[standardization date]→Time series
Standardization date (date [left edge of chart]).
Result: The Norm
function returns the time series of the percentage price (value) increases related to the time series value on the <normalization date>.
TimeSeries.OptimalTradeSystemState
[StartDate;Expenses;Slippage;Interest]→TimeSeries
Start date (date).
Expenses (number).
Slippage (number).
Interest (number).
Result: The OptimalTradeSystemState
function returns a state time series (1=Long, 0=Out, -1=Short) for an optimal trading system from the start date. All price movements that show a profit above expenses, slippage and interest are exploited.
Time series.periodmaximum
[period:number]→Time series
Result: The PeriodMaximum
function returns the time series that contains the maximum value of the<period>preceding periods at each point in time.
Example: (1,4,3,2,1).PeriodenMaximum
[2]→ (-,4,4,3,2)
Time series.periodminimum
[period:number]→Time series
Result: The PeriodMinimum
function returns the time series that contains the minimum value of the<period>preceding periods at each point in time.
TimeSeries.PeriodIndex
[Back:Boolean]→TimeSeries
Result: The PeriodIndex
function provides a period count of a time series, upwards or downwards depending on the<Back>parameter. The position of period 0 is undefined.
Time series. PeriodsSinceAllTimeHigh
[start date]→Time series
Start date (date).
Result: The PeriodsSinceAllTimeHigh
function returns the time series that specifies the number of past periods in each period since the last all-time high was reached.
Time series. PeriodsSinceAllTimeLow
[start date]→Time series
Start date (date).
Result: The PeriodsSinceAllTimeLow
function returns the time series that indicates the number of past periods in each period since the last all-time low was reached.
Time series.PeriodsSinceHigh
[period:number]→Time series
Result: The PeriodsSinceHigh
function returns the time series that contains the number of past periods since the period high occurred at each point in time. Cf. period maximum.
Condition: TimeSeries.PeriodsSinceFirst
[period:number]→TimeSeries
Result: The PeriodsSinceFirst
function is similar to the following PeriodsSinceLast
function, with the difference that it does not measure the distance to the last occurrence of "True" (≠0) within<period>periods, but to the first occurrence.
Condition: Time series.PeriodsSinceLast
[period:number]→Time series
Result: The PeriodsSinceLast
function is used to evaluate the last time the condition was fulfilled in the condition time series. The result is the number of past periods since this point in time. A maximum of <period> periods are looked into the past. If the condition is not fulfilled for <period> or more periods, the result is <period>.
Time series.PeriodsSinceLow
[period:number]→Time series
Result: The PeriodsSinceLow
function returns the time series that contains the number of past periods since the low point of the period occurred at each point in time. Cf. period minimum.
Time series.PeriodYields
[LogReturns]→Time series
LogReturns (Boolean[False]).
Result: The macro PeriodYields
returns the time series of the period yields, i.e. the quotient of two consecutive values of the input time series. The values in the results time series are percentages based on 1. If the "Logarithmic returns" parameter ("LogReturns") is set to "True", the values are logarithmized.
TimeSeries.PositiveElasticity
[TimeSeries2;Date;Periods]→Number
Date (date).
Periods (number).
Result: The PositiveElasticity
function provides the positive elasticity (with regard to the return ratio to the benchmark).
Time series.product
[start date]→Time series
Start date (date).
Result: The Product
function returns the time series that contains the product of all values of the predecessor since <start date> at each point in time. By default, <start date> is the left-hand edge of the chart.
Candidate:TimeSeries.Rank
[TimeSeriesList;Up]→TimeSeries
Up (Boolean[True]): Determines whether the ranking is based on the highest or lowest values. Up="True" means: the minimum has rank 0 and the maximum has the highest rank.
Result: The Rank
function carries out a ranking list evaluation of the candidate. In each period, its ranking position among the values of the same period in the time series list is calculated. These ranking positions are delivered as numerical values in a time series as a result. The values of the result time series therefore run between 0 and the length of the time series list.
Time series.redefine
[Type:Line type[Default];Consolidation:Consolidation type[Default];Replacement time series]→Time series
Result: The Redefine
function returns a time series in which the parts given by type and consolidation are replaced by the replacement time series. This function can be used to create freely defined candlestick charts, i.e. candlestick charts in which open/high/low/close are each represented by different values. Indicators that expect variable prices as input can also be applied to such time series compilations.
Time series.regressionAlpha
[time series2;date;period]→number
Date (date).
Period (number).
Result: The RegressionAlpha
function returns the regression alpha between the two time series over<period>at<date>.
TimeSeries.regressionBeta
[TimeSeries2;Date;Period]→Number
Date (date).
Period (number).
Result: The RegressionBeta
function returns the regression beta between the two time series over<period>at<date>.
Time series.regressionSlope
[period:number]→Time series
Result: The RegressionSlope
function provides the time series of the relative daily slopes of the regression line over the last<period>values.
TimeSeries.ScaleYields
[LogReturns;Consolidation;Period2Year]→TimeSeries
LogReturns (Boolean[True]).
Consolidation (time series consolidation type): Daily, weekly or monthly consolidation.
Period2Year (Boolean[True]).
Result: The ScaleYields
function returns a time series of percentages with a base of 1. The values are regarded as period returns and rescaled to annual returns. The "LogReturns" parameter determines whether the period returns are treated as linear or logarithmic returns. If <Period2Year> is "True" (default), the period returns are annualized (scaled up), otherwise the input values are treated as annual returns and scaled down to the given consolidation.
Time series.some
[period]→Time series
Period (number).
Result: The Some
function returns "True" if one of the values in<period>is "True" (as a time series).
Corresponds to: Count[$period]>0
Time series.hr
[period]→Time series
Period (number).
Result: The Std
function returns the standard deviation of the time series over<period>periods as a time series. The values of the resulting time series are percentages based on 1.
Time series.StdN
[period]→Time series
Period (number).
Result: The StdN
function returns the standard deviation (in the variant for complete samples: Factor (1/n)) of the time series over <period> periods as a time series. The values of the resulting time series are percentages based on 1.
Time series.StdNormal
[Period;Scaling;Scaling factor]→Time series
Period (number).
Scaling (Boolean).
Scaling factor (number).
Result: The StdNormal
function returns the standard deviation (in the variant for samples: Factor (1/n-1)) of the time series over <period> as a time series. If <scaling>="True", scaling is performed depending on the consolidation with root(252/n) for consolidation on an n-day basis, with root(52) for consolidation on a weekly basis and with root(12) for consolidation on a monthly basis. Alternatively, a fixed scaling factor can be specified. Normal distribution is assumed for the scaling.
Time series.sum
[period]→Time series
Period (number).
Result: The Sum
function returns the time series that contains the sum of the values of the predecessor of the<period>preceding periods at each point in time.
Time series.sum
[From;To]→number
From (date [beginning of year from to]).
Until (date [current date]).
Result: The Sum
function returns the sum of the time series values between<From>and<To>.
TimeSeries.TangentLine
[Period:Number;Above:Boolean(True)]→MultilineTimeSeries(Gradient, Offset)
Result: The TangentLine
function calculates a geometric straight line at each point in time A, which ends at the value of point A and is above or below the time series on the preceding time period. A multiline time series is delivered, which on the one hand provides the gradients of these straight lines and on the other hand the number of past periods since the line was touched (offset).
TimeSeries.TrendAnalysisAssessment
[Tolerance;Period;Course_correction;Weight_rectangles;Weight_triangles;Weight_head_shoulder;Weight_resistance_lines;Weight_support_lines]→TimeSeries
Result: The TrendAnalysisAssessment
function provides the time series of the trend analysis assessments on the input time series for the corresponding parameters. A multi-line time series with two lines is supplied. The first is the line of valuations, the second is a Boolean line that indicates whether a formation has been broken. The trend analysis provides a signal if the valuation is greater than one and at least one formation has been broken (see section Trend analysis).
Time series.TurnAround
[Threshold;Falling]→Time series
Threshold (number [0]).
Falling (Boolean[False]): Reversal of the condition to falling after rising values above the <threshold>.
Result: The TurnAround
function returns a Boolean time series that marks the points at which the input time series below the<threshold>begins to rise again after values that fall from period to period.
Time series.VarBefore
[Offsets:Time series;Period]→Time series
Period (number).
Result: Similar to the Before
function, the VarBefore
function returns a time series of values from the past. The index under which a point in time is looked up is variable, i.e. it is specified in the form of an offset time series. The offset size is limited to a specified period and may not assume negative values. See also functions such as PeriodsSinceFirst
and similar, which provide offset time series.
Time series.VarGDExp
[Weights;Start date]→Time series
Weights (time series or number).
Start date (date).
Result: The VarGDExp
function calculates a variable exponential moving average, whereby the variable weight values are defined in the form of a further time series. The weights should assume values of 0..1. The start date is the start time of the GD calculation and is by default the left edge of the chart.
Time series.vola
[period;annualization factor]→Time series
Period (number).
Annualization factor (figure [252]): The number of trading days per year.
Result: The Vola
function provides the volatility of the time series over<period>periods as a time series. The values of the time series provide percentages based on 100 (i.e. 2% are output as 2).
Time series.volatility
[period;date;annualization factor]→number
Period (number).
Date (date).
Annualization factor (figure [252]): The number of trading days per year.
Result: The Volatility
function returns the volatility of time series over<period>periods at<date>. The function returns a percentage with a base of 1 (i.e. 2% is output as 0.02).
Beispiel: Heikin-ashi Charts
Heikin-ashi charts are special candlestick charts that are intended to illustrate trends.
The following formula should be displayed in the chart as a candlestick chart:
$Close:= Close;
$Open:= Open;
$High:= High;
$Low:= Low;
$haClose:= ($Open+$High+$Low+$Close)/4;
$lasthaOpen:= na;
$haOpen:= MapZ(#[](
$lasthaOpen:=if($lasthaOpen=na; object; ($lasthaOpen+object)/2); $lasthaOpen);500;false;_;$haclose.Before[1]);
$haHigh:= Max($high;Max($haOpen;$haClose));
$haLow:= Min($Low;Min($haOpen;$haClose));
MakeZ(0) {irrelevant} .Redefine["price"; "open";$haOpen] .Redefine["price"; "high";$haHigh] .Redefine["price"; "low";$haLow] .Redefine["price"; "close";$haClose]