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.

Bracketing

I have finally gotten pretty close to finishing up my scans, or, I hope that I am near the end. My scans are complex and very long so I am going to reduce and simplify them in order to ask a few bracketing questions. Below passes the syntax test and it produces good results but I think that it's bracketing might not be correct and might actually miss a good signal from time to time. Maybe I need to add a set of brackets around the first paragraph? Maybe I need to add a set of brackets around the whole thing, one left bracket at the head of the first paragraph and maybe one at the end of the last sentence?

[Favorites list is 2] and [[Weekly MACD Hist(12,26,9) > 1 Week ago MACD Hist(12,26,9)] or [MACD Hist(48,104,36) > 1 Day ago MACD Hist(48,104,36)] or [Weekly MACD Line(12,26,9) > 1 Week ago MACD Line(12,26,9)]] and [Open < Close] and [[1 Day ago MACD Hist(6,9,0) < 0.0] or [1 Day ago MACD Hist(12,26,9) < 0.0]]

and [[[MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]]

or [[MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)]]

or [[MACD Line(12,26,9) < 0.0] and [MACD Signal(12,26,9) > 0.0]]

or [[MACD Line(12,26,9) < 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]]

or [[MACD Line(12,26,9) < 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)]]]

Comments

  • markdmarkd mod
    edited December 2021
    The editor only checks that there are an equal number of left and right brackets (and they don't break up a complete statement). It does not check whether the placement makes sense because it doesn't know what you are trying to accomplish.

    For me, this is much too complicated to work out. But, if you need to keep straight all the different parts of this complicated scan, I would suggest you document (explain to yourself) in comments in plain english what each line or group of lines is supposed to capture (in general terms - like, "get weekly and daily Hist set up", "get crossovers above zero", "get crossovers below zero", etc.)

    Also, where you use "or" statements, I would suggest putting the opening bracket for each group of statements alone by itself on one line, and the closing bracket also by itself on another line. Maybe label the opening and closing "or" brackets - like [ // "or" group 1 begin, then ] // "or" group 1 end, or something along those lines.

    Professional programmers always comment for a reason. It makes things clearer while you are writing the program, and its a reminder what you were thinking when you come back weeks or even years later. In the long run, it saves more time than it takes.

    I know commenting an spacing takes up a lot of room but it might clear things up for you. You can always remove the comments and spacing once you are happy with the results.

    P.S. I think a long time ago I offered a suggestion to break up the scan into simpler components and run them separately, but obviously that suggestion didn't take. I still think its a good idea. But, people think differently and I understand that. Also, do you have a chart style (or more than one chart style) that verifies your results? I ask because the scan requires different time frames which you can't put on one chart style, and I wonder how you check your results.
  • Thanks again. Yes, you made several suggestions a while back but they take up a tremendous amount of space so I have resisted them. Even now, I am using more than 8 scans that I have broken down into smaller pieces / scans because of a lack of space. I don't need a description any longer, I know what I want. For some crazy reason, I still don't seem to be able to keep a grasp on where to place brackets properly. Thanks
  • markdmarkd mod
    edited December 2021
    OK. Basically, there are only two uses for brackets - to enclose a statement, and to enclose the alternative statements of an "or" condition into a group so they are considered together, but separately from the rest of the scan. So basically, an "or group" is treated as a single result just as a solo statement would be.

    So, an (obvious) example of brackets in a statement:

    and [MACD Line(12,26,9) < 0.0]


    An example of brackets enclosing a series of "or" alternatives you want grouped together:

    // begin scan

    // some code preceding the "or" statement

    and

    [ // begin or group 1


    [ statement 1]

    or

    [statement 2]

    or

    [ statement 3]



    ] // end or group 1


    You can nest an "or" statement inside another or statement. If you indent the lines of the nested "or" it helps keep them visually separate from the "or" statement that contains it:

    // code preceding the nested or statement

    and

    [ // begin or group 1


    [ statement 1]

    or

    ..... [ // begin nested or (which is statement 2 of the containing "or" group 1

    .......... [ nested statement 1]

    ..... or

    .......... [ nested statement 2]

    ..... ] // end nested or

    or

    [statement 3]

    ] // end or group 1


    (Note: the series of dots ..... in the nested or statement are there to illustrate indenting - this forum's editor doesn't allow blanks at the start of a line, but the Stockcharts editor does, so you don't need the dots there.)

    The easy way to keep track of brackets is to add them in FIRST with nothing between them - label them for what will go between them, (e.g. cross below above zero or cross abv below zero) - THEN put in the statement(s) that go between them.

    P.S. There is a third use for brackets - to group arithmetic operations within a statement to guarantee the order of execution, but that doesn't apply here.
  • [Favorites list is 2] and [Weekly MACD Hist(12,26,9) > 1 Week ago MACD Hist(12,26,9)] or [MACD Hist(48,104,36) > 1 Day ago MACD Hist(48,104,36)] or [Weekly MACD Line(12,26,9) > 1 Week ago MACD Line(12,26,9)]] and [Open < Close] and [[1 Day ago MACD Hist(6,9,0) < 0.0] or [1 Day ago MACD Hist(12,26,9) < 0.0]

    and [[MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) < 0.0] and [MACD Signal(12,26,9) > 0.0]

    or [MACD Line(12,26,9) < 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]

    or [[MACD Line(12,26,9) < 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)]]
  • markdmarkd mod
    edited December 2021
    I think your first group of or statements were missing an opening or bracket. But maybe you mean something else. I can't be sure.

    [Favorites list is 2]

    and

    [ // begin or 1

    // test for at least one rising Hist
    [Weekly MACD Hist(12,26,9) > 1 Week ago MACD Hist(12,26,9)]

    or [MACD Hist(48,104,36) > 1 Day ago MACD Hist(48,104,36)]

    or [Weekly MACD Line(12,26,9) > 1 Week ago MACD Line(12,26,9)]

    ] // end or 1

    and [Open < Close]

    and

    [ //begin or 2

    // test for Hists below 0

    [1 Day ago MACD Hist(6,9,0) < 0.0]

    or [1 Day ago MACD Hist(12,26,9) < 0.0]

    ] // end or 2

    and

    [ // begin or 3

    // test for Line and Signal level combinations

    [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) < 0.0] and [MACD Signal(12,26,9) > 0.0]

    or [MACD Line(12,26,9) < 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]

    or [[MACD Line(12,26,9) < 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)]

    ] // end or 3
  • I know that it's hard to know what I have in my mind. I think it might be easier if I shorten some of it, at least the first paragraph just for easier understanding. I want the scan to consider the first paragraph first. If everything in the first paragraph is met, then consider one of the next 5 paragraphs. So, if everything in the first paragraph is good and one of the next paragraphs is also met, it triggers a signal. BTW, favorites list 2 has only one symbol in it, SPX.

    [Favorites list is 2] and [Weekly MACD Hist(12,26,9) > 1 Week ago MACD Hist(12,26,9)]

    and [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) < 0.0] and [MACD Signal(12,26,9) > 0.0]

    or [MACD Line(12,26,9) < 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) < 0.0]

    or maybe I need to enclose the whole thing like this. I added one left hand bracket at the beginning and one right hand bracket at the end.

    [Favorites list is 2] and [[Weekly MACD Hist(12,26,9) > 1 Week ago MACD Hist(12,26,9)]

    and [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) < 0.0] and [MACD Signal(12,26,9) > 0.0]

    or [MACD Line(12,26,9) < 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) < 0.0]]
  • markdmarkd mod
    edited December 2021
    OK. See if this does it. At the end, I'm assuming you can use brackets to group "and" conditions within an "or" statement. I don't think I've ever tried to do it. It should pass syntax (assuming no typos), but I don't know if the scan engine will support it.


    [Favorites list is 2]

    // begin "first paragraph" - all have to be true, so use only "and" statements, no "or" statements


    and [Weekly MACD Hist(12,26,9) > 1 Week ago MACD Hist(12,26,9)]

    and [MACD Hist(48,104,36) > 1 Day ago MACD Hist(48,104,36)]

    and [Weekly MACD Line(12,26,9) > 1 Week ago MACD Line(12,26,9)]

    and [Open < Close]

    and [1 Day ago MACD Hist(6,9,0) < 0.0]

    and [1 Day ago MACD Hist(12,26,9) < 0.0]

    // end "first paragraph" required conditions


    and

    [ // begin "or" selections - this will execute if all preceding conditions are true;
    // at least one of the statements below has to be true to make a hit.

    [ // begin selection 1
    [MACD Line(12,26,9) > 0.0]
    and [MACD Line(12,26,9) > MACD Signal(12,26,9)]
    ] // end selection 1

    or
    [ // etc.
    [MACD Line(12,26,9) > 0.0]
    and [MACD Line(12,26,9) < MACD Signal(12,26,9)]
    ]

    or
    [
    [MACD Line(12,26,9) < 0.0]
    and [MACD Signal(12,26,9) > 0.0]
    ]

    or

    [
    [MACD Line(12,26,9) < 0.0]
    and [MACD Line(12,26,9) > MACD Signal(12,26,9)]
    ]

    or

    [ // begin last selection
    [MACD Line(12,26,9) < 0.0]
    and [MACD Line(12,26,9) < MACD Signal(12,26,9)]
    ] // end last selection

    ] // end "or"
  • [Favorites list is 2] and [Weekly MACD Hist(12,26,9) > 1 Week ago MACD Hist(12,26,9)]

    and [[[MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]]

    or [[MACD Line(12,26,9) > 0.0] and [MACD Line(12,26,9) < MACD Signal(12,26,9)]]

    or [[MACD Line(12,26,9) < 0.0] and [MACD Signal(12,26,9) > 0.0]]

    or [[MACD Line(12,26,9) < 0.0] and [MACD Line(12,26,9) > MACD Signal(12,26,9)]

    or [MACD Line(12,26,9) < 0.0]]]
  • Are you getting the result(s) you expect?
  • GM. It's a difficult thing to explain this way. I'm not sure yet if I am getting the correct results. It's hard to understand unless you've tried it too. Apparently, what I want to do is fairly complicated to scan. And, as you know, my scans have been very long as well. I was trying to use only 4 very long scans but I finally gave it up and now have about 10 fairly long scans. I try to back test as far back as possible, and SC allows only about 10 years back testing because the scan engine doesn't work beyond that. And, some of the weekly indicators don't work in the scan engine that far back in time and I never know for sure if I am getting correct results or not until I accidentally stumble across the problem and somehow figure it out. It took me a couple of years to figure out that MACD can be tested in a scan as far back as about 10 years but Stochastics will work only as far back as about 2 years. For several years I assumed that all of the indicators worked the same in the scan engine and it drove me crazy. It took me several years to figure out that weekly indicators like the MACD sometimes update during the day and other times it won't update until after the close while the chart that I am watching is updating every few minutes or every few seconds. It's been exhausting. So, every so often, I when I am worn out, I'll ask you a question like this one. As far as the bracketing goes, In addition, the back testing is all manual, you have to manually enter the year, the month and the day and them click run for every single day in a year, so it takes an awful long time to truly test a scan. I am fairly sure now that if my bracketing isn't correct, the scan engine won't give me a bad unintended signal, it will miss a good valid signal because incorrect bracketing will tell the scan engine to apply some unintended criteria where I didn't want to use it.
  • As far as the scan above, once I feel certain that I have the bracketing correct, I will add three more just like it with the criteria in the first paragraph being different in each of them. MACD above zero and above signal line, MACD above zero and below signal line. MACD below zero and below signal line and MACD below zero and above signal line. Those are the four basic initial criteria.
  • Again, thanks for trying. I understand that I am trying to do more than SC intended or imagined but I think it can be done pretty well. It may not be perfect, but I think that it's capable of giving me results that are good enough. The hard part for me is deciding when it's good enough. Every so often, I learn something new about the scans. I just started trying to use their alerts and it helps take off the mental pressure of trying to run all of my scans every few minutes. As you know, I don't get email alerts, it's not working for me, but the text messages seem to be working well so far. BTW, the scans are profitable as is but I feel certain that I have mistakes in the bracketing.
  • Well, I admire your persistence.

    Does the bracketing in my last example not do what you described (first paragraph all lines true, then at least one of the next five)?

    The next question I would ask, if you have only symbol ($SPX) why not just read the chart with a check list of requirements -or is that the process you want to automate?
  • At first blush what you gave me does work and does produce expected signals. Most of the complications will come when I try to add all of my other ideas to a scan or in more than one scan. Trying to string together four of those little scans above into one scan and then trying to add several one-off kind of situations is very time consuming to test over a period of time and for all the reasons I mentioned above. With just those four listed above I have 32 different scenarios. 16ea long and 16ea short. When I add more criteria to keep me in a certain trade longer when certain conditions are present or shorter when opposite conditions are present and I add about 20 more one-off situations they can become very long and complicated for my little pea brain. I believe that i have figured out that my wording is pretty good but the bracketing is not correct sometimes. I have long entry scans, long profit scans, short entry scans and short profit scans. There is some over-lap but trying to watch this all day long is very boring and very difficult. I could get rid of a whole lot of stuff and make the scans much, much simpler but they won't produce as much profit either. I could also wait to enter or exit until the next day so that I have all night after the close to make decisions but the gaps are awful and they hurt my results a whole lot. I will get the best results entering a long position as soon as I get one my long signals and I have about 50 of them now. However, when I take a long profit I have to wait until after the market closes which means I can exit and take profits within the first 15 minutes of the close or I wait until the next day. I absolutely have to wait until the next day to enter a short position. Way too many times i will get a short signal during the day just to see it evaporate right at the close and I mean during the last few secons sometimes. I use BB, moving averages and MACD as the backbone so there is a whole lot to keep up with. The alerts have been wonderful so far. They seem to send me a signal within a few minutes of the scan recognizing one of the signals
  • My back testing proves my scans to be correct 7 out of 10 times over a year or maybe even a little better over a multi year time frame with winners being much larger than my losses. I have approximately a dozen trades in a year with an average loss of about 2% and the largest loss less than 8%. It's worth the effort because I don't think the pros can get even close to as good. I am trading real money so for me it's a serious thing.
  • It sounds like you are getting there. But there is a lot to juggle. The trick may be to visualize the whole thing at once. You might try printing things out separately, then cutting and pasting the physical pieces of paper - or, grouping them in, say, envelopes of different sizes or doing something with index cards. Keeping it all straight in the scan workbench window is quite a chore. Maybe write it on a word processor first if you have, then cut and paste into the workbench window. Or, work it out in outline in plain english first on big sheet of kraft paper so you are not limited by page length in seeing the finished product. Just some ideas. Good luck!
  • Yes, thank you. I do a version of just what you describe by creating spaces between expressions etc. I think that was one of your suggestions and it helps a great deal to see it in an over all kind of way. Every time I think that I have the bracketing just right, something happens and then I am not confident in what I have done with them. Dang it. I do feel like I am making progress but it's excruciatingly slow. Even if my bracketing is not correct, I still get enough signals to make a very good return each year but it can be better I believe.
  • "I have long entry scans, long profit scans, short entry scans and short profit scans."

    I'm not sure how deeply you can nest "or" statements, but I think you would want a top level skeleton something like this:

    [favorites list is 2]

    and

    [ // top level or bracket - embraces long and short entry/exit options

    [ // LONG ENTRY - embraces all long entry set ups

    ...

    ] // END long entry

    or

    [ // LONG EXIT - embraces all long exits

    ...

    ] // END long exit

    or

    [ //SHORT ENTRY

    ...

    ] // END short entries

    or

    [ // SHORT EXIT

    ...


    ] // END short exits


    ] // end top level


    For each ... substitute [ [ ] or [ ] or [ ] ... ] // set up 1, etc.

    Again it would be helpful to do this on a word processor, especially if it allows color fonts. Or you could alternate font types or sizes or bold or italics for each group (long entry bold italic, long exit bold; short entry regular italic, short exit regular), etc.
Sign In or Register to comment.