I have a lot of time on my hands to run random studies during the day to see what happened the last time a particular setup appeared. Sometimes my studies yield interesting looks at the market and other times, meh, not so much.
Yesterday I noticed that the e-mini S&P had closed lower than it opened on six of the last seven days. I wasn’t sure how to code that question into thinkorswim (my trading platform) so if the code looks a little more verbose than it should be, well then feel free to help me shorten it by adding a comment below.
First, the code:
# random thoughts
def a1 = close < open;
plot b1 = if a1 is true then 1 else 0;
def a2 = close < open;
plot b2 = if a2 is true then 1 else 0;
def a3 = close < open;
plot b3 = if a3 is true then 1 else 0;
def a4 = close < open;
plot b4 = if a4 is true then 1 else 0;
def a5 = close < open;
plot b5 = if a5 is true then 1 else 0;
def a6 = close < open;
plot b6 = if a6 is true then 1 else 0;
def a7 = close < open;
plot b7 = if a7 is true then 1 else 0;
plot roosevelt = (b1 + b2 + b3 + b4 + b5 + b6 + b7) > 5;
AssignPriceColor(if roosevelt is true then color.blue else Color.CURRENT);
AddLabel(yes, if roosevelt is true then “true” else “”, color.yellow);
Now the picture:
I was expecting to see that perhaps the bears were adding selling pressure on the occurrences, and that the sellers would have eventually driven the market lower after each one of these 6-of-7 occurrences (marked with yellow arrows on the chart). Wrong. Each occasion saw the bulls roaring back from swing lows; the one exception being that time just before the big drop during the summer of 2015. I only ran the study with a look-back of three years, so if you want to run it for longer just copy and paste the code and see what you get.
Cheers, and stay safe out there.