Add alert to a 50/9 EMA cross


0
0

Hi Pete,

I was hoping to add an alert to this study. Also hope to add it to the chart with up and down arrows if it cross to the upside or downside.

def ema1 = ExpAverage(close, 50);
def ema2 = ExpAverage(close, 9);
def emaCrossingAbove = ema1[1] < ema2[1] and ema1 > ema2;
plot scan = emaCrossingAbove[-1];

 

Marked as spam
Posted by (Questions: 49, Answers: 42)
Asked on November 29, 2018 3:07 pm
200 views
-1
Private answer

I see that you requested up and down arrows. However your code only contained a signal for crossing above. So here it is with the up arrow and alert based on the signal provided in your original source code:

def ema1 = ExpAverage(close, 50);
def ema2 = ExpAverage(close, 9);
def emaCrossingAbove = ema1[1] < ema2[1] and ema1 > ema2;
plot scan = emaCrossingAbove[-1];
scan.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
scan.SetDefaultColor(Color.CYAN);
scan.SetLineWeight(3);
Alert(scan, "EMA Crossing Above", Alert.BAR, Sound.RING);

Notice I only added 4 lines to your code. And three of those were mere style statements to configure the same elements that can be adjusted from user settings. They really are not required. They are only there to provide default user settings.

Update: The request has been modified to include crosses below as well as crosses above. Here is the code required to add those elements.

def ema1 = ExpAverage(close, 50);
def ema2 = ExpAverage(close, 9);
def emaCrossingAbove = ema1[1] < ema2[1] and ema1 > ema2;
def emaCrossingBelow = ema1[1] > ema2[1] and ema1 < ema2;
plot crossingAbove = emaCrossingAbove[-1];
crossingAbove.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
crossingAbove.SetDefaultColor(Color.CYAN);
crossingAbove.SetLineWeight(3);
Alert(crossingAbove, "EMA Crossing Above", Alert.BAR, Sound.RING);
plot crossingBelow = emaCrossingBelow[-1];
crossingBelow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
crossingBelow.SetDefaultColor(Color.MAGENTA);
crossingBelow.SetLineWeight(3);
Alert(crossingBelow, "EMA Crossing Below", Alert.BAR, Sound.RING);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 30, 2018 7:33 am
0

Hi Pete,
Could I get this study to the upside and downside with alert..

Thanks

( at November 30, 2018 9:36 am)
0

I have updated my answer to include the crosses below.

( at November 30, 2018 10:14 am)