♥ 0 |
Good morning Hahn, Hope all is well. I was wondering if you could help me out or lead me in the right direction. In ToS Scan, I would like to have a scan alert that I could set to my phone for the following situation. For example, If RSI signals Oversold 2 or more times within the following 5 bars, then the Moving Average (9) crosses above the Moving Average (18), send an alert text/plot arrow up I would like to be able to adjust the following inputs above: RSI Oversold RSI Overbought min number of times = 2 (shown in example) length of time for the signal = 5 (shown in example) moving avg. #1 = 9 (shown in example) moving avg. #2 = (shown in example)
Thanks, Robin Hood
Marked as spam
|
Private answer
I think this will do the trick. I’m logged into PaperMoney side today and the scans are only available on the real money side. So I could not test it.
Marked as spam
|
|||||||||||||||||
Private answer
Ok, given the clarified specification I have an updated version of the code I provided previously. The original version merely counted how many bars the RSI was in Oversold state. The new version counts how many time the RSI crosses from above Oversold to below Oversold Once again, this is setup as a scan and not a lower study to keep things within the context of the original request to send text alert to a phone. A chart study is not able to send text alerts. You must use this code in a Study Alert or a Scan in order to enable text alerts for this code.
Marked as spam
|
Please log in to post questions.
It worked but I need to make a slight change & not sure how to do it. RSI oversold hits needs to be changed to ”rsiOneBarCrossAbove” hits as shown in the code below.
=============
declare lower;
input length = 14;
input over_Bought = 80;
input over_Sold = 20;
input price = close;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, price – price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price – price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
OverSold.SetDefaultColor(Color.CYAN);
OverSold.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot OverBought = over_Bought;
OverBought.SetDefaultColor(Color.MAGENTA);
OverBought.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
RSI.DefineColor(”OverBought”, GetColor(5));
RSI.DefineColor(”Normal”, GetColor(7));
RSI.DefineColor(”OverSold”, GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.Color(”OverBought”) else if RSI < over_Sold then RSI.Color("OverSold") else RSI.Color("Normal")); OverSold.SetDefaultColor(GetColor(8)); OverBought.SetDefaultColor(GetColor(8)); def rsiOneBarCrossAbove = RSI[1] > 20 and RSI < 20; plot scanUp = rsiOneBarCrossAbove; scanUp.SetDefaultColor(Color.CYAN); scanUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); def rsiOneBarCrossBelow = RSI[1] < 80 and RSI > 80;
plot scanDown = rsiOneBarCrossBelow;
scanDown.SetDefaultColor(Color.MAGENTA);
scanDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Alert(rsiOneBarCrossAbove, ”RSI Cross Above 80”, Alert.BAR, Sound.Ring);
Alert(rsiOneBarCrossBelow, ”RSI Cross Below 20”, Alert.BAR, Sound.Ring);
Couple things about your original request and the code you have included in the comment above.
First is that you are asking for this to send alerts to your phone. The code you have posted here is for a chart study. Not a scan. If you want to send alerts to your phone you must build this as a scan and not a custom chart study.
Second is that your original specification states the following:
”If RSI signals Oversold 2 or more times within the following 5 bars, then the Moving Average (9) crosses above the Moving Average (18), send an alert text/plot arrow up”
In order to modify the code to achieve some different specification you need to clearly state what that new specification is. So please explain what has changed from your original specification that I have quoted here.
Hi Hahn,
Correct me if I’m wrong, I believe there is a difference between the current RSI oversold hits & (RSIcrossAbove>20 in 1bar) scan shown in my scan pasted in the previous comment. Instead of ”oversold hits”, I want the hits to be the number of times RSI crosses from below 20 to above 20. Here’s my example showing 2 hits within 4 ticks (i.e. If RSI is at 18 then is at 22 at the next bar = 1 hit, next bar RSI goes from 22 to 21=0 hits, next bar RSI goes from 21 to 19=0 hits, next bar RSI goes from 19 to 23= 1 hit (2nd hit).
If this code seems familiar, you helped make it.
==========
def rsiOneBarCrossAbove = RSI[1] > 20 and RSI < 20; plot scanUp = rsiOneBarCrossAbove; scanUp.SetDefaultColor(Color.CYAN); scanUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); def rsiOneBarCrossBelow = RSI[1] < 80 and RSI > 80;
plot scanDown = rsiOneBarCrossBelow;
scanDown.SetDefaultColor(Color.MAGENTA);
scanDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Alert(rsiOneBarCrossAbove, ”RSI Cross Above 20”, Alert.BAR, Sound.Ring);
Alert(rsiOneBarCrossBelow, ”RSI Cross Below 80”, Alert.BAR, Sound.Ring);