Ok, I’ll only post the lines of code that you would add to each existing study:
Number One:
def ichiCloudCrossAbove = high[1] < "Span A" and high[1] < "Span B" and close > "Span A" and close > "Span B";
Alert(IchiCloudCrossAbove, "Cross Above Cloud", Alert.BAR, Sound.RING);
Note: the above code assumes a literal interpretation of your specification. So that the high of the previous bar must be under the cloud and the close of the current bar must be above the cloud
Number Two:
def rsiOneBarCrossBelow = RSI[1] > 79 and RSI < 21;
Alert(rsiOneBarCrossBelow, "RSI Cross Below", Alert.BAR, Sound.RING);
Number Three:
def rsiOneBarCrossAbove = RSI[1] < 21 and RSI > 79;
Alert(rsiOneBarCrossAbove, "RSI Cross Above", Alert.BAR, Sound.RING);
Hi Hahn.
I’m wondering how to plot these Alerts into scans. I’m used to using the ToS Scan tab to ALERT WATCHLIST SCAN when ”Scan” is ”equal to” value ”1”. There’s probably a better way but this is the only way I know.
It is very simple to convert an alert into a scan. The Alert() function takes four arguments. Each separated by a comma. The first of the four arguments is the true/false condition. So for the example I did for the Ichimoku, the first argument is ”IchiCloudCrossAbove”. If you want to convert that to a scan simply replace the Alert statement with ”plot scan = IchiCloudCrossAbove;”
Your code appears to be missing this line:
def rsiOneBarCrossBelow = RSI[1] > 79 and RSI < 21; The compiler should be giving you an error message while that line is missing.
Hahn,
I have that in my code (see below). I guess when I ran out of characters it cut off some of my coding.
——————–
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;
plot OverBought = over_Bought;
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 rsiOneBarCrossBelow = RSI[1] > 79 and RSI < 21; plot scan = rsiOneBarCrossBelow; Alert(rsiOneBarCrossBelow, "RSI Cross Below", Alert.BAR, Sound.RING);
Ok, that version appears correct. For a lower study, but not for a scan. A scan will only except a single plot statement so there is a lot that needs to be adjusted there. But for a lower study it will plot the RSI indicator along with the alert signal. Problem is the alert signal has a range of 0-1 while the RSI has a range 0-80. So you will never be able to see the signals with the naked eye. If you complete the conversion to a form that can run in a scan, you will be able to plot it as a lower study and see only the signal line.
Another issue to point out is that for the RSI to go from above 79 to below 21in a single bar, almost never happens….. when using the default settings. Go back and look at some charts and see if you can find any single day moves of the RSI from 79 down to 21. Then adjust the settings until you find one. Alternatively, you can change the values from 79 and 21 to something easily achieved such as 70 and 69.