SMA Breakout with RSI<50

A

AggieEMT

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:
Code:
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;
TIA!
 
horserider

horserider

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

AggieEMT

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.....?
 
Adeodatus

Adeodatus

New member
SO AHH, this is not doing something & I cant' program. Down at line 20 "plot...>0:" is red on thinkscript editor. Can someone help out?
I thought adding the last bottom two lines would work, well no such luck. It's Chinese to me

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 breakout = SMA1 > SMA2 and SMA2 > SMA3;
plot breakout if highest(overSoldRSI[1], 4) > 0;

plot breakout = asd;
breakout.SetDefaultColor(GetColor(0));
 
horserider

horserider

Well-known member
VIP
@Adeodatus That code is a mess. Start from scratch if you want to code what this thread describes.
 
Adeodatus

Adeodatus

New member
OK thanks, I just want to see a code to plot three SMA as the move up or down and cross, maybe four, nothing fancy. I thought AggieEMT had a nice one started but it's bust and but i cant write code. Back to square one again.
 
horserider

horserider

Well-known member
VIP
@Adeodatus

input price = close;
input length1 = 9;
input length2 = 27;
input length3 = 42;

plot SMA1 = SimpleMovingAvg(price, length1);
plot SMA2 = SimpleMovingAvg(price, length2);
plot SMA3 = SimpleMovingAvg(price, length3);

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

drayset

New member
@horserider how to get total ask buy (buy volume number) and total bid sell (sell volume number) for the day?
 

Similar threads

Top