Close vs Open For ThinkOrSwim

PonchoMike

New member
VIP
Several years back, I saw a video where someone noted that when the market is bullish, it typically closes higher than it opens. After some thinking, I decided to plot moving averages of the open and closing price on the same chart. I played around with a couple of different moving averages, eventually settling on the 8 and 21 ema. I further refined it by calculating the difference between the two moving averages and making it a histogram.

Below is what the chart looks like The blue line is the exponential moving average of the close, the red line is the moving average of the open. The solid lines are based on the 8 ema, the dashed lines are based on the 21 ema.

The first histogram below the curves is the difference between the open and closing price of the 8 ema, the bottom histogram uses the 21 ema.

You can easily scan for the crossing of the open vs close for either moving average. I use it mostly for confirmation that a trend is changing. I think it could be useful to imbed this as part of another indicator to confirm trend changes.

I also attached a screen shot showing how I create the moving average curves.


1749348623437.png



1749349149743.png
 
here is 1 study that does this,

it is a lower study,
find average of open and close, for 8 and 21
find the difference , subtract open from close, for both
.. plot these 2 lines
draw a histogram for each line,
.. ema8 is cyan , below
.. ema21 is yellow , above
.. the histograms are automatically spaced away from the lines. can adjust the spacing with a factor variable (set to 1.1)

Code:
#close_vs_open_avg
#https://usethinkscript.com/threads/close-vs-open-for-tos.21131/
#Indicator Forums Indicators Custom

declare lower;

def na = double.nan;
def bn = barnumber();
def valid = !isnan(close);

input avg1_type = AverageType.exponential;
input avg1_length = 8;
def avg1o = MovingAverage(avg1_type, open, avg1_length );
def avg1c = MovingAverage(avg1_type, close, avg1_length );
def avg1_diff = avg1c - avg1o;
def x1up = avg1_diff crosses above 0;
def x1dwn = avg1_diff crosses below 0;

input avg2_type = AverageType.exponential;
input avg2_length = 21;
def avg2o = MovingAverage(avg2_type, open, avg2_length );
def avg2c = MovingAverage(avg2_type, close, avg2_length );
def avg2_diff = avg2c - avg2o;
def x2up = avg2_diff crosses above 0;
def x2dwn = avg2_diff crosses below 0;


def hi1 = if bn == 1 then highestall(avg1_diff) else hi1[1];
def lo1 = if bn == 1 then lowestall(avg1_diff) else lo1[1];
def rng1 = hi1 - lo1;

def hi2 = if bn == 1 then highestall(avg2_diff) else hi2[1];
def lo2 = if bn == 1 then lowestall(avg2_diff) else lo2[1];
def rng2 = hi2 - lo2;

input range_factor = 1.1;
def rngx = max(rng1,rng2)*range_factor;


#  avgs
#  blue line is the ma of close
#  red line is the ma of open
#   solid lines , 8 ema
#   dashed lines , 21 ema.

input show_avg1_line = yes;
input show_avg2_line = yes;
plot zavg1 = if show_avg1_line then avg1_diff else na;
plot zavg2 = if show_avg2_line then avg2_diff else na;
zavg1.SetDefaultColor(Color.cyan);
zavg1.setlineweight(1);
zavg1.hidebubble();
zavg2.SetDefaultColor(Color.yellow);
zavg2.setlineweight(1);
zavg2.hidebubble();
zavg2.SetStyle(Curve.MEDIUM_DASH);

plot z0 = if valid then 0 else na;


addlabel(1, "avg c - o", color.white);

addlabel(1,
(if avg1_type == AverageType.Simple then "SMA"
 else if avg1_type == AverageType.exponential then "EMA"
 else if avg1_type == AverageType.hull then "HULL"
 else if avg1_type == AverageType.weighted then "WT"
 else if avg1_type == AverageType.wilders then "WILD"
 else "---") + avg1_length
, color.cyan);

addlabel(1,
(if avg2_type == AverageType.Simple then "SMA"
 else if avg2_type == AverageType.exponential then "EMA"
 else if avg2_type == AverageType.hull then "HULL"
 else if avg2_type == AverageType.weighted then "WT"
 else if avg2_type == AverageType.wilders then "WILD"
 else "---") + avg2_length
, color.yellow);


#avg1_diff  cyan
#avg2_diff  yellow

#def off1 = -5;
def off1 = -rngx/2;
def cond1 = (avg1_diff > 0);
def o1 = off1 + (if cond1 then 0 else avg1_diff);
def c1 = off1 + (if cond1 then avg1_diff else 0);
def h1 = off1 + (if cond1 then avg1_diff else 0);
def l1 = off1 + (if cond1 then 0 else avg1_diff);
AddChart(growColor = Color.cyan, high = h1, low = l1, open = c1, close = o1, type = ChartType.CANDLE);

#def off2 = 2 * off1;
def off2 = -off1;
def cond2 = (avg2_diff > 0);
def o2 = off2 + (if cond2 then 0 else avg2_diff);
def c2 = off2 + (if cond2 then avg2_diff else 0);
def h2 = off2 + (if cond2 then avg2_diff else 0);
def l2 = off2 + (if cond2 then 0 else avg2_diff);
AddChart(growColor = Color.yellow, high = h2, low = l2, open = c2, close = o2, type = ChartType.CANDLE);


input test1_ranges = no;
addlabel(test1_ranges, "R1 " + rng1);
addlabel(test1_ranges, "R2 " + rng2);
addlabel(test1_ranges, "Rx " + rngx);
#
 

Attachments

  • img3.JPG
    img3.JPG
    105.4 KB · Views: 47

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
308 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top