Custom Indiator with Series Input
Forums › ProRealTime English forum › ProBuilder support › Custom Indiator with Series Input
- This topic has 17 replies, 2 voices, and was last updated 5 years ago by dburgh.
-
-
01/04/2019 at 6:26 PM #88008
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
01/04/2019 at 7:28 PM #88012PRT 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:
1MyIndicator = 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:
1MyIndicator[5] //value retained 5 bars agoYou’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).
01/04/2019 at 7:32 PM #88013No, 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
01/04/2019 at 7:43 PM #88014Ok, 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!
01/04/2019 at 7:47 PM #88015I 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
01/04/2019 at 8:00 PM #88016Then 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.
01/04/2019 at 8:07 PM #8801701/04/2019 at 8:16 PM #8801801/04/2019 at 8:34 PM #88019Here is the reference I found ising the search box https://www.prorealcode.com/documentation/customclose/
01/04/2019 at 8:39 PM #88020Yeah, I found that too. It is only 1-2 lines and not very useful. Can it work like this…
123456789101112131415// FUNCTIONvalue1 = 2value2 = customclosereturnVar = 0if value2[0] > value2[value1] thenreturnVal = 1endifreturn returnVal123456789// STRATEGYindicator1 = close + open * 2indicator2 = Close - low * 2.5mycustom1 = CALL customIndicator[2](indiator1)mycustom2 = CALL customIndicator[2](indicator2)Would this work?
01/05/2019 at 12:56 AM #88024I 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.
01/05/2019 at 1:14 AM #88025CUSTOMCLOSE 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.
01/05/2019 at 12:35 PM #88036The 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
01/05/2019 at 1:24 PM #88039Indicators ARE like functions, though PRT only supports one data type and NO arrays.
Try to use something like this:
MyIndicator1234//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…):
MyStrategy1x = MyIndicator[20,2.7](customclose)01/05/2019 at 1:26 PM #88040Parameters must be written within brackets.
Edit: I had to edit my previous post, you may want to re-read it.
-
AuthorPosts
Find exclusive trading pro-tools on