Passing Series into custom function/indicator
Forums › ProRealTime English forum › ProBuilder support › Passing Series into custom function/indicator
- This topic has 14 replies, 3 voices, and was last updated 2 years ago by robertogozzi.
-
-
05/10/2022 at 11:14 PM #193018
Hey,
Is it possible to create a custom indicator/function that accepts an array/series of values? I want to create something like normalize or standardize function where I can pass in any series of values (maybe close, RSI, another function’s values) and run some calculation on the most recent N bars’ values of this input series.
Thanks
05/11/2022 at 3:49 AM #193022Make an indicator (named, say, DoSomething) with a variable named, say, MySeries.
That indicator will do its own calculations, then return one or more values.
Then it can be used in a strategy with the CALL instructions:
1MyVar = CALL DoSomething[MySeries]MyVar will retain the value calculated by the indicator according to MySeries.
Only variables can be used as input and output parameters, not arrays.
05/11/2022 at 11:19 AM #193054Great. How does one declare/define “MySeries” inside the indicator? So that the indicator can do calculations on MySeries. I only see options for Integer, Decimal, Boolean, Moving Average Type. I assumed decimal but does not seem to do what I need.
05/11/2022 at 3:04 PM #193056You simply write the series of your choice within brackets when calling the indicator, such as:
1MyVar = CALL DoSomething[Sma200]it can be any number of your choice, as only real numbers are supported.
05/11/2022 at 3:11 PM #19305705/11/2022 at 8:49 PM #19307505/11/2022 at 11:52 PM #19308105/12/2022 at 6:15 AM #193082There’s no need for special definitions, as only one data type is supported.
Your indicator is simply this:
12//InputDatum = ...Return InputDatum / 2InputDatum is the variable you have to add, in ProBuilder, as an input parameter.
then use it on your strategy:
1234MyVar1 = CALL DoSomething[5]MyVar2 = CALL DoSomething[Sma200]MyVar3 = CALL DoSomething[Rsi14]MyVar4 = CALL DoSomething[close]it will halve whatever number is being input.
Nothing changed since https://www.prorealcode.com/topic/custom-indiator-with-series-input/, despite a function-like support is highly longed for by many.
05/12/2022 at 12:06 PM #193109Can you please show an example on how to create the function with InputDaum as a series not as a scalar value. The options are only [integer, decimal, boolean, SMA type].
Can you please show an example where you can pass in a SERIES and access the series’s historical values inside the indicator. Not just the most recent decimal value.
05/12/2022 at 12:23 PM #193111You can PASS values only by CALLing it within a strategy.
If you want to USE different values other than those built-in to use them on a chart, you can’t.05/12/2022 at 12:28 PM #19311205/12/2022 at 2:10 PM #193120Actually there is something that can partially mimick functions.
This is the DoSomething indicator that uses either RSI or MACD, Multiplting or Dividing it by a factor and returning the calculated result. You can add it to your chart like Rsi or Macd (but you don’t need to add them).
The user can take advantage of the indicator’s settings to set some parameters without having to edit the code each time:
12345678910111213141516171819202122//RsiPeriods = 14//Macd1 = 9//Macd2 = 12//Macd3 = 26//Factor = 2 //Multiplier or Divisor (decimal digits are allowed), set to 1 to mirror the original indicator//UseMACD = 0 //if 0 then use RSI//OPdivide = 0 //if 0 then Multiply//MyRSI = Rsi[RsiPeriods](customclose)MyMACD = Macd[Macd1,Macd2,Macd3](customclose)MyData = MyRSIIF UseMACD THENMyData = MyMACDENDIFIF OPdivide THENIF Factor <> 0 THENResult = MyData / Factor //divideENDIFELSEResult = MyData * Factor //multiplyENDIFRETURN Result AS "MyNewData"You can also call it from a strategy:
12src = close //can be anything elseindicator1 = CALL "DoSomething"[14, 9, 12, 26, 0, 2.0, 0](src)05/12/2022 at 2:14 PM #193123You can add more indicators or different data series, as well as more operations to be undertaken (add, subbtract, square root, or any combinations etc…).
05/12/2022 at 2:15 PM #193124Unfortunately, I don’t want to hard code functions and only have ability to adjust the numeric input parameters to the hard-coded functions. I need to pass a SERIES into a function. This series could be any numeric values. I am not sure the weight you have with PRT dev team, but I highly urge them to add support for this functionality as it would greatly enhance the abilities of the platform.
05/12/2022 at 2:25 PM #193126I have no direct link with PRT. Maybe Nicolas can tell us more.
For sure there will not be any text or string support (at least not within a few years), because that would involve changing massively the whole inner workings, mainly memory management.
-
AuthorPosts
Find exclusive trading pro-tools on