Using regex in functions?

Have a QScript to share, or need help with programming? Post your comment here.
Post Reply
hjelmstade
Posts: 34
Joined: Wed May 18, 2016 6:51 pm
Contact:

Using regex in functions?

Post by hjelmstade » Sat Dec 24, 2016 10:24 pm

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

User avatar
earik
Site Admin
Posts: 474
Joined: Mon Dec 01, 2014 12:41 pm
Contact:

Re: Using regex in functions?

Post by earik » Tue Dec 27, 2016 7:31 pm

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

hjelmstade
Posts: 34
Joined: Wed May 18, 2016 6:51 pm
Contact:

Re: Using regex in functions?

Post by hjelmstade » Tue Dec 27, 2016 11:43 pm

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!

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests