Passing Series into custom function/indicator

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #193018 quote
    dburgh
    Participant
    Average

    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

    #193022 quote
    robertogozzi
    Moderator
    Master

    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.

    #193054 quote
    dburgh
    Participant
    Average
    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.
    #193056 quote
    robertogozzi
    Moderator
    Master
    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.
    #193057 quote
    dburgh
    Participant
    Average
    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.
    #193075 quote
    JS
    Participant
    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.

    #193081 quote
    dburgh
    Participant
    Average
    I am afraid you’re right. Thank you.
    #193082 quote
    robertogozzi
    Moderator
    Master
    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.
    #193109 quote
    dburgh
    Participant
    Average
      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.
    #193111 quote
    robertogozzi
    Moderator
    Master
    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.
    #193112 quote
    dburgh
    Participant
    Average
      Ok, hopefully series input parameters are supported soon. Thank you.
    #193120 quote
    robertogozzi
    Moderator
    Master
    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)
    #193123 quote
    robertogozzi
    Moderator
    Master
    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…).
    #193124 quote
    dburgh
    Participant
    Average
      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.
    #193126 quote
    robertogozzi
    Moderator
    Master
    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.
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

Passing Series into custom function/indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
dburgh @dburgh Participant
Summary

This topic contains 14 replies,
has 3 voices, and was last updated by robertogozzi
3 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/10/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...