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
Make 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:
MyVar = 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.
Great. 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.
You simply write the series of your choice within brackets when calling the indicator, such as:
MyVar = CALL DoSomething[Sma200]
it can be any number of your choice, as only real numbers are supported.
This is how you call a function from a strategy. I am asking to see how you define the function itself. Please show me the function definition for DoSomething. Let’s say DoSomething just divides all series values by 2.
JSParticipant
Senior
In my opinion, it is not possible what you want because you have to define the input series (close, RSI,—) in the indicator itself.
I am afraid you’re right. Thank you.
There’s no need for special definitions, as only one data type is supported.
Your indicator is simply this:
//InputDatum = ...
Return InputDatum / 2
InputDatum is the variable you have to add, in ProBuilder, as an input parameter.
then use it on your strategy:
MyVar1 = 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.
Can 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.
You 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.
Ok, hopefully series input parameters are supported soon. Thank you.
Actually 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:
//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 = MyRSI
IF UseMACD THEN
MyData = MyMACD
ENDIF
IF OPdivide THEN
IF Factor <> 0 THEN
Result = MyData / Factor //divide
ENDIF
ELSE
Result = MyData * Factor //multiply
ENDIF
RETURN Result AS "MyNewData"
You can also call it from a strategy:
src = close //can be anything else
indicator1 = CALL "DoSomething"[14, 9, 12, 26, 0, 2.0, 0](src)
You can add more indicators or different data series, as well as more operations to be undertaken (add, subbtract, square root, or any combinations etc…).
Unfortunately, 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.
I 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.