Custom Indiator with Series Input

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

    Hey,

    Can someone please direct me to where I can read how to create a custom indicator that takes a series (expression) as input? Ideally, I want multiple inputs of different type (double series, int).

    customIndicator[n](series)

     

    Thanks,

    David

    #88012 quote
    robertogozzi
    Moderator
    Master

    PRT only supports one data type, which can de defined as “floating point” in other languages, so you can store there decimal numebers, integers, with no distinction. No alphanumeric data types are supported as aren’t arrays of any kind (as of this version).

    A nice simple example of an indicator is at https://www.prorealcode.com/prorealtime-indicators/ma-lag-reduce-factor/.

    It can be CALLed with:

    MyIndicator = CALL "PRC_MA Lag reduce factor"[20, 1.3](close)

    then you can reference MyIndicator as any common variable, you can use brackets to access past values like in:

    MyIndicator[5]    //value retained 5 bars ago

    You’ll find the PRT manual at https://www.prorealtime.com/en/help-manual/quick-tour (download the PDF file, page 109 will be of much help for indicators).

    #88013 quote
    dburgh
    Participant
    Average

    No, mate. This isn’t my question/concern.

    Let me try with an example:

    indicator1 = close * 3.7

    can I do something like this

    customIndicator[5](indicator1)

    If so, how do I create this customIndicator without hard coding the ‘close *3.7’? Because in another strategy I might want

    indicator2 = open / 2.4

    customIndicator[5](indicator2)

     

    Thanks,

    David

    #88014 quote
    robertogozzi
    Moderator
    Master

    Ok, now I got it.

    Unfortunately it is NOT possible, since there’s no interaction between a strategy and the user, once it’s running.

    You can use prices or time to alter variables, but the user cannot change OPEN to CLOSE  or 3.7 to 2.4 at runtime. You have to hard code any constant value CLOSE will remain CLOSE till you hard code something different!

    It is rumoured version 11 is due this year (nobody knows when), we’ll see what improvements it will bring us. The interaction (input) would be much acclaimed and beneficial for the community!

    #88015 quote
    dburgh
    Participant
    Average

    I dont need to change anything at runtime. I just want a custom indicator that is flexible to take different inputs (or series or whatever we call them).

    So strategy1

    indicator1 = close * 3.7

    myIndicator = CALL customIndicator[5](indicator1)

     

    Then in strategy2

    indicator2 = open * 2.4

    myIndicator = CALL customIndicator[5](indicator2)

     

     

    I just dont want to create two custom indicators and I might have 57 strategies with indicator1, indicator2… indicator57 which would require 57 custom functions.. or 1 custom function that allows for changing the input series.

    If this is not possible, I would surely like to suggest this for v11!

    Thanks,

    David

    #88016 quote
    robertogozzi
    Moderator
    Master

    Then my first answer is correct, you may use as many constants/variables within brackets, data will be returned in one or more variables written to the left of the “=“ operator.

    #88017 quote
    dburgh
    Participant
    Average

    I dont care about the values inside the brackets [ ]

    I want to change the “(close)” in your first answer to “(indicator1)” or “(indicator57)”. How do I create a custom indicator that allows for this?

    #88018 quote
    dburgh
    Participant
    Average

    I actually think the ‘customclose’ is the answer. Do you have any documentation for this? It seems to work!

    #88019 quote
    robertogozzi
    Moderator
    Master

    Here is the reference I found ising the search box https://www.prorealcode.com/documentation/customclose/

    #88020 quote
    dburgh
    Participant
    Average

    Yeah, I found that too. It is only 1-2 lines and not very useful. Can it work like this…

     

    // FUNCTION
    
    value1 = 2
    
    value2 = customclose
    
    returnVar = 0
    
    if value2[0] > value2[value1] then
    
    returnVal = 1
    
    endif
    
    return returnVal
    
    

     

    // STRATEGY
    
    indicator1 = close + open * 2
    
    indicator2 = Close - low * 2.5
    
    mycustom1 = CALL customIndicator[2](indiator1)
    
    mycustom2 = CALL customIndicator[2](indicator2)
    
    

     

    Would this work?

    #88024 quote
    robertogozzi
    Moderator
    Master

    I guess it couyld work, but I can’t write that code due to the very odd values (close + open * 2 is impossible to be reached).

    Moreover, what does the number 2 within brackets mean? Where do you use it?

    To be able to help you I need to know the details, with common data, to write some code.

    #88025 quote
    robertogozzi
    Moderator
    Master

    CUSTOMCLOSE can only be set predefined calculation modes (other than CLOSE), not user-defined ones.

    edit: To write code, please use the <> “insert PRT code” button, to make code easier to read. Thank you.

    #88036 quote
    dburgh
    Participant
    Average

    The beginning of the function should have read value1 = Length (which is preset to 2). It is used as a ‘lookback’ inside the for loop.

    Also, what relevance does it matter if (close + open * 2) can be reached? I am comparing the value of this calculation to its prior self. I’m not hoping price ‘reaches’ it. Regardless, I do not know how we’re 8 messages in and I still am unsure if you understand what I am trying to accomplish.

    Does anyone else know how to create template functions or change the input series? In other programming languages you can create a function like this

    functionName(std::vector<double> values, int length)

    {

    // blah blah

    }

     

    so then I can use this created function, functionName(), on any vector of data. It can be used on close values, open values or even (close + open * 2) values. I am afraid in PRT I must create 3 separate functions. 1 for close, 1 for open and 1 for (close + open * 2), e.g.!

    Thanks

    Another way of asking… If I want to create a function that

    #88039 quote
    robertogozzi
    Moderator
    Master

    Indicators ARE like functions, though PRT only supports one data type and NO arrays.

    Try to use something like this:

    //indicator (function) MyIndicator:
    //input data: a (length)
    //            b (multiplier)
    RETURN average[a](customclose * b)

    then use it within your strategy (setting CUSTOMCLOSE to Open, High, close, and so forth…):

    x = MyIndicator[20,2.7](customclose)
    #88040 quote
    robertogozzi
    Moderator
    Master

    Parameters must be written within brackets.

    Edit: I had to edit my previous post, you may want to re-read it.

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.

Custom Indiator with Series Input


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
dburgh @dburgh Participant
Summary

This topic contains 17 replies,
has 2 voices, and was last updated by dburgh
7 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/04/2019
Status: Active
Attachments: No files
Logo Logo
Loading...