New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.
Options

Proper use of "OR" function?

Seems to be an error in the way I'm using the "OR" function .... I get a different number of returns for this scan depending on the order sequence of the scan statements within the scan below .... anyone see what I am doing incorrectly .... thanks.

[[favorites list = 126] or [favorites list = 195] or [favorites list = 115]] and
[weekly sma(20,volume) > 500000] and [weekly ema(50,volume) > 500000] and

[[weekly williams %R(30) X weekly ema(10,Williams %R(30))] and
[weekly ema(10, Fast stoch %K(30,1)) > weekly ema(10, slow stoch %K(30,1))] and
[Weekly RSI(20) > weekly ema(10,RSI(20))] OR

[weekly williams %R(30) > weekly ema(10,Williams %R(30))] and
[weekly ema(10, Fast stoch %K(30,1)) X weekly ema(10, slow stoch %K(30,1))] and
[Weekly RSI(20) > weekly ema(10,RSI(20))] OR

[weekly williams %R(30) > weekly ema(10,Williams %R(30))] and
[weekly ema(10, Fast stoch %K(30,1)) > weekly ema(10, slow stoch %K(30,1))] and
[Weekly RSI(20) X weekly ema(10,RSI(20))]]

Best Answer

  • Options
    markdmarkd mod
    edited February 2016 Answer ✓
    Hi @Abuelo I've reformatted the text and added additional brackets to group the "and" statements within the second OR statement. I didn't check it for logic, just syntax.

    I picked up this method of formatting "or" statements (each bracket on an empty line) from other contributors here. Also, to my eyes, starting each line with "and" makes it a little easier to read. I used to do it your way, too, but I think it was @gord who persuaded me this way is clearer.

    This passes syntax:

    [ // begin OR-1
    [favorites list = 126] or [favorites list = 195] or [favorites list = 115]
    ] // end OR-1

    and [weekly sma(20,volume) > 500000] and [weekly ema(50,volume) > 500000]

    and

    [ // begin OR-2

    [ // begin AND group 1

    [weekly williams %R(30) X weekly ema(10,Williams %R(30))]
    and [weekly ema(10, Fast stoch %K(30,1)) > weekly ema(10, slow stoch %K(30,1))]
    and [Weekly RSI(20) > weekly ema(10,RSI(20))]

    ] // end AND group 1

    OR

    [ // begin AND group 2

    [weekly williams %R(30) > weekly ema(10,Williams %R(30))]
    and [weekly ema(10, Fast stoch %K(30,1)) X weekly ema(10, slow stoch %K(30,1))]
    and [Weekly RSI(20) > weekly ema(10,RSI(20))]

    ] // end AND group 2

    OR

    [ // begin AND group 3

    [weekly williams %R(30) > weekly ema(10,Williams %R(30))]
    and [weekly ema(10, Fast stoch %K(30,1)) > weekly ema(10, slow stoch %K(30,1))]
    and [Weekly RSI(20) X weekly ema(10,RSI(20))]

    ] // end AND group 3

    ] // end OR-2

    NOTE: I think you have to add "weekly" in front of "Fast Stoch" and "Slow Stoch" and "RSI", etc. within the ema( ) functions - so for instance

    weekly ema(10, Fast stoch %K(30,1))

    should be

    weekly ema(10, weekly Fast stoch %K(30,1))

    Otherwise, I believe you are getting the weekly ema of the default daily indicator values.

Answers

  • Options
    Thanks markd .... immediate problem solved .... but don't understand a couple of the additions/changes you made .... will get back with you on those.
  • Options
    MarkD .... Thanks .... yes, you solved my immediate problem .... and I now understand the syntax for multiple OR / AND statements thanks to your detailed response .... really appreciate it.
Sign In or Register to comment.