4 Replies Latest reply on Jan 15, 2014 1:29 AM by Aakash Dhondiyal

# Function and Calculations

My Study is work related where i am suppose to create "Parabolic stop and reverse".

I have problem in doing all these, below i have mentioned my queries/questions and the algorithm that requires all collectively.

Question(s): I want to implement a query where

1. My [variable] modifies itself.

2. It will/could create an [New_Variable].

3. It should Call Previous_Values.

I want to process this algorithm:

IF Current_Value of [Variable]  >  Previous_value of [Variable]  Then  [New_variable] = Previous of [New_Variable] + Constant

Else Previous of [New_variable]

END

• ###### 1. Re: Function and Calculations

It would be easier if I can look at your data structure. Can you post a sample packaged workbook?

You need to create some additional calculated fields and a parameter (for the constant value, adds flexibility) for the above algorithm. Like a calculated field for New Variable with formula as

IF [Current Value] > [Previous Value] THEN  [Previous Value] +[Constant Parameter]

ELSE [Previous Value]

END

You may create a parameter with some allowable values that suits you.

• ###### 2. Re: Re: Function and Calculations

Thanks @ manas

Yes i did though of same but problem still persist. I have posted the sample data sheet.

Also, I have tried to do same using R script function.Code is provided below.

SCRIPT_REAL(
' Temp <- function(x){

n <- length(sum(x))
AP <- rep(0.02, n)
for(i in 1:n) {

if( x[i+1] > x[i] ) { AP[i+1] <- 0.02 + AP[i]
if( is.na( AP[i+1]) == "TRUE" ) AP[i+1] <- AP[i]
}
else AP[i+1] <- AP[i]
}

return(AP)
};

Temp(sum(.arg1));'
,[EP])

But it is giving Error.

• ###### 3. Re: Function and Calculations

Can you point out what you want with respect to the sample data? All I see is the close/open prices, what might be your intended output?

• ###### 4. Re: Re: Function and Calculations

I want to create chart using this data.

Chart Name : Parabolic SAR

I am stuck in the recursive process required to work out in this.