Confidence Mean Indicator for ThinkorSwim

J007RMC

Well-known member
2019 Donor
Calculates standard error and constructs Confidence Intervals for mean
Mobius
V01.01.01.2018
{Simple Confidence system. Trade is taken when close crosses the mean and added to when price is outside the confidence bands and trade is exited once close crosses into the bands.} Really know more of the indicator except that one can changed=number of days. The red labels indicate the Laguerre indicator a part of the Confidence Mean Indicator. and definitely dont understand the thumbs down lol.



Code:
# Confidence Intervals
# calculates standard error and constructs Confidence Intervals for mean
# Mobius
# V01.01.01.2018
# Simple Confidence system. Trade is taken when close crosses the mean and added to when price is outside the confidence bands and trade is exited once close crosses into the bands.


input n = 21;

# Detrended Mean
plot detrended_Mean = Average(close + (close - close[n/2]), n);
# variance of the mean
def var_of_mean = Sum(sqr(close - detrended_mean), n) / (n-1);
# standard deviation
def st_dev = sqrt(var_of_mean);
# standard error of the mean
def st_error = st_dev / sqrt(n);
# Determine the 95% Confidence Level
# Margin Of Error t-statistic of 1.96
def mar_of_error = 1.96 * st_error;
# Confidence Interval
plot upper = detrended_mean + mar_of_error;
upper.setDefaultColor(color.cyan);
plot lower = detrended_mean - mar_of_error;
lower.setDefaultColor(color.cyan);
addCloud(lower, upper, color.cyan, color.cyan);
plot upArrow = if close crosses above detrended_Mean
then low
else double.nan;
upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
upArrow.SetDefaultColor(Color.Green);
plot Confidence_upArrow = if close crosses above upper
then low
else double.nan;
Confidence_upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
Confidence_upArrow.SetDefaultColor(Color.Dark_Green);
plot STC_Arrow = if close crosses below upper
then high
else double.nan;
STC_Arrow.SetPaintingStrategy(PaintingStrategy.Boolean_WEDGE_DOWN);
STC_Arrow.SetDefaultColor(Color.Yellow);
STC_Arrow.SetLineWeight(4);
plot dnArrow = if close crosses below detrended_Mean
then high
else double.nan;
dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
dnArrow.SetDefaultColor(Color.Red);
plot Confidence_dnArrow = if close crosses below lower
then high
else double.nan;
Confidence_dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
Confidence_dnArrow.SetDefaultColor(Color.Dark_Red);
plot BTC_Arrow = if close crosses above lower
then low
else double.nan;
BTC_Arrow.SetPaintingStrategy(PaintingStrategy.Boolean_Wedge_UP);
BTC_Arrow.SetLineWeight(3);
BTC_Arrow.SetDefaultColor(Color.Yellow);
# End Code Confidence_Intervals
 
Last edited:
@J007RMC Hey man, surprised nobody has responded to this, but this indicator is amazing. I've been looking for something like it to weed out bad trades and show me when things are breaking out. I day trade SPY Options on the 1000 tick chart, and after changing the settings to 34 instead of 21, it seems to really work for me. Really appreciate you posting this and glad I found this diamond in the rough.
 

tem2005

Active member
VIP
@J007RMC I like this indicator. How can I disable the cyan cloud? I cants see other indicators. also, does it repaint?
 
Last edited:

cos251

Well-known member
@J007RMC I like this indicator. How can I disable the cyan cloud? I cants see other indicators. also, does it repaint?
See below; I added a toggle for the cloud and changed the detrendedMean line to red.

Code:
# Confidence Intervals
# calculates standard error and constructs Confidence Intervals for mean
# Mobius
# V01.01.01.2018
# Simple Confidence system. Trade is taken when close crosses the mean and added to when price is outside the confidence bands and trade is exited once close crosses into the bands.
# 2020.10.22 - @cos251 - added Cloud Toggle and changed detrendedMean line color to red

input n = 21;
input showClouds = yes;

# Detrended Mean
plot detrended_Mean = Average(close + (close - close[n/2]), n);
detrended_Mean.SetDefaultColor(Color.Red);
# variance of the mean
def var_of_mean = Sum(sqr(close - detrended_mean), n) / (n-1);
# standard deviation
def st_dev = sqrt(var_of_mean);
# standard error of the mean
def st_error = st_dev / sqrt(n);
# Determine the 95% Confidence Level
# Margin Of Error t-statistic of 1.96
def mar_of_error = 1.96 * st_error;
# Confidence Interval
plot upper = detrended_mean + mar_of_error;
upper.SetDefaultColor(color.cyan);
plot lower = detrended_mean - mar_of_error;
lower.SetDefaultColor(color.cyan);

AddCloud(if showClouds then lower else Double.NaN, if showClouds then upper else Double.NaN, color.cyan, color.cyan);

plot upArrow = if close crosses above detrended_Mean
then low
else double.nan;
upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
upArrow.SetDefaultColor(Color.Green);
plot Confidence_upArrow = if close crosses above upper
then low
else double.nan;
Confidence_upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
Confidence_upArrow.SetDefaultColor(Color.Dark_Green);
plot STC_Arrow = if close crosses below upper
then high
else double.nan;
STC_Arrow.SetPaintingStrategy(PaintingStrategy.Boolean_WEDGE_DOWN);
STC_Arrow.SetDefaultColor(Color.Yellow);
STC_Arrow.SetLineWeight(4);
plot dnArrow = if close crosses below detrended_Mean
then high
else double.nan;
dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
dnArrow.SetDefaultColor(Color.Red);
plot Confidence_dnArrow = if close crosses below lower
then high
else double.nan;
Confidence_dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
Confidence_dnArrow.SetDefaultColor(Color.Dark_Red);
plot BTC_Arrow = if close crosses above lower
then low
else double.nan;
BTC_Arrow.SetPaintingStrategy(PaintingStrategy.Boolean_Wedge_UP);
BTC_Arrow.SetLineWeight(3);
BTC_Arrow.SetDefaultColor(Color.Yellow);
# End Code Confidence_Intervals
 

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.
Top