SMA Breakout with RSI<50



New member
So I’ll preface by saying I know just enough about coding to be dangerous. I’ve written a little bit mostly from trial-and-error with copy/paste, but this has had me stumped for several days. I’m trying to build a scan that alerts when the SMA1 pulls away from SMA2 when both are above SMA3 and RSI is <=50 to alert of a potential breakout (where SMA1 < SMA2 < SMA3)….. I’ve tried to pull down code snippets and put them together but can’t get them quite right. I currently have the 9, 12, and 26 SMA overlaid on my chart, with RSI and volume below but know it can be coded into a scan with an alert.

I watched the Hahn Tech video on the MACD RSI squeeze and tried to emulate the spike on the bottom of the chart when the criteria are met, but I can't quite figure it out.... . If everything goes the way it is in my head, it would display the spike on this chart and/or pop up as an alert when the above criteria are met The problem right now is that I’m not sure what definition to use where the ****** is, which (if it works out like I envision) is where the SMA9 starts to pull away from the SMA27 but it’s not yet oversold.

Here’s what I’ve got so far:
input price = close;
input length1 = 9;
input length2 = 27;
input length3 = 42;
input barsAfterCross = 2;

def SMA1 = SimpleMovingAvg(price, length1);
def SMA2 = SimpleMovingAvg(price, length2);
def SMA3= SimpleMovingAvg(price, length3);
def crossAbove = SMA1[1] < SMA2[1] and SMA1 > SMA2;
def crossBelow = SMA1[1] > SMA2[1] and SMA1 < SMA2;

SMA1.SetDefaultColor(CreateColor(0, 197, 47));
SMA2.SetDefaultColor(CreateColor(255, 126, 0));
SMA3.SetDefaultColor(CreateColor(204, 0, 51));

def overSoldRSI = RSI <= 40;

def ******** = SMA1 > SMA2 and SMA2 > SMA3
plot ******* if highest(overSoldRSI[1], 4) > 0;


Well-known member
The "def" is kind of what it says it is. You can define a condition. So you can name it anything.


New member
Well, that’s what I thought... so when I tried to name it “Breakout”, it was highlighted in red with an error. I didn’t know if it rejected it because I’d syntax or bc that definition is already used somewhere else.....?