Show the difference between candle close and the EMA lines

Friends,

I am kind of new with thinkscript and look for experts to help on sharing few lines of code with what I am looking for.

I need a bubble to show the difference between candle close and the EMA lines on the top left corner (ref to the attached image)

your help is much apprecaited


xzSwAPd.png
 
Last edited by a moderator:
Solution
Friends,

I am kind of new with thinkscript and look for experts to help on sharing few lines of code with what I am looking for.

I need a bubble to show the difference between candle close and the EMA lines on the top left corner (ref to the attached image)

your help is much apprecaited


this has 4 averages. if the length is > 1 then they will be evaluated

Code:
# price_diff_emas_00

# https://usethinkscript.com/threads/show-the-difference-between-candle-close-and-the-ema-lines.14254/
# Show the difference between candle close and the EMA lines

def na = double.nan;
def bn = barnumber();

# last bar  ( most recent)
#def lastbar = !isnan(close[0]) and isnan(close[-1]);


def price = close;

input ma1_len = 8;
input...
Friends,

I am kind of new with thinkscript and look for experts to help on sharing few lines of code with what I am looking for.

I need a bubble to show the difference between candle close and the EMA lines on the top left corner (ref to the attached image)

your help is much apprecaited


this has 4 averages. if the length is > 1 then they will be evaluated

Code:
# price_diff_emas_00

# https://usethinkscript.com/threads/show-the-difference-between-candle-close-and-the-ema-lines.14254/
# Show the difference between candle close and the EMA lines

def na = double.nan;
def bn = barnumber();

# last bar  ( most recent)
#def lastbar = !isnan(close[0]) and isnan(close[-1]);


def price = close;

input ma1_len = 8;
input ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);

input ma2_len = 20;
input ma2_type =  AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);

input ma3_len = 50;
input ma3_type =  AverageType.EXPONENTIAL;
def ma3 = MovingAverage(ma3_type, price, ma3_len);

input ma4_len = 1;
input ma4_type =  AverageType.EXPONENTIAL;
def ma4 = MovingAverage(ma4_type, price, ma4_len);


def en1 = ma1_len > 1;
def en2 = ma2_len > 1;
def en3 = ma3_len > 1;
def en4 = ma4_len > 1;

input show_average_lines = yes;
plot z1 = if show_average_lines and en1 then ma1 else na;
z1.setdefaultcolor(getcolor(1));
#z1.setlineweight(1);
z1.hidebubble();

plot z2 = if show_average_lines and en2 then ma2 else na;
z2.setdefaultcolor(getcolor(2));
#z2.setlineweight(1);
z2.hidebubble();

plot z3 = if show_average_lines and en3 then ma3 else na;
z3.setdefaultcolor(getcolor(3));
#z3.setlineweight(1);
z3.hidebubble();

plot z4 = if show_average_lines and en4 then ma4 else na;
z4.setdefaultcolor(getcolor(4));
#z4.setlineweight(1);
z4.hidebubble();


def diff1 = close - ma1;
def diff2 = close - ma2;
def diff3 = close - ma3;
def diff4 = close - ma4;

addlabel(en1, "MA"+ ma1_len + " diff " + diff1, getcolor(1));
addlabel(en2, "MA"+ ma2_len + " diff " + diff2, getcolor(2));
addlabel(en3, "MA"+ ma3_len + " diff " + diff3, getcolor(3));
addlabel(en4, "MA"+ ma4_len + " diff " + diff4, getcolor(4));
#

6xlRPGn.jpg
 
Solution
Appreciate all your help @halcyonguy Can this be made into a watchlist

yes, just have to reduce the data displayed so it will fit in a column


for a watchlist, i make a lower study , then change it to be a column study

this is a lower for studying data


Code:
# price_diff_emas_00_lower

# https://usethinkscript.com/threads/show-the-difference-between-candle-close-and-the-ema-lines.14254/
# Show the difference between candle close and the EMA lines

declare lower;

def na = double.nan;
def bn = barnumber();

# last bar  ( most recent)
#def lastbar = !isnan(close[0]) and isnan(close[-1]);


def price = close;

input ma1_len = 8;
input ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);

input ma2_len = 20;
input ma2_type =  AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);

input ma3_len = 50;
input ma3_type =  AverageType.EXPONENTIAL;
def ma3 = MovingAverage(ma3_type, price, ma3_len);

input ma4_len = 1;
input ma4_type =  AverageType.EXPONENTIAL;
def ma4 = MovingAverage(ma4_type, price, ma4_len);

def en1 = ma1_len > 1;
def en2 = ma2_len > 1;
def en3 = ma3_len > 1;
def en4 = ma4_len > 1;

#input show_average_lines = no;
#plot z1 = if show_average_lines and en1 then ma1 else na;
#z1.setdefaultcolor(getcolor(1));
##z1.setlineweight(1);
#z1.hidebubble();

#plot z2 = if show_average_lines and en2 then ma2 else na;
#z2.setdefaultcolor(getcolor(2));
##z2.setlineweight(1);
#z2.hidebubble();

#plot z3 = if show_average_lines and en3 then ma3 else na;
#z3.setdefaultcolor(getcolor(3));
##z3.setlineweight(1);
#z3.hidebubble();

#plot z4 = if show_average_lines and en4 then ma4 else na;
#z4.setdefaultcolor(getcolor(4));
##z4.setlineweight(1);
#z4.hidebubble();


def diff1b = round(close - ma1, 2);
def diff2b = round(close - ma2, 2);
def diff3b = round(close - ma3, 2);
def diff4b = round(close - ma4, 2);

def diff1 = absvalue(diff1b);
def diff2 = absvalue(diff2b);
def diff3 = absvalue(diff3b);
def diff4 = absvalue(diff4b);

def max1 = en1 and (diff1 > diff2 and diff1 > diff3 and diff1 > diff4);
def max2 = en2 and (diff2 > diff1 and diff2 > diff3 and diff2 > diff4);
def max3 = en3 and (diff3 > diff1 and diff3 > diff2 and diff3 > diff4);
def max4 = en4 and (diff4 > diff1 and diff4 > diff2 and diff4 > diff3);


#addlabel(en1, "MA"+ ma1_len + " diff " + diff1, getcolor(1));
#addlabel(en2, "MA"+ ma2_len + " diff " + diff2, getcolor(2));
#addlabel(en3, "MA"+ ma3_len + " diff " + diff3, getcolor(3));
#addlabel(en4, "MA"+ ma4_len + " diff " + diff4, getcolor(4));

addlabel(1,
(if en1 then "|" + diff1b else "") +
(if en2 then "|" + diff2b else "") +
(if en3 then "|" + diff3b else "") +
(if en4 then "|" + diff4b else "") + "|"
, color.black);


#addlabel(1,
#(if en1 then " | MA"+ ma1_len + " " + diff1b else "") +
#(if en2 then " | MA"+ ma2_len + " " + diff2b else "") +
#(if en3 then " | MA"+ ma3_len + " " + diff3b else "") +
#(if en4 then " | MA"+ ma4_len + " " + diff4b else "") + " |"
#, color.black);


AssignBackgroundColor(
#if 1 then color.current else
if max1 then getcolor(1)
else if max2 then getcolor(2)
else if max3 then getcolor(3)
else if max4 then getcolor(4)
else color.white);


addlabel(1,
max1+"|"+
max2+"|"+
max3+"|"+
max4
, color.blue);
#



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

watchlist study

this shows up to 4 price difference, separated by |
the biggest difference decides the color# for the background , 1,2,3,4


Code:
# price_diff_emas_00_column

# https://usethinkscript.com/threads/show-the-difference-between-candle-close-and-the-ema-lines.14254/
# Show the difference between candle close and the EMA lines

def na = double.nan;
def bn = barnumber();

# last bar  ( most recent)
#def lastbar = !isnan(close[0]) and isnan(close[-1]);


def price = close;

input ma1_len = 8;
input ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);

input ma2_len = 20;
input ma2_type =  AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);

input ma3_len = 50;
input ma3_type =  AverageType.EXPONENTIAL;
def ma3 = MovingAverage(ma3_type, price, ma3_len);

input ma4_len = 1;
input ma4_type =  AverageType.EXPONENTIAL;
def ma4 = MovingAverage(ma4_type, price, ma4_len);

def en1 = ma1_len > 1;
def en2 = ma2_len > 1;
def en3 = ma3_len > 1;
def en4 = ma4_len > 1;


def diff1b = round(close - ma1, 2);
def diff2b = round(close - ma2, 2);
def diff3b = round(close - ma3, 2);
def diff4b = round(close - ma4, 2);

def diff1 = absvalue(diff1b);
def diff2 = absvalue(diff2b);
def diff3 = absvalue(diff3b);
def diff4 = absvalue(diff4b);

def max1 = en1 and (diff1 > diff2 and diff1 > diff3 and diff1 > diff4);
def max2 = en2 and (diff2 > diff1 and diff2 > diff3 and diff2 > diff4);
def max3 = en3 and (diff3 > diff1 and diff3 > diff2 and diff3 > diff4);
def max4 = en4 and (diff4 > diff1 and diff4 > diff2 and diff4 > diff3);


addlabel(1,
(if en1 then "|" + diff1b else "") +
(if en2 then "|" + diff2b else "") +
(if en3 then "|" + diff3b else "") +
(if en4 then "|" + diff4b else "") + "|"
, color.black);


AssignBackgroundColor(
#if 1 then color.current else
if max1 then getcolor(1)
else if max2 then getcolor(2)
else if max3 then getcolor(3)
else if max4 then getcolor(4)
else color.white);
#
 
this has 4 averages. if the length is > 1 then they will be evaluated

Code:
# price_diff_emas_00

# https://usethinkscript.com/threads/show-the-difference-between-candle-close-and-the-ema-lines.14254/
# Show the difference between candle close and the EMA lines

def na = double.nan;
def bn = barnumber();

# last bar  ( most recent)
#def lastbar = !isnan(close[0]) and isnan(close[-1]);


def price = close;

input ma1_len = 8;
input ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);

input ma2_len = 20;
input ma2_type =  AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);

input ma3_len = 50;
input ma3_type =  AverageType.EXPONENTIAL;
def ma3 = MovingAverage(ma3_type, price, ma3_len);

input ma4_len = 1;
input ma4_type =  AverageType.EXPONENTIAL;
def ma4 = MovingAverage(ma4_type, price, ma4_len);


def en1 = ma1_len > 1;
def en2 = ma2_len > 1;
def en3 = ma3_len > 1;
def en4 = ma4_len > 1;

input show_average_lines = yes;
plot z1 = if show_average_lines and en1 then ma1 else na;
z1.setdefaultcolor(getcolor(1));
#z1.setlineweight(1);
z1.hidebubble();

plot z2 = if show_average_lines and en2 then ma2 else na;
z2.setdefaultcolor(getcolor(2));
#z2.setlineweight(1);
z2.hidebubble();

plot z3 = if show_average_lines and en3 then ma3 else na;
z3.setdefaultcolor(getcolor(3));
#z3.setlineweight(1);
z3.hidebubble();

plot z4 = if show_average_lines and en4 then ma4 else na;
z4.setdefaultcolor(getcolor(4));
#z4.setlineweight(1);
z4.hidebubble();


def diff1 = close - ma1;
def diff2 = close - ma2;
def diff3 = close - ma3;
def diff4 = close - ma4;

addlabel(en1, "MA"+ ma1_len + " diff " + diff1, getcolor(1));
addlabel(en2, "MA"+ ma2_len + " diff " + diff2, getcolor(2));
addlabel(en3, "MA"+ ma3_len + " diff " + diff3, getcolor(3));
addlabel(en4, "MA"+ ma4_len + " diff " + diff4, getcolor(4));
#

6xlRPGn.jpg
Awesome bruh !! This is great stuff.

how easy it is to add RSI label so as to show the RSI value (14 days) for this candle?
 

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
472 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