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

KevinSammy

Member
VIP
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 ;
 

KevinSammy

Member
VIP
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 ;
 

rad14733

Moderator
Staff member
VIP
@KevinSammy The logic is flawed... No need making is more complex than to needs to be... We had a busy day watching a granddaughter and nephew and I dozed off after they left... I'll see if my brain is back in action after dinner and test some code before posting it...
 

KevinSammy

Member
VIP
@KevinSammy The logic is flawed... No need making is more complex than to needs to be... We had a busy day watching a granddaughter and nephew and I dozed off after they left... I'll see if my brain is back in action after dinner and test some code before posting it...

Thank you, Rad.

@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.
 

KevinSammy

Member
VIP
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 ;
 

rad14733

Moderator
Staff member
VIP
@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

Member
VIP
@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!
 

Similar threads

Top