Alert When Price > 9ema after closing below it, in last 5 minutes.

Hello,

I am attempting to create a scanner to buy when shorts are potentially trapped.

My thought is to wait for the price to close below the 9ema, where shorts might jump in.
Then in the next 5 minutes, if the price goes above the 9ema I will buy in hopes that shorts are trapped.

I created the code, but am having trouble with getting the condition to check within the last 5 minutes. Can someone please help with this?

Thanks in advance!!


def ema9 = MovAvgExponential(close, 9, 0, no);
def CloseBelowNine = close < ema9;
def LastPrice = close;
def input bars_away = 5;
def input bars_count = yes;


def BuyOverNine = LastPrice crosses above CloseBelowNine and bars_away;
plot scan =BuyOverNine ;
 
You should try using the within x bars clause...

Hi @rad14733 - I tried doing it via the "within x bars" code, but unfortunately it didn't work. Do you have any other suggestions, please?


def ema9 = MovAvgExponential(close, 9, 0, no);
def CloseBelowNine = close < ema9;


def BuyOverNine = Price > CloseBelowNine within 5bars;
plot scan =BuyOverNine ;
 
@generic - there are two parts to this.
The second part is what you mentioned, where the price is above the 9ema within the previous 5 bars (def BuyOverNine = Price > CloseBelowNine within 5bars) .
The first part, however, is where the price is BELOW the 9ema (def CloseBelowNine). This is the part that's kicking my butt - how to look at the next 5 bars and alert if this condition is met. Thanks.
 
Last edited by a moderator:
If you say so. Are you looking for price to crosses below and above ema9 within 5 bars?


Yes, the first step is for the price to close below the 9ema. This sets off a timer/counter that checks if the price closes ABOVE the 9ema in the next 5 candles. If it does, then it fires an alert. I can't code the second part correctly, so any help would be greatly appreciated!!
tagging @rad14733 as well.


Here's the code, so that you guys/gals don't have to scroll up:

def ema9 = MovAvgExponential(close, 9, 0, no);
def CloseBelowNine = close < ema9;

def BuyOverNine = Price > CloseBelowNine within 5bars;
plot scan =BuyOverNine ;
 
@KevinSammy Something like this...??? I think your logic was reversed... You want to know when close crosses back above ema9 after it has crossed below ema9 within the past 5 bars...

Ruby:
plot buyOver9 = close crosses below ExpAverage(close, 9) within 5 bars and close crosses above ExpAverage(close, 9);
buyOver9.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Up);
buyOver9.SetDefaultColor(Color.GREEN);
buyOver9.SetLineWeight(5);
 
@KevinSammy Something like this...??? I think your logic was reversed... You want to know when close crosses back above ema9 after it has crossed below ema9 within the past 5 bars...

Ruby:
plot buyOver9 = close crosses below ExpAverage(close, 9) within 5 bars and close crosses above ExpAverage(close, 9);
buyOver9.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Up);
buyOver9.SetDefaultColor(Color.GREEN);
buyOver9.SetLineWeight(5);


Thank you, Rad!
Can't believe that I missed that, tunnel vision did me in. Thank you!
 

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