the indicator show candle above 5 ema mark as 1,2,3,4,5

the indicator show above 5 ema mark as 1,2,3,4,5

Not exactly sure what you wanted, but this will count consecutive closes above the ema5.

If there are at least 5 consecutive closes above the ema5 in a row, then a chart bubble will be colored yellow along with the count.

Otherwise, closes above the ema5 will have gray colored bubbles with the consecutive count.

Screenshot 2023-05-27 163224.png
Code:
input length = 5;
input price  = close;
input avg    = AverageType.EXPONENTIAL;
plot  ema5   = MovingAverage(avg, price, length);
def above    = if close crosses above ema5
               then 1
               else if above[1] >= 1 and close > ema5
               then above[1] + 1
               else 0;
def above5  = if above[-4] == 5
              then 1
              else if above5[1] == 1 and above[1] > 0
              then 1 else 0;

AddChartBubble(above > 0, high, above + "\n" + above5, if above <= 5 and above5 == 1 then Color.YELLOW else Color.GRAY);
 
thanks,I modify it ,so above 5 ema and below 5 ema mark it.
is it is possible only 5 ema up ,mark 1,2,3,4,5 up and 5 ema down ,market 1,2,3,4,5 down
Code:
input length = 5;
input price  = close;
input avg    = AverageType.EXPONENTIAL;
plot  ema5   = MovingAverage(avg, price, length);
def above    = if close crosses above ema5
               then 1
               else if above[1] >= 1 and close > ema5
               then above[1] + 1
               else 0;
def above5  = if above[-4] == 5
              then 1
              else if above5[1] == 1 and above[1] > 0
              then 1 else 0;

AddChartBubble(above > 0, high, above + "\n" , if above <= 5  then Color.YELLOW else Color.GRAY);

def below    = if close crosses below ema5
               then 1
               else if below[1] >= 1 and close < ema5
               then below[1] + 1
               else 0;
def below5  = if below[-4] == 5
              then 1
              else if below5[1] == 1 and below[1] > 0
              then 1 else 0;

AddChartBubble(below > 0, low, below + "\n" , if below <= 5  then Color.RED else Color.GRAY);
 
thanks,I modify it ,so above 5 ema and below 5 ema mark it.
is it is possible only 5 ema up ,mark 1,2,3,4,5 up and 5 ema down ,market 1,2,3,4,5 down
Code:
input length = 5;
input price  = close;
input avg    = AverageType.EXPONENTIAL;
plot  ema5   = MovingAverage(avg, price, length);
def above    = if close crosses above ema5
               then 1
               else if above[1] >= 1 and close > ema5
               then above[1] + 1
               else 0;
def above5  = if above[-4] == 5
              then 1
              else if above5[1] == 1 and above[1] > 0
              then 1 else 0;

AddChartBubble(above > 0, high, above + "\n" , if above <= 5  then Color.YELLOW else Color.GRAY);

def below    = if close crosses below ema5
               then 1
               else if below[1] >= 1 and close < ema5
               then below[1] + 1
               else 0;
def below5  = if below[-4] == 5
              then 1
              else if below5[1] == 1 and below[1] > 0
              then 1 else 0;

AddChartBubble(below > 0, low, below + "\n" , if below <= 5  then Color.RED else Color.GRAY);

This should work

Screenshot 2023-05-28 061456.png
Code:
input length = 5;
input price  = close;
input avg    = AverageType.EXPONENTIAL;
plot  ema5   = MovingAverage(avg, price, length);
def above    = if close crosses above ema5
               then 1
               else if above[1] >= 1 and close > ema5
               then above[1] + 1
               else 0;
def above5  = if above[-4] == 5
              then 1
              else if above5[1] == 1 and above[1] > 0
              then 1 else 0;

AddChartBubble(between(above, 1, 5) and above5 == 1, high, above + "\n" , if above <= 5  then Color.YELLOW else Color.GRAY);

def below    = if close crosses below ema5
               then 1
               else if below[1] >= 1 and close < ema5
               then below[1] + 1
               else 0;
def below5  = if below[-4] == 5
              then 1
              else if below5[1] == 1 and below[1] > 0
              then 1 else 0;

AddChartBubble(between(below, 1, 5) and below5 == 1, low, below + "\n" , if below <= 5  then Color.RED else Color.GRAY);
 
it is perfect
Hey mmm I really like the ema 5 strategy, buy when close above it, SL under that same candle, profit taking when it breaks the low candle close under ema 5. What strategy do you use? Do you use any other indicator to confirm your strategy? Can you explain a little?
Thanks @SleepyZ for the code I definitely using it…
 

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