NeedForTrade Documentation

PVB (Previous Value Based) Functions

Previous value based (PVB) functions is a type of functions that use value, calculated in previous call to that function to calculate next value (sample 1). The main reason to create and use PVB functions is performance improvement. First parameter of PVB function is always of type FunctionContext. This parameter is generated automatically and must be passed in PVB function call (sample 2).

 

Warning! Previous value based functions must be called on each calculation step as their value depends on previously calculated values.

 

Tip 1: We recommend to call previous value based functions on the top of the calling analysis technique. See warning above.

Tip 2: It's recommended to place PVB abbreviature at the end of previous value based function name.

 

Sample 1: Previous value based function

Description:

Function SummationPVB calculates summary of Length values back, passed by Values parameter. On the first call it calculates summary of Length values back by calling Summation function. On the subsequent calls summary is calculated by using previous summary value.

 

Analysis Technique Type:

Function

 

Analysis Technique Properties:

Name Language Type
SummationPVB CSharp (C#) DoubleFunction

 

References:

Summation function

 

Parameters:

Name Type Reference Default value
Values DoubleSeries False
Length Integer False

 

Variable Store:

Name Type Default value
PreviousSummary DoubleSeries

 

Code:

if ( Values.Count == Length ) //Is it a first pass? -> calculating
                                    first value
{
	Value = Summation(Values, Length);
} 
else // Not a first pass -> Calculating Value, based
    on a previous value
{
	Value = PreviousSummary[1] + Values[0] - Values[Length];
}

PreviousSummary[0] = Value; // Storing calculated value 

 

Sample 2: Previous value based function call

Description:

Function AveragePVB calculates average of summary of Length values back, passed by Values parameter. It uses SummationPVB function to calculate summary of Length values back. Variable store is used to hold

 

Analysis Technique Type:

Function

 

Analysis Technique Properties:

Name Language Type
AveragePVB CSharp (C#) DoubleFunction

 

References:

SummationPVB function

 

Parameters:

Name Type Reference Default value
Values DoubleSeries False
Length Integer False

 

Variable Store:

Name Type Default value
SummationPVBContext FunctionContext 

 

Code:

Value = SummationPVB(SummationPVBContext, Values, Length) / Length;

 

See also Indicator Creation Tutorial, Strategy Creation Tutorial, Function Creation Tutorial.