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)]]]
0
Comments
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.
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.
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)]]
[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
[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]]
[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"
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]]]
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?
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.