Page 1 of 1

Using regex in functions?

Posted: Sat Dec 24, 2016 10:24 pm
by hjelmstade
Hi Earik,

Is it possible to use regex inside a function?

In the Livermore ATS I shared earlier, I had to run regex in the indicator and pass the result into the function as I kept getting a "cannot divide by 0" error when I tried to include regex in a function.

This is the code I was trying to run.


if (pat({5}, low < low[1] {1}, low >= low[1] and high > high[1] {1:8} ~~ minimize)) {
long_found = true;
long_start = get_regex_start(2);
}

if (pat({5}, high > high[1] {1}, high <= high[1] and low < low[1] and close < open {1:8} ~~ minimize)) {
short_found = true;
short_start = get_regex_start(2);
}


If you cannot use regex inside a function, can you explain why? Does it have to do with referencing bars during the pattern search which is done in a way not possible on the function level?

Thanks!
hjelmstade

Re: Using regex in functions?

Posted: Tue Dec 27, 2016 7:31 pm
by earik
The regex stuff might have a bug or two. I think I broke it a few years ago, and I have to go through to debug it. Honestly, it was low on my to-do list because I didn't think anyone ever used it (or tried using it), so congrats on that front at least. ;)

Not sure why it gave that error in the function. It should be able to be put anywhere. If you are seeing that, try messing around with the reference bars setting for the function itself. Make it match the indicator version, and see if that changes anything.

Earik

Re: Using regex in functions?

Posted: Tue Dec 27, 2016 11:43 pm
by hjelmstade
Ok, I'll keep playing with it. Not a big deal if I have to just pass the result to a function if there is a bug.

I have to say, I was really impressed when I discovered qscript had regular expressions so its too bad they are not more widely used :/

For anyone else reading this, regex is incredibly powerful so you should really explore this great feature if you have time.

Thanks!