Candle to Indicator Correlation For ThinkOrSwim

VincentJalapeno

New member
Is there a way to measure or code how the value of my indicator is correlated to price action?
If price goes up and my indicator value increases, shows a correlation for x indicator.
If price goes up and my indicator value decreases, shows that the indicator is not correlated to current price movement.
Any sort of help with this would be greatly appreciated! I have tried to analyze fractal and supertrend codes to maybe find the information I need, but haven't been able to find anything.
 

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

Is there a way to measure or code how the value of my indicator is correlated to price action?
If price goes up and my indicator value increases, shows a correlation for x indicator.
If price goes up and my indicator value decreases, shows that the indicator is not correlated to current price movement.
Any sort of help with this would be greatly appreciated! I have tried to analyze fractal and supertrend codes to maybe find the information I need, but haven't been able to find anything.


here are 3 versions of what you may be looking for

upper0,
find the the percent change, bar to bar, of a signal and price.
compare them , (price - signal)
plot as squares on a line in the middle of the candles.

Ruby:
# compare_signal_upper_0

# find the % change of a signal and price, bar to bar
# plot the diff on a histogram

# ----------------------------------------
addlabel(1, "upper0 , bar to bar change", color.yellow);

def na = Double.NaN;
def bn = BarNumber();

# find price limits, and middle
#def len1 = 1500;
def hi = highestall(high);
def lo = lowestall(low);
def rng = hi - lo;
def mid = (hi + lo) / 2;

plot m = if isnan(close) then na else mid;
m.setdefaultcolor(color.cyan);


# ----------------------------------------
# example signal , ema
def price = close;
input MA1_len = 11;
input MA1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(MA1_type, price, MA1_len);

input show_signal = yes;
# replace the formula for signal with your formula or variable
def signal = ma1;

plot s1 = if show_signal then signal else na;
s1.setdefaultcolor(color.yellow);


# ----------------------------------------
# signal diff
def signal_diff = if bn == 1 then 0 else signal - signal[1];
def signal_per = round( 100 * signal_diff/signal[1] , 1);

# ----------------------------------------
# price diff
def price_diff = if bn == 1 then 0 else close - close[1];
def price_per = round( 100 * price_diff/close[1] , 1);

# ----------------------------------------
# plot data
def compare = signal_per - price_per;

plot z1 = if IsNaN(close) then na else (mid + compare);
#z1.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
z1.SetPaintingStrategy(PaintingStrategy.SQUARES);
z1.AssignValueColor(if compare > 0 then color.green else color.red);
z1.SetLineWeight(3);
z1.HideBubble();

addlabel(1, " difference of %'s " + compare + "%", (if compare > 0 then color.green else color.red));
#

------------------------------------


lower0,
find the the percent change, bar to bar, of a signal and price.
compare them , (price - signal)
plot as a histogram on a lower chart.

Ruby:
# compare_signal_lower_0

# find the % change of a signal and price, bar to bar
# plot the diff on a histogram

# ----------------------------------------
declare lower;

addlabel(1, "lower0, bar to bar change", color.yellow);

def na = Double.NaN;
def bn = BarNumber();

# ----------------------------------------
# example signal , ema
def price = close;
input MA1_len = 11;
input MA1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(MA1_type, price, MA1_len);


# replace the formula for signal with your formula or variable
def signal = ma1;

# ----------------------------------------
# signal diff
def signal_diff = if bn == 1 then 0 else signal - signal[1];
def signal_per = round( 100 * signal_diff/signal[1] , 1);

# ----------------------------------------
# price diff
def price_diff = if bn == 1 then 0 else close - close[1];
def price_per = round( 100 * price_diff/close[1] , 1);

# ----------------------------------------
# plot data
def compare = signal_per - price_per;

plot z1 = if IsNaN(close) then na else compare;
z1.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
z1.AssignValueColor(if compare > 0 then color.green else color.red);
#z1.SetLineWeight(1);
z1.HideBubble();

addlabel(1, " difference of %'s " + compare + "%", (if compare > 0 then color.green else color.red));
#

------------------------------------


lower1,
find the the price change, in the same bar, of a signal and price.
compare them , (price - signal)
plot as a histogram on a lower chart.

Ruby:
# compare_signal_lower_1

# find the difference of a signal and price, same bar
# plot it on a histogram

# ----------------------------------------
declare lower;

addlabel(1, "lower1, $ diff, same bar", color.magenta);

def na = Double.NaN;
def bn = BarNumber();

# ----------------------------------------
# example signal , ema
def price = close;
input MA1_len = 11;
input MA1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(MA1_type, price, MA1_len);


# replace the formula for signal with your formula or variable
def signal = ma1;

# ----------------------------------------
# signal diff
#def signal_diff = if bn == 1 then 0 else signal - signal[1];
#def signal_per = round( 100 * signal_diff/signal[1] , 1);

# ----------------------------------------
# price diff
#def price_diff = if bn == 1 then 0 else close - close[1];
#def price_per = round( 100 * price_diff/close[1] , 1);

# ----------------------------------------
# plot data
#def compare = signal_per - price_per;
def compare = round(signal - price, 2);


plot z1 = if IsNaN(close) then na else compare;
z1.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
z1.AssignValueColor(if compare > 0 then color.green else color.red);
#z1.SetLineWeight(1);
z1.HideBubble();

addlabel(1, " difference of $ " + compare , (if compare > 0 then color.green else color.red));
#

------------------------------------

all 3 studies

eQgW7BB.jpg
 
Last edited:
here are 3 versions of what you may be looking for

upper0,
find the the percent change, bar to bar, of a signal and price.
compare them , (price - signal)
plot as squares on a line in the middle of the candles.

Ruby:
# compare_signal_upper_0

# find the % change of a signal and price, bar to bar
# plot the diff on a histogram

# ----------------------------------------
addlabel(1, "upper0 , bar to bar change", color.yellow);

def na = Double.NaN;
def bn = BarNumber();

# find price limits, and middle
#def len1 = 1500;
def hi = highestall(high);
def lo = lowestall(low);
def rng = hi - lo;
def mid = (hi + lo) / 2;

plot m = if isnan(close) then na else mid;
m.setdefaultcolor(color.cyan);


# ----------------------------------------
# example signal , ema
def price = close;
input MA1_len = 11;
input MA1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(MA1_type, price, MA1_len);

input show_signal = yes;
# replace the formula for signal with your formula or variable
def signal = ma1;

plot s1 = if show_signal then signal else na;
s1.setdefaultcolor(color.yellow);


# ----------------------------------------
# signal diff
def signal_diff = if bn == 1 then 0 else signal - signal[1];
def signal_per = round( 100 * signal_diff/signal[1] , 1);

# ----------------------------------------
# price diff
def price_diff = if bn == 1 then 0 else close - close[1];
def price_per = round( 100 * price_diff/close[1] , 1);

# ----------------------------------------
# plot data
def compare = signal_per - price_per;

plot z1 = if IsNaN(close) then na else (mid + compare);
#z1.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
z1.SetPaintingStrategy(PaintingStrategy.SQUARES);
z1.AssignValueColor(if compare > 0 then color.green else color.red);
z1.SetLineWeight(3);
z1.HideBubble();

addlabel(1, " difference of %'s " + compare + "%", (if compare > 0 then color.green else color.red));
#

------------------------------------


lower0,
find the the percent change, bar to bar, of a signal and price.
compare them , (price - signal)
plot as a histogram on a lower chart.

Ruby:
# compare_signal_lower_0

# find the % change of a signal and price, bar to bar
# plot the diff on a histogram

# ----------------------------------------
declare lower;

addlabel(1, "lower0, bar to bar change", color.yellow);

def na = Double.NaN;
def bn = BarNumber();

# ----------------------------------------
# example signal , ema
def price = close;
input MA1_len = 11;
input MA1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(MA1_type, price, MA1_len);


# replace the formula for signal with your formula or variable
def signal = ma1;

# ----------------------------------------
# signal diff
def signal_diff = if bn == 1 then 0 else signal - signal[1];
def signal_per = round( 100 * signal_diff/signal[1] , 1);

# ----------------------------------------
# price diff
def price_diff = if bn == 1 then 0 else close - close[1];
def price_per = round( 100 * price_diff/close[1] , 1);

# ----------------------------------------
# plot data
def compare = signal_per - price_per;

plot z1 = if IsNaN(close) then na else compare;
z1.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
z1.AssignValueColor(if compare > 0 then color.green else color.red);
#z1.SetLineWeight(1);
z1.HideBubble();

addlabel(1, " difference of %'s " + compare + "%", (if compare > 0 then color.green else color.red));
#

------------------------------------


lower1,
find the the price change, in the same bar, of a signal and price.
compare them , (price - signal)
plot as a histogram on a lower chart.

Ruby:
# compare_signal_lower_1

# find the difference of a signal and price, same bar
# plot it on a histogram

# ----------------------------------------
declare lower;

addlabel(1, "lower1, $ diff, same bar", color.magenta);

def na = Double.NaN;
def bn = BarNumber();

# ----------------------------------------
# example signal , ema
def price = close;
input MA1_len = 11;
input MA1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(MA1_type, price, MA1_len);


# replace the formula for signal with your formula or variable
def signal = ma1;

# ----------------------------------------
# signal diff
#def signal_diff = if bn == 1 then 0 else signal - signal[1];
#def signal_per = round( 100 * signal_diff/signal[1] , 1);

# ----------------------------------------
# price diff
#def price_diff = if bn == 1 then 0 else close - close[1];
#def price_per = round( 100 * price_diff/close[1] , 1);

# ----------------------------------------
# plot data
#def compare = signal_per - price_per;
def compare = round(signal - price, 2);


plot z1 = if IsNaN(close) then na else compare;
z1.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
z1.AssignValueColor(if compare > 0 then color.green else color.red);
#z1.SetLineWeight(1);
z1.HideBubble();

addlabel(1, " difference of $ " + compare , (if compare > 0 then color.green else color.red));
#

------------------------------------

all 3 studies

IhSboHI.png
thank you very much I appreciate you <3
 
What would I change in order to change the amount of bars it looks back? I'm using the 2nd study if it helps you, but would it just be inserted a number between () in BarNumber()?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
274 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