Study for ema 21

dexter2025

New member
Hello guys , I need a study that shows the stocks that touching the 21 ema on hour , something like the attached file , and also for 21 ema on a day
 

Attachments

  • Screenshot_20231108-153540.png
    Screenshot_20231108-153540.png
    139.7 KB · Views: 101
Solution
Hello guys , I need a study that shows the stocks that touching the 21 ema on hour , something like the attached file , and also for 21 ema on a day

when saying touch, i think of high or low having the same value as the average.
but 2 different variables will almost never have the same value, so they won't touch.
but they might cross, and we can check if they cross and are near a candle high or low.

you didn't say what or where you wanted to see something.
i made an upper study, that draws shapes when a bar is crossed.

price crosses an average line,
can pick 2 different type of crossings,
..highorlow within a range of the high OR within a range of the low
..any within the high and low

range is some number x tick...
Hello guys , I need a study that shows the stocks that touching the 21 ema on hour , something like the attached file , and also for 21 ema on a day

when saying touch, i think of high or low having the same value as the average.
but 2 different variables will almost never have the same value, so they won't touch.
but they might cross, and we can check if they cross and are near a candle high or low.

you didn't say what or where you wanted to see something.
i made an upper study, that draws shapes when a bar is crossed.

price crosses an average line,
can pick 2 different type of crossings,
..highorlow within a range of the high OR within a range of the low
..any within the high and low

range is some number x tick size. default is 5 x 0.01

yellow dots are drawn when the average line is near the high or low
cyan triangles are drawn when the average line is crossed by any part of the candle


Code:
#price_cross_ema

#https://usethinkscript.com/threads/study-for-ema-21.17116/
# touching ema 21

def na = double.nan;
def t = ticksize();
input tick_factor = 2;
def f = t * tick_factor;

addlabel(1, "+- range " + f, color.yellow);

input bar_part_cross_avg_type = { default highorlow , any };

#input avg_type = AverageType.Simple;
input avg_type = AverageType.exponential;
input avg_data = close;
input avg_len = 21;
def avg = MovingAverage( avg_type , avg_data , avg_len );
plot zavg = avg;

def x;
def a;
switch( bar_part_cross_avg_type) {
case any:
 a = 1;
 x = if high >= avg and low <= avg then 1 else 0;
case highorlow:
 a = 2;
 x = if (high >= avg and (high - f) <= avg) or ((low + f) >= avg and (low <= avg)) then 1 else 0;
}


plot zcross1 = if x and a == 1 then high*1.004
 else na;
zcross1.SetPaintingStrategy(PaintingStrategy.triangles);
zcross1.SetDefaultColor(Color.cyan);
zcross1.setlineweight(5);
zcross1.hidebubble();


plot zcross2 = if x and a == 2 and ((high - f) <= avg) then high*1.002
 else if x and a == 2 and ((low + f) >= avg) then low*0.998
 else na;
zcross2.SetPaintingStrategy(PaintingStrategy.POINTS);
zcross2.SetDefaultColor(Color.yellow);
zcross2.setlineweight(5);
zcross2.hidebubble();

#----------------------

input test1_diff = no;
addchartbubble(test1_diff, low*0.996,
(high - avg) + "\n" +
(low - avg)
, color.yellow, no);

addverticalline(0 and x, "-", color.yellow);
#

SgPx0Y9.jpg
 
Solution

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