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.
 

halcyonguy

Well-known member
VIP
Lifetime
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:

VincentJalapeno

New member
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.jpg
thank you very much I appreciate you <3
 

Similar threads

Top