Does a script exist for: Candle Closes above 9 EMA, plots dot below candle. Candle closes below 9 EMA, plots dot above Candle? Or something similar?

B-Ride

New member
Hello, working on a new system for myself and realized it would be advantageous to have a script that would help confirm momentum by plotting a dot below a candle when it closes above the 9 EMA and above a candle when it closes below the 9 EMA. Don't know if something like this exists already, but since the 9 EMA is used in momentum day trading often, I have to imagine it does. Have the dot plot just once at the start of the trend would all that I would need and only plot again when the trend changes. If anyone has something, I'd appreciate a copy of it.

Okay, so I found this existing script that @BenTen made for someone. It plots an arrow after a second candle closes above the 9 EMA. I copied his script to create the same rule for closing below the 9 EMA after two candles. However, I don't want the arrows to continue above or below every candle respective of if it's a uptrend or a downtrend. I would like it to plot just one arrow after the close of the second candle on an uptrend or down trend, and not for the entire trend. Too messy. Then when a single candle does close below or above the 9 EMA counter to the prior trend, a yellow arrow would plot to alert to a momentum change. I can copy and paste, but I am in no way proficient in ThinkScript. Here is the existing code:

]input price = close;
input length = 9;
input displace = 0;
input showBreakoutSignals = no;

plot AvgExp = ExpAverage(price[-displace], length);

def condition = close[1] > AvgExp and close > AvgExp;
plot UpSignal = condition;

AvgExp.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

def condition1 = close[1] < AvgExp and close < AvgExp;
plot DownSignal = condition1;

AvgExp.SetDefaultColor(GetColor(2));
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Alert(DownSignal, " ", Alert.BAR, Sound.Chimes);[/CODE]
 
Okay, so I found this existing script that @BenTen made for someone. It plots an arrow after a second candle closes above the 9 EMA. I copied his script to create the same rule for closing below the 9 EMA after two candles. However, I don't want the arrows to continue above or below every candle respective of if it's a uptrend or a downtrend. I would like it to plot just one arrow after the close of the second candle on an uptrend or down trend, and not for the entire trend. Too messy. Then when a single candle does close below or above the 9 EMA counter to the prior trend, a yellow arrow would plot to alert to a momentum change. I can copy and paste, but I am in no way proficient in ThinkScript. Here is the existing code:

this lets you pick how many bars in a row should be above (or below) the average before showing an arrow.
default is 2
input sequential_bars = 2;

can pick the type of average

changed the arrows to be non boolean, so they can be moved away from the bars a little bit.
i like plotting shapes away from the bars, because i think it makes it easier to see them.

changed the alerts,
. used ding , a higher pitch sound for up
. used bell , a lower pitch sound for down


Ruby:
# ema_cross_1arrow_01

# https://usethinkscript.com/threads/does-a-script-exist-for-candle-closes-above-9-ema-plots-dot-below-candle-candle-closes-below-9-ema-plots-dot-above-candle-or-something-similar.13230/#post-111632

def na = double.nan;

input avg_type =  AverageType.EXPONENTIAL;
input avg_len = 9;
input price = close;
input displace = 0;
def avg = MovingAverage(avg_type, price[-displace], avg_len);

plot zavg = avg;
zavg.SetDefaultColor(GetColor(2));

input sequential_bars = 2;

addlabel(1, " ", color.black);
addlabel(1, "sequential bars " + sequential_bars, color.yellow);

def close_above = close > avg;
def condition_up = (getvalue(!close_above, sequential_bars) and sum(close_above, sequential_bars) == sequential_bars);

def close_below = close < avg;
def condition_dwn = (getvalue(!close_below, sequential_bars) and sum(close_below, sequential_bars) == sequential_bars);

def vert = 0.004;
plot zup = if condition_up then (low*(1-vert)) else na;
zup.SetDefaultColor(Color.UPTICK);
#zup.SetDefaultColor(Color.cyan);
zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zup.setlineweight(3);

plot zdwn = if condition_dwn then (high*(1+vert)) else na;
zdwn.SetDefaultColor(Color.DOWNTICK);
#zdwn.SetDefaultColor(Color.yellow);
zdwn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zdwn.setlineweight(3);

# =====================================
# alerts , sounds
# alert(condition, text, alert type, sound);
# Sound.Ding,  higher , up sound
# Sound.Bell,  lower , down sound
#def a = no;
alert(condition_up, "crossed up" ,alert.BAR, sound.DING);
alert(condition_dwn, "crossed down" ,alert.BAR, sound.bell);
# =====================================


input test1_bubble = no;
addchartbubble(test1_bubble, high,
condition_up + "\n" +
condition_dwn
, (if condition_up then color.green else if condition_dwn then color.red else color.gray), yes);
#

HdIb2XP.jpg
 
this lets you pick how many bars in a row should be above (or below) the average before showing an arrow.
default is 2
input sequential_bars = 2;

can pick the type of average

changed the arrows to be non boolean, so they can be moved away from the bars a little bit.
i like plotting shapes away from the bars, because i think it makes it easier to see them.

changed the alerts,
. used ding , a higher pitch sound for up
. used bell , a lower pitch sound for down


Ruby:
# ema_cross_1arrow_01

# https://usethinkscript.com/threads/does-a-script-exist-for-candle-closes-above-9-ema-plots-dot-below-candle-candle-closes-below-9-ema-plots-dot-above-candle-or-something-similar.13230/#post-111632

def na = double.nan;

input avg_type =  AverageType.EXPONENTIAL;
input avg_len = 9;
input price = close;
input displace = 0;
def avg = MovingAverage(avg_type, price[-displace], avg_len);

plot zavg = avg;
zavg.SetDefaultColor(GetColor(2));

input sequential_bars = 2;

addlabel(1, " ", color.black);
addlabel(1, "sequential bars " + sequential_bars, color.yellow);

def close_above = close > avg;
def condition_up = (getvalue(!close_above, sequential_bars) and sum(close_above, sequential_bars) == sequential_bars);

def close_below = close < avg;
def condition_dwn = (getvalue(!close_below, sequential_bars) and sum(close_below, sequential_bars) == sequential_bars);

def vert = 0.004;
plot zup = if condition_up then (low*(1-vert)) else na;
zup.SetDefaultColor(Color.UPTICK);
#zup.SetDefaultColor(Color.cyan);
zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zup.setlineweight(3);

plot zdwn = if condition_dwn then (high*(1+vert)) else na;
zdwn.SetDefaultColor(Color.DOWNTICK);
#zdwn.SetDefaultColor(Color.yellow);
zdwn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zdwn.setlineweight(3);

# =====================================
# alerts , sounds
# alert(condition, text, alert type, sound);
# Sound.Ding,  higher , up sound
# Sound.Bell,  lower , down sound
#def a = no;
alert(condition_up, "crossed up" ,alert.BAR, sound.DING);
alert(condition_dwn, "crossed down" ,alert.BAR, sound.bell);
# =====================================


input test1_bubble = no;
addchartbubble(test1_bubble, high,
condition_up + "\n" +
condition_dwn
, (if condition_up then color.green else if condition_dwn then color.red else color.gray), yes);
#

HdIb2XP.jpg
@halcyonguy Thank you so much for this, it was what I was looking for! Have a good weekend.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
489 Online
Create Post

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