Move Average Cross with RSI

maston21

New member
Wanted to know if anyone could create an indicator that creates a buy/sell tag on the upper chart. Conditions are:

Buy: 5 exp move avg greater than 13 exp move avg and RSI is above 50.

Sell 5 exp move avg less than 13 exp move avg and RSI is below 50

Any help would be greatly appreciated!

Wanted to see if we could add a condition to this script. As the script is now, the buy and sell signal appear when the move averages cross but I would like to add a condition for those buy and sell signals to occur only when RSI is above or below 50. Any help would be greatly appreciated!

Buy signal: Buy signal occurs when the faster move average crosses above the slower move average ( just as it is now) and RSI is above 50. Once those two conditions are met, the buy signal will generate.

Sell signal: Sell signal occurs when the faster move average crosses below the slower move average ( just as it is now) and RSI is below 50. Once those two conditions are met, the sell signal will generate.

Here is the code:
Ruby:
#hint: <b>Find Moving Average Xover</b>\nFinds when a fast moving average crosses over or under a slow.\n The fast average going above the slow average (bullish crossover) is a signal to buy, while the opposite situation (bearish crossover) is a signal to sell.

input price = close;#hint price: The price used to calculate the crossover. <b>(Default is CLOSE)</b>
input fastLength = 9;#hint fastLength: The number of bars used to calculate the fast moving average. <b>(Default is 3)</b>
input slowLength = 21;#hint slowLength: The number of bars used to calculate the slow moving average. <b>(Default is 8)</b>
input slowAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint slowAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Expontential)</b>
input fastAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint fastAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Exponential)</b>
Input DoArrows = no;#hint DoArrows:Yes shows arrows to define crosses
Input DoPlots = yes;#hint DoPlots: Yes shows MA plots to define crosses. Default is 'YES'
Input DoAlerts = No;#hint DoAlerts:No turns off alerts

Assert( fastLength < slowLength, "fastLength ["+fastLength+"] must be less than slowLength["+slowLength+"]");

def fastAvg;
switch (slowAvgType) {
case Simple:
fastAvg = Average(price, fastLength);
case Exponential:
fastAvg = ExpAverage(price, fastLength);
case Weighted:
fastAvg = wma(price, fastLength);
case Wilders:
fastAvg = WildersAverage(price, fastLength);
case Hull:
fastAvg = HullMovingAvg(price, fastLength);
}

def slowAvg;
switch (fastAvgType) {
case Simple:
slowAvg = Average(price, slowLength);
case Exponential:
slowAvg = ExpAverage(price, slowLength);
case Weighted:
slowAvg = wma(price, slowLength);
case Wilders:
slowAvg = WildersAverage(price, slowLength);
case Hull:
slowAvg = HullMovingAvg(price, slowLength);
}

plot signalXup = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.above) else Double.nan;

signalXup.SetDefaultColor(Color.pink);
signalXup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signalXup.SetLineWeight(3);
plot signalXdn = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.below) else Double.nan;

signalXdn.SetDefaultColor(Color.cyAN);
signalXdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signalXdn.SetLineWeight(3);

Alert(signalXup && DoAlerts, "UP...Fast MA Cross Above Slow MA", Alert.BAR, Sound.Ring );
Alert(signalXdn && DoAlerts, "Down...Fast Ma Cross Below Slow MA", Alert.BAR, Sound.Bell );

Plot fast_Avg = If DoPlots then Fastavg else double.nan;
fast_Avg.SetDefaultColor(Color.red);
fast_Avg.SetPaintingStrategy(PaintingStrategy.line);
fast_Avg.SetLineWeight(2);

Plot Slo_Avg = If DoPlots then Slowavg else double.nan;
Slo_Avg.SetDefaultColor(Color.cyan);
Slo_Avg.SetPaintingStrategy(PaintingStrategy.line);
Slo_Avg.SetLineWeight(2);

AddCloud(fastAvg, slowAvg, color.green, color.RED);
#AddLabel(1, "Fast MA(" + fastLength + ")",color.pink);
#AddLabel(1, "Slow MA(" + slowLength + ")",color.cyan);
#end

Wanted to see if anyone knew how to how to add a condition to the move average cross indicator. Would like to add RSI as a condition so when the move averages cross and produce a signal, RSI is taken into consideration as well to produce those signals. Thank you in advance for any assistance!

New Buy Condition: Fast move average crosses above slow move average and RSI is above 50, the buy signal is produced. As of right now the signal is produced when the move averages crosses.

New Sell Condition: Fast move average crosses below slow move average and RSI is below 50, the sell signal is produced. As of right now the signal is produced when the move averages crosses.

Here is the thinkscript I am using:
Ruby:
#hint: <b>Find Moving Average Xover</b>\nFinds when a fast moving average crosses over or under a slow.\n The fast average going above the slow average (bullish crossover) is a signal to buy, while the opposite situation (bearish crossover) is a signal to sell.

input price = close;#hint price: The price used to calculate the crossover. <b>(Default is CLOSE)</b>
input fastLength = 9;#hint fastLength: The number of bars used to calculate the fast moving average. <b>(Default is 3)</b>
input slowLength = 21;#hint slowLength: The number of bars used to calculate the slow moving average. <b>(Default is 8)</b>
input slowAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint slowAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Expontential)</b>
input fastAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint fastAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Exponential)</b>
Input DoArrows = no;#hint DoArrows:Yes shows arrows to define crosses
Input DoPlots = yes;#hint DoPlots: Yes shows MA plots to define crosses. Default is 'YES'
Input DoAlerts = No;#hint DoAlerts:No turns off alerts

Assert( fastLength < slowLength, "fastLength ["+fastLength+"] must be less than slowLength["+slowLength+"]");

def fastAvg;
switch (slowAvgType) {
case Simple:
fastAvg = Average(price, fastLength);
case Exponential:
fastAvg = ExpAverage(price, fastLength);
case Weighted:
fastAvg = wma(price, fastLength);
case Wilders:
fastAvg = WildersAverage(price, fastLength);
case Hull:
fastAvg = HullMovingAvg(price, fastLength);
}

def slowAvg;
switch (fastAvgType) {
case Simple:
slowAvg = Average(price, slowLength);
case Exponential:
slowAvg = ExpAverage(price, slowLength);
case Weighted:
slowAvg = wma(price, slowLength);
case Wilders:
slowAvg = WildersAverage(price, slowLength);
case Hull:
slowAvg = HullMovingAvg(price, slowLength);
}

plot signalXup = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.above) else Double.nan;

signalXup.SetDefaultColor(Color.pink);
signalXup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signalXup.SetLineWeight(3);
plot signalXdn = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.below) else Double.nan;

signalXdn.SetDefaultColor(Color.cyAN);
signalXdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signalXdn.SetLineWeight(3);

Alert(signalXup && DoAlerts, "UP...Fast MA Cross Above Slow MA", Alert.BAR, Sound.Ring );
Alert(signalXdn && DoAlerts, "Down...Fast Ma Cross Below Slow MA", Alert.BAR, Sound.Bell );

Plot fast_Avg = If DoPlots then Fastavg else double.nan;
fast_Avg.SetDefaultColor(Color.red);
fast_Avg.SetPaintingStrategy(PaintingStrategy.line);
fast_Avg.SetLineWeight(2);

Plot Slo_Avg = If DoPlots then Slowavg else double.nan;
Slo_Avg.SetDefaultColor(Color.cyan);
Slo_Avg.SetPaintingStrategy(PaintingStrategy.line);
Slo_Avg.SetLineWeight(2);

AddCloud(fastAvg, slowAvg, color.green, color.RED);
#AddLabel(1, "Fast MA(" + fastLength + ")",color.pink);
#AddLabel(1, "Slow MA(" + slowLength + ")",color.cyan);
#end
 
Last edited by a moderator:
Solution
Wanted to know if anyone could create an indicator that creates a buy/sell tag on the upper chart. Conditions are:

Buy: 5 exp move avg greater than 13 exp move avg and RSI is above 50.

Sell 5 exp move avg less than 13 exp move avg and RSI is below 50

Any help would be greatly appreciated!

Wanted to see if we could add a condition to this script. As the script is now, the buy and sell signal appear when the move averages cross but I would like to add a condition for those buy and sell signals to occur only when RSI is above or below 50. Any help would be greatly appreciated!

Buy signal: Buy signal occurs when the faster move average crosses above the slower move average ( just as it is now) and RSI is above 50. Once...
it looks like you posted twice.
i used notepad++ to compare the first half of your post to the 2nd half.
your words are different, but the 2 codes are the same.

here is your post, separated out.

Wanted to know if anyone could create an indicator that creates a buy/sell tag on the upper chart. Conditions are:

Buy: 5 exp move avg greater than 13 exp move avg and RSI is above 50.

Sell 5 exp move avg less than 13 exp move avg and RSI is below 50

Any help would be greatly appreciated!

Wanted to see if we could add a condition to this script. As the script is now, the buy and sell signal appear when the move averages cross but I would like to add a condition for those buy and sell signals to occur only when RSI is above or below 50. Any help would be greatly appreciated!

Buy signal: Buy signal occurs when the faster move average crosses above the slower move average ( just as it is now) and RSI is above 50. Once those two conditions are met, the buy signal will generate.

Sell signal: Sell signal occurs when the faster move average crosses below the slower move average ( just as it is now) and RSI is below 50. Once those two conditions are met, the sell signal will generate.

Here is the code:


Wanted to see if anyone knew how to how to add a condition to the move average cross indicator. Would like to add RSI as a condition so when the move averages cross and produce a signal, RSI is taken into consideration as well to produce those signals. Thank you in advance for any assistance!

New Buy Condition: Fast move average crosses above slow move average and RSI is above 50, the buy signal is produced. As of right now the signal is produced when the move averages crosses.

New Sell Condition: Fast move average crosses below slow move average and RSI is below 50, the sell signal is produced. As of right now the signal is produced when the move averages crosses.

Here is the thinkscript I am using:


Code:
#hint: <b>Find Moving Average Xover</b>\nFinds when a fast moving average crosses over or under a slow.\n The fast average going above the slow average (bullish crossover) is a signal to buy, while the opposite situation (bearish crossover) is a signal to sell.

input price = close;#hint price: The price used to calculate the crossover. <b>(Default is CLOSE)</b>
input fastLength = 9;#hint fastLength: The number of bars used to calculate the fast moving average. <b>(Default is 3)</b>
input slowLength = 21;#hint slowLength: The number of bars used to calculate the slow moving average. <b>(Default is 8)</b>
input slowAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint slowAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Expontential)</b>
input fastAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint fastAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Exponential)</b>
Input DoArrows = no;#hint DoArrows:Yes shows arrows to define crosses
Input DoPlots = yes;#hint DoPlots: Yes shows MA plots to define crosses. Default is 'YES'
Input DoAlerts = No;#hint DoAlerts:No turns off alerts

Assert( fastLength < slowLength, "fastLength ["+fastLength+"] must be less than slowLength["+slowLength+"]");

def fastAvg;
switch (slowAvgType) {
case Simple:
fastAvg = Average(price, fastLength);
case Exponential:
fastAvg = ExpAverage(price, fastLength);
case Weighted:
fastAvg = wma(price, fastLength);
case Wilders:
fastAvg = WildersAverage(price, fastLength);
case Hull:
fastAvg = HullMovingAvg(price, fastLength);
}

def slowAvg;
switch (fastAvgType) {
case Simple:
slowAvg = Average(price, slowLength);
case Exponential:
slowAvg = ExpAverage(price, slowLength);
case Weighted:
slowAvg = wma(price, slowLength);
case Wilders:
slowAvg = WildersAverage(price, slowLength);
case Hull:
slowAvg = HullMovingAvg(price, slowLength);
}

plot signalXup = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.above) else Double.nan;

signalXup.SetDefaultColor(Color.pink);
signalXup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signalXup.SetLineWeight(3);
plot signalXdn = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.below) else Double.nan;

signalXdn.SetDefaultColor(Color.cyAN);
signalXdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signalXdn.SetLineWeight(3);

Alert(signalXup && DoAlerts, "UP...Fast MA Cross Above Slow MA", Alert.BAR, Sound.Ring );
Alert(signalXdn && DoAlerts, "Down...Fast Ma Cross Below Slow MA", Alert.BAR, Sound.Bell );

Plot fast_Avg = If DoPlots then Fastavg else double.nan;
fast_Avg.SetDefaultColor(Color.red);
fast_Avg.SetPaintingStrategy(PaintingStrategy.line);
fast_Avg.SetLineWeight(2);

Plot Slo_Avg = If DoPlots then Slowavg else double.nan;
Slo_Avg.SetDefaultColor(Color.cyan);
Slo_Avg.SetPaintingStrategy(PaintingStrategy.line);
Slo_Avg.SetLineWeight(2);

AddCloud(fastAvg, slowAvg, color.green, color.RED);
#AddLabel(1, "Fast MA(" + fastLength + ")",color.pink);
#AddLabel(1, "Slow MA(" + slowLength + ")",color.cyan);
#end
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Wanted to know if anyone could create an indicator that creates a buy/sell tag on the upper chart. Conditions are:

Buy: 5 exp move avg greater than 13 exp move avg and RSI is above 50.

Sell 5 exp move avg less than 13 exp move avg and RSI is below 50

Any help would be greatly appreciated!

Wanted to see if we could add a condition to this script. As the script is now, the buy and sell signal appear when the move averages cross but I would like to add a condition for those buy and sell signals to occur only when RSI is above or below 50. Any help would be greatly appreciated!

Buy signal: Buy signal occurs when the faster move average crosses above the slower move average ( just as it is now) and RSI is above 50. Once those two conditions are met, the buy signal will generate.

Sell signal: Sell signal occurs when the faster move average crosses below the slower move average ( just as it is now) and RSI is below 50. Once those two conditions are met, the sell signal will generate.

Here is the code:

#hint: <b>Find Moving Average Xover</b>\nFinds when a fast moving average crosses over or under a slow.\n The fast average going above the slow average (bullish crossover) is a signal to buy, while the opposite situation (bearish crossover) is a signal to sell.

input price = close;#hint price: The price used to calculate the crossover. <b>(Default is CLOSE)</b>
input fastLength = 9;#hint fastLength: The number of bars used to calculate the fast moving average. <b>(Default is 3)</b>
input slowLength = 21;#hint slowLength: The number of bars used to calculate the slow moving average. <b>(Default is 8)</b>
input slowAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint slowAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Expontential)</b>
input fastAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint fastAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Exponential)</b>
Input DoArrows = no;#hint DoArrows:Yes shows arrows to define crosses
Input DoPlots = yes;#hint DoPlots: Yes shows MA plots to define crosses. Default is 'YES'
Input DoAlerts = No;#hint DoAlerts:No turns off alerts

Assert( fastLength < slowLength, "fastLength ["+fastLength+"] must be less than slowLength["+slowLength+"]");

def fastAvg;
switch (slowAvgType) {
case Simple:
fastAvg = Average(price, fastLength);
case Exponential:
fastAvg = ExpAverage(price, fastLength);
case Weighted:
fastAvg = wma(price, fastLength);
case Wilders:
fastAvg = WildersAverage(price, fastLength);
case Hull:
fastAvg = HullMovingAvg(price, fastLength);
}

def slowAvg;
switch (fastAvgType) {
case Simple:
slowAvg = Average(price, slowLength);
case Exponential:
slowAvg = ExpAverage(price, slowLength);
case Weighted:
slowAvg = wma(price, slowLength);
case Wilders:
slowAvg = WildersAverage(price, slowLength);
case Hull:
slowAvg = HullMovingAvg(price, slowLength);
}

plot signalXup = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.above) else Double.nan;

signalXup.SetDefaultColor(Color.pink);
signalXup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signalXup.SetLineWeight(3);
plot signalXdn = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.below) else Double.nan;

signalXdn.SetDefaultColor(Color.cyAN);
signalXdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signalXdn.SetLineWeight(3);

Alert(signalXup && DoAlerts, "UP...Fast MA Cross Above Slow MA", Alert.BAR, Sound.Ring );
Alert(signalXdn && DoAlerts, "Down...Fast Ma Cross Below Slow MA", Alert.BAR, Sound.Bell );

Plot fast_Avg = If DoPlots then Fastavg else double.nan;
fast_Avg.SetDefaultColor(Color.red);
fast_Avg.SetPaintingStrategy(PaintingStrategy.line);
fast_Avg.SetLineWeight(2);

Plot Slo_Avg = If DoPlots then Slowavg else double.nan;
Slo_Avg.SetDefaultColor(Color.cyan);
Slo_Avg.SetPaintingStrategy(PaintingStrategy.line);
Slo_Avg.SetLineWeight(2);

AddCloud(fastAvg, slowAvg, color.green, color.RED);
#AddLabel(1, "Fast MA(" + fastLength + ")",color.pink);
#AddLabel(1, "Slow MA(" + slowLength + ")",color.cyan);
#end

Wanted to see if anyone knew how to how to add a condition to the move average cross indicator. Would like to add RSI as a condition so when the move averages cross and produce a signal, RSI is taken into consideration as well to produce those signals. Thank you in advance for any assistance!

New Buy Condition: Fast move average crosses above slow move average and RSI is above 50, the buy signal is produced. As of right now the signal is produced when the move averages crosses.

New Sell Condition: Fast move average crosses below slow move average and RSI is below 50, the sell signal is produced. As of right now the signal is produced when the move averages crosses.

Here is the thinkscript I am using:

#hint: <b>Find Moving Average Xover</b>\nFinds when a fast moving average crosses over or under a slow.\n The fast average going above the slow average (bullish crossover) is a signal to buy, while the opposite situation (bearish crossover) is a signal to sell.

input price = close;#hint price: The price used to calculate the crossover. <b>(Default is CLOSE)</b>
input fastLength = 9;#hint fastLength: The number of bars used to calculate the fast moving average. <b>(Default is 3)</b>
input slowLength = 21;#hint slowLength: The number of bars used to calculate the slow moving average. <b>(Default is 8)</b>
input slowAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint slowAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Expontential)</b>
input fastAvgType = {default exponential, simple, Weighted, Wilders, Hull};#hint fastAvgType: Type of the fast moving average to be used for calculation. <b>(Default is Exponential)</b>
Input DoArrows = no;#hint DoArrows:Yes shows arrows to define crosses
Input DoPlots = yes;#hint DoPlots: Yes shows MA plots to define crosses. Default is 'YES'
Input DoAlerts = No;#hint DoAlerts:No turns off alerts

Assert( fastLength < slowLength, "fastLength ["+fastLength+"] must be less than slowLength["+slowLength+"]");

def fastAvg;
switch (slowAvgType) {
case Simple:
fastAvg = Average(price, fastLength);
case Exponential:
fastAvg = ExpAverage(price, fastLength);
case Weighted:
fastAvg = wma(price, fastLength);
case Wilders:
fastAvg = WildersAverage(price, fastLength);
case Hull:
fastAvg = HullMovingAvg(price, fastLength);
}

def slowAvg;
switch (fastAvgType) {
case Simple:
slowAvg = Average(price, slowLength);
case Exponential:
slowAvg = ExpAverage(price, slowLength);
case Weighted:
slowAvg = wma(price, slowLength);
case Wilders:
slowAvg = WildersAverage(price, slowLength);
case Hull:
slowAvg = HullMovingAvg(price, slowLength);
}

plot signalXup = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.above) else Double.nan;

signalXup.SetDefaultColor(Color.pink);
signalXup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signalXup.SetLineWeight(3);
plot signalXdn = If DoArrows Then crosses(fastAvg, slowAvg, CrossingDirection.below) else Double.nan;

signalXdn.SetDefaultColor(Color.cyAN);
signalXdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signalXdn.SetLineWeight(3);

Alert(signalXup && DoAlerts, "UP...Fast MA Cross Above Slow MA", Alert.BAR, Sound.Ring );
Alert(signalXdn && DoAlerts, "Down...Fast Ma Cross Below Slow MA", Alert.BAR, Sound.Bell );

Plot fast_Avg = If DoPlots then Fastavg else double.nan;
fast_Avg.SetDefaultColor(Color.red);
fast_Avg.SetPaintingStrategy(PaintingStrategy.line);
fast_Avg.SetLineWeight(2);

Plot Slo_Avg = If DoPlots then Slowavg else double.nan;
Slo_Avg.SetDefaultColor(Color.cyan);
Slo_Avg.SetPaintingStrategy(PaintingStrategy.line);
Slo_Avg.SetLineWeight(2);

AddCloud(fastAvg, slowAvg, color.green, color.RED);
#AddLabel(1, "Fast MA(" + fastLength + ")",color.pink);
#AddLabel(1, "Slow MA(" + slowLength + ")",color.cyan);
#end
maston21, here is a script that places an up arrow when EMA5 crosses EMA13 and RSI is above 50 and places a down arrow when EMA5 crosses below EMA13 and RSI is below 50.

I looked at some charts and am a bit surprised at how promising this looks. I think it needs another filter to reduce the occasional back-to-back signals, but seems like a great starting framework for a strategy.

Screenshot (1711).png


Code:
# EMAcrossPlusRSI50
# question from maston21 on 4-15-24

input price = close;
input length1 = 5;
input length2 = 13;
input averagetype = AverageType.EXPONENTIAL;
input RSIlength = 14;
input averagetype2 = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType2, price - price[1], RSIlength);
def TotChgAvg = MovingAverage(averageType2, AbsValue(price - price[1]), RSIlength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def FastMA = movingaverage(averagetype, price, length1);
def SlowMA = movingaverage(averagetype, price, length2);

plot UpSignal = FastMA crosses above SlowMA and RSI > 50;
plot DownSignal = FastMA crosses below SlowMA and RSI < 50;

UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpSignal.SetDefaultColor(Color.BLUE);
UpSignal.SetLineWeight(4);

DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownSignal.SetDefaultColor(Color.RED);
DownSignal.SetLineWeight(4);
 
Last edited by a moderator:
Solution
I have one more request @traderLK. Is there any way to replace the buy/sell arrows with a simple label that shows up in its place with a buy/sell label? Only asking so it would be different if any other arrows are used on the chart and would stand out.

UPDATE:
I figured it out!

# EMAcrossPlusRSI50
# question from maston21 on 4-15-24

input price = close;
input length1 = 5;
input length2 = 13;
input averagetype = AverageType.EXPONENTIAL;
input RSIlength = 14;
input averagetype2 = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType2, price - price[1], RSIlength);
def TotChgAvg = MovingAverage(averageType2, AbsValue(price - price[1]), RSIlength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def FastMA = movingaverage(averagetype, price, length1);
def SlowMA = movingaverage(averagetype, price, length2);

plot UpSignal = FastMA crosses above SlowMA and RSI > 50;
plot DownSignal = FastMA crosses below SlowMA and RSI < 50;



AddChartBubble(UpSignal, low, "Bullish", Color.light_green, no);
AddChartBubble(DownSignal, high, "Bearish", Color.light_red, no);
 
Last edited by a moderator:
Thank you so much @traderLK! This is a strategy that I am using and wanted something simple on the chart to indicate when both conditions are met.

Not sure what could be added when consolidation occurs to eliminate back to back signals.
 
I have one more request @traderLK. Is there any way to replace the buy/sell arrows with a simple label that shows up in its place with a buy/sell label? Only asking so it would be different if any other arrows are used on the chart and would stand out.

UPDATE:
I figured it out!

# EMAcrossPlusRSI50
# question from maston21 on 4-15-24

input price = close;
input length1 = 5;
input length2 = 13;
input averagetype = AverageType.EXPONENTIAL;
input RSIlength = 14;
input averagetype2 = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType2, price - price[1], RSIlength);
def TotChgAvg = MovingAverage(averageType2, AbsValue(price - price[1]), RSIlength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def FastMA = movingaverage(averagetype, price, length1);
def SlowMA = movingaverage(averagetype, price, length2);

plot UpSignal = FastMA crosses above SlowMA and RSI > 50;
plot DownSignal = FastMA crosses below SlowMA and RSI < 50;



AddChartBubble(UpSignal, low, "Bullish", Color.light_green, no);
AddChartBubble(DownSignal, high, "Bearish", Color.light_red, no);

Hi maston21,

Good job with the labels, I wonder if it might help to write Buy and Sell or B and S in the labels because they'll take up less space.

I've been playing around with potential filters to reduce whipsaws and the best of all the ones I tested was to simply add a 100 period EMA and only take buy signals when price has closed above the line and only take sell signals when price is below the line.

A version 2 of the script that includes this filter is shown below. I'm also going to try to attach two charts with one using v1 and one using v2 (totally cherry-picked to make the point). If the 2nd chart doesn't work, I'll put it in the next post.

In my tests the new filter consistently improved results, though it's important to note that this was using specific rules for entries and stoplosses that I prefer to use.

Chart with v1:
srRwnlq.png


Chart with v2:
f8SOAoF.png



Code:
# EMAcrossPlusRSI50v2
# question from maston21 on 4-15-24
# version 2 adds rule that arrows only occur if price has closed at or above a longterm MA line for UpSignals and at or below a longterm MA line for DownSignals

input price = close;
input length1 = 5;
input length2 = 13;
input RSIlength = 14;
input averagetype2 = AverageType.WILDERS;
input length3 = 100;
input averagetype = AverageType.EXPONENTIAL;

def NetChgAvg = MovingAverage(averageType2, price - price[1], RSIlength);
def TotChgAvg = MovingAverage(averageType2, AbsValue(price - price[1]), RSIlength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def FastMA = movingaverage(averagetype, price, length1);
def SlowMA = movingaverage(averagetype, price, length2);
def SlowestMA = movingaverage(averagetype, price, length3);

plot UpSignal = FastMA crosses above SlowMA and RSI > 50 and close >= SlowestMA;
plot DownSignal = FastMA crosses below SlowMA and RSI < 50 and close <= SlowestMA;

UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpSignal.SetDefaultColor(Color.BLUE);
UpSignal.SetLineWeight(4);

DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownSignal.SetDefaultColor(Color.RED);
DownSignal.SetLineWeight(4);
 
Last edited by a moderator:
@traderLK Also wanted to make this script so that you can choose which move averages someone would prefer for both move averages individually (exp, simple. weighted etc). Understand what you were saying about the labels and I did look at that but wanted to make it a bit more obvious without having to hunt for it but without being totally obstructive. That is something someone could easily change if they want though.

@traderLK I am noticing that when the move averages cross and the rsi moves above/below 50, no signal is produced both do not happen within a short time. Have seen several times when there is more than two days difference between the two crosses, no signal is produced even though it should have.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
218 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top