Applying standard functions to arrays

Questions about MultiCharts and user contributed studies.
trader0311
Posts: 50
Joined: 28 Sep 2014
Has thanked: 7 times

Applying standard functions to arrays

Postby trader0311 » 13 Aug 2015

Hi,

I would like to add values to an array based on whether a condition is true. So only when the condition is true, do I want to add any values into an array.

Then, once the values are stored in the array, I would like to apply some of the standard analysis techniques to that conditional data array. The problem I seem to be encountering when I review a printlog of the array values is that when my condition is not true and when new bars are forming, that a "0" is stored in the array. Obviously storing a series of zeros followed by a series of numbers and that sequence repeating itself will really throw off any analysis technique that you would apply to the array.

So I would like to have an analysis of my array done using some simple code like the following:

RSI(myarray, 20). So the function needs to look back at the last 20 values in the array, but I can't have it looking at the zero's. So I either need to change my code so that the only thing that is stored in the array are the actual conditional datapoints I entered or I need to somehow remove the zeros from the array before I analyze it.

Any insights you could provide would be most helpful. I am really stuck on this.

Thanks!

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Applying standard functions to arrays

Postby TJ » 14 Aug 2015

Hi,
::
RSI(myarray, 20). So the function needs to look back at the last 20 values in the array, but I can't have it looking at the zero's. So I either need to change my code so that the only thing that is stored in the array are the actual conditional datapoints I entered or I need to somehow remove the zeros from the array before I analyze it.

Any insights you could provide would be most helpful. I am really stuck on this.

Thanks!
If it is an infrastructure problem, you will need an infrastructure solution.
If it is a logic problem, you will need a logic solution.
If it is a fundamental problem, you will need a fundamental solution.
If it is a technical problem, you will need a technical solution.
If it is a coding problem, you will need a coding solution.


What do you think the problem is?

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Applying standard functions to arrays

Postby JoshM » 15 Aug 2015

I would like to add values to an array based on whether a condition is true. So only when the condition is true, do I want to add any values into an array.

Then, once the values are stored in the array, I would like to apply some of the standard analysis techniques to that conditional data array. The problem I seem to be encountering when I review a printlog of the array values is that when my condition is not true and when new bars are forming, that a "0" is stored in the array. Obviously storing a series of zeros followed by a series of numbers and that sequence repeating itself will really throw off any analysis technique that you would apply to the array.
There's no way around this I'm afraid. Each variable (and thus each array element) has a default value (with 0 for numbers, as you already encountered). It's not possible to have an empty value in an array (not in PowerLanguage at least).

What you could do, however, is filling the array conditionally. So instead of creating an array with values like 2, 0, 4, 5, 0, 0, 0, and 2, you only put values in the array when the condition is true (to end up with 2, 4, 5, and 2), and then perform your analysis technique on those values.

(Assuming your analysis technique can deal with that).
RSI(myarray, 20). So the function needs to look back at the last 20 values in the array, but I can't have it looking at the zero's. So I either need to change my code so that the only thing that is stored in the array are the actual conditional datapoints I entered or I need to somehow remove the zeros from the array before I analyze it.
Sorry for the bad news, but pretty much all of the standard functions don't accept arrays as parameters. So if you want to proceed with this approach, any standard function that you'll use will need to be recoded.

trader0311
Posts: 50
Joined: 28 Sep 2014
Has thanked: 7 times

Re: Applying standard functions to arrays

Postby trader0311 » 17 Aug 2015

Thanks for the insights Josh.

I will see if I can get the values added in conditionally. If I am able to do that....will using standard functions with the conditional array values work or do I will need to recode the standard function.

I have used standard variables as inputs into standard functions. Instead of using an array, I wonder if I could use the conditional statement to add the conditional values into a variable (instead of an array). If that would be possible, then perhaps that variable could be used as an input into a standard function?

I appreciate your insights.


Return to “MultiCharts”