RSI + MACD Confluence Indicator for ThinkorSwim

Shinthus

Shinthus

Member
2019 Donor
Thanks to BenTen's assembling skills, I bring you this indicator. I haven't named it yet, but it revolves around the RSI coming up from O/S to 34 and coming down from O/B to 66.... while the MACD crosses at the same exact time. I got this idea from Chad Brinkman's Youtube channel. He is a day trader. Check out these 3 vids to get an idea of where this came from:


Here is what the indicator looks like





This works on all timeframes. You can edit the MACD lengths and RSI O/S and O/B levels as you please. The indicator came hot off the script plate from BenTen with standard MACD settings but as I backtested, I realized I needed something faster. I ended up using Chad's faster settings of 6,9,and13 for MACD. As for the RSI, it's my understanding that 34/66 or 35/65 levels are pretty much equal in terms of signal quality.

Please play around with this and post your thoughts here.

Indicator: https://tos.mx/wyPd1m

Code:
plot Data = close;
# MACD+RSI 34 Trading Indicator
# Assembled by BenTen at useThinkScript.com
# Concept shared by @Ohta via Discord
# You are free to use this code for personal use, and make derivative works from it. You are NOT GRANTED permission to use this code (or derivative works) for commercial purposes which includes and is not limited to selling, reselling, or packaging with other commercial indicators. Headers and attribution in this code should remain as provided, and any derivative works should extend the existing headers.

# RSI
input length = 14;
input price = close;
input over_Bought = 66;
input over_Sold = 34;
input RSIaverageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(RSIaverageType, price - price[1], length);
def TotChgAvg = MovingAverage(RSIaverageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;

def RSIup = RSI crosses above OverSold;
def RSIdwn = RSI crosses below OverBought;

input fastLength = 6;
input slowLength = 9;
input MACDLength = 12;
input averageType = AverageType.EXPONENTIAL;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

def Diff = Value - Avg;
def ZeroLine = 0;

def UpSignal = Diff crosses above ZeroLine;
def DwnSignal = Diff crosses below ZeroLine;

plot bullish = UpSignal and RSIup;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(3);

plot bearish = DwnSignal and RSIdwn;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.CYAN);
bearish.SetLineWeight(3);
 
Last edited by a moderator:
horserider

horserider

Well-known member
VIP
Ok sorry to be critical of this indicator. Good job putting it together. I do not think that guy in the video understands the RSI and MACD. He is putting together two indicators measuring the same thing. Just the calculations differ. So the AH HA moment is both align . Of course they will as RSI is a first derivative of price and MACD a second. As Markos has said many times you do not want to use indicators showing the same information. The gentleman in the video has also done the same thing with the BB and Ichimoku.
Ok back to this indicator, my opinion is you will have a difficult time making the arrows work well. I think there are better indicators to use in making arrows. I have put several on this site already.
 
Shinthus

Shinthus

Member
2019 Donor
Ok sorry to be critical of this indicator. Good job putting it together. I do not think that guy in the video understands the RSI and MACD. He is putting together two indicators measuring the same thing. Just the calculations differ. So the AH HA moment is both align . Of course they will as RSI is a first derivative of price and MACD a second. As Markos has said many times you do not want to use indicators showing the same information. The gentleman in the video has also done the same thing with the BB and Ichimoku.
Ok back to this indicator, my opinion is you will have a difficult time making the arrows work well. I think there are better indicators to use in making arrows. I have put several on this site already.
How are the BB and Ichimoku interpreted the same way?
 
horserider

horserider

Well-known member
VIP
@Shinthus I am going by what the guy describes in the video. If you notice where he picks support/resistance on ichi it is very close to the midline or outer band of BB. He picks that 9.35 level, so go count the ichi ahead and see when that level appears as to when he calls it. Looks like the ichi is still heading down. That level is also close to mid BB if I remember correctly. Easy to make a video after the fact but at least make sure what you describe has actually happened. Notice how he ignores the many arrows followed by a cross that go nowhere and sometimes trades before the cross. I guess my opinion is this is not a good strategy. As long as the RSI is below 50 the strength is weak and a bounce off the 50 is a possibility. If you can make it work then go for it.
 
L

laukce01

New member
I'm looking for some help on making a custom indicator looking at the Simple Moving Average (10 period) and the MACD (8,17,9). I want to be able to plot a buy or sell signal when I get 2 green or 2 red arrows respectively.

It would be preferred that the 2 arrows align in the same time period but it would also be acceptable if they are off by maybe 1 or 2 time periods if that makes sense. For example, if the MA would trigger a green first and then a candle or 2 later the MACD would trigger.

Any help on this would be greatly appreciated! Thanks so much!

laukce01
 
BenTen

BenTen

Administrative
Staff
VIP
@laukce01 Take a look at the code above. It's similar to what you're looking for. Just need to change the RSI portion to your desired moving average.
 
L

laukce01

New member
Thanks Ben,

I'm pretty new to Thinkscript. Do you have any code as it pertains to the Moving Avg from another thread? I searched and nothing jumped out at me.
 
BenTen

BenTen

Administrative
Staff
VIP
@laukce01 SMA and EMA are available in your ThinkorSwim. You should be able to get access to the code directly inside the platform.
 
L

laukce01

New member
I really need some help with this and I'm having trouble.

I took the RSI code as you said from above and tried to replace with the the SMA code within TOS but am not having any luck.

I basically want it so when the SMA crosses above or below the 10 SMA And when the MACD crosses above or below the zero line to give me a single red or green arrow.

I got it to work for the MACD portion but when I added the SMA part it messed it up.

Code:
plot Data = close;


# SMA
input price = close;
input length = 10;
input displace = 0;

plot SMA = Average(price[-displace], length);
plot UpSignal2 = price crosses above SMA;
plot DwnSignal2 = price crosses below SMA;

SMA.SetDefaultColor(GetColor(1));


# MACD
input fastLength = 6;
input slowLength = 9;
input MACDLength = 12;
input averageType = AverageType.EXPONENTIAL;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

def Diff = Value - Avg;
def ZeroLine = 0;

def UpSignal = Diff crosses above ZeroLine;
def DwnSignal = Diff crosses below ZeroLine;

plot bullish = UpSignal and UpSignal2;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(3);

plot bearish = DwnSignal and DwnSignal2;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.CYAN);
bearish.SetLineWeight(3);

CORRECTION: I basically want it so when the PRICE crosses above or below the 10 SMA And when the MACD crosses above or below the zero line to give me a single red or green arrow.
 
Last edited by a moderator:
BenTen

BenTen

Administrative
Staff
VIP
@laukce01 Do you have any chart examples of where both conditions happened within the same candle?
 
L

laukce01

New member
How do you attach a screenshot?

There are instances where it happens with both candles but it's also ok if they are staggered or offset by a couple candles too. For example, the SMA triggers first and then the MACD maybe a candle or 2 later and vice versus.
 
L

laukce01

New member
Please see screen shot below. In middle to late Aug there is a Red and Green arrow on both candles. But like I said they can be offset by several or even multiple candles.

 
L

laukce01

New member
No disrespect, but why do you need more examples? Do you not understand the goal of what I am trying to accomplish? If you pull any company on TOS with a 10 period SMA and the MACD (8,17,9) and look at 10 years of history there are plenty of examples. Again, for my purpose they don't need to be aligned during the exact time period. Please let me know if you need more clarification. Thanks!
 
L

laukce01

New member
So basically, instead of having 2 separate graphs (SMA and MACD) with 2 red or green arrows like I have above in the screenshot, I want to show just the price graph with one buy or sell indicator. And the buy or sell indicator would not show up until BOTH conditions are met. So if you get a Green arrow on the SMA and any number of time periods later you get a green arrow from the MACD then and only then you see a single Buy or Green arrow on the price graph. And likewise in reverse for the Red arrows. Does that make sense?
 
L

laukce01

New member


Code:
#Here is the code I used for the above image. There seems to be an issue with the arrows. Sometimes it works and sometimes it doesn't. Any help would be appreciated.

def SMA10 = SimplemovingAvg(close,10);

def MH = MACDHistogram(8,17,9);

plot bullish = if (close > SMA10 and close[1] <= SMA10[1]) and MH >= 0 then 1 else 0;

plot bearish = if (close < SMA10 and close[1] >= SMA10[1]) and MH <= 0 then 1 else 0;

bullish.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Up);

bearish.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Down);

Bullish.setLineWeight(3);
Bearish.setLineWeight(3);
 
MerryDay

MerryDay

Active member
VIP
One way to start debugging your code is to use AddChartBubble.

By adding the following code to your script, it will test for each of your conditions on each and every candle.
When you determine which condition is being returned in error; you can redefine your tests to display each variable in that condition and thus verify your logic. HTH
Code:
def Test1 = if close > SMA10 then 1 else 0;
def Test2 = if close[1] <= SMA10[1] then 1 else 0;;
def Test3 = if MH >= 0 then 1 else 0;;

AddChartBubble(close, close, bullish +" | "  +Test1 +" | " +Test2 +" | " +Test3, color.light_gray);
 
L

laukce01

New member
#Below is the code that I have so far. It partially works. The MACD portion worked perfect but when adding the SMA script and I go to plot it, I think it's looking for conditions that are met at the exact same time frame or candle. When the price crosses the SMA at a different time from the MACD no arrow shows up. I want to show an arrow when BOTH conditions are met even if it's not in the same time period. It may not even be looking at the SMA at all and only the MACD. I don't know. Would you be able to look at this code and see where there may be an issue? Thanks for your help.

#See attached screenshot.




Code:
#SMA

input price = close;

input length = 10;



Def SMA = Average(price,length);

Def SMAup = price >= SMA;

Def SMAdwn = price <= SMA;



#MACD

input fastLength = 8;

input slowLength = 17;

input MACDLength = 9;

input averageType = AverageType.EXPONENTIAL;



def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);

def Avg = MovingAverage(averageType, Value, MACDLength);



def Diff = Value - Avg;

def ZeroLine = 0;



def UpSignal = Diff crosses above ZeroLine;

def DwnSignal = Diff crosses below ZeroLine;



plot bullish = UpSignal AND SMAup;

bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

bullish.SetDefaultColor(Color.UPTICK);

bullish.SetLineWeight(3);



plot bearish = DwnSignal AND SMAdwn;

bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

bearish.SetDefaultColor(Color.DOWNTICK);

bearish.SetLineWeight(3);
 
L

laukce01

New member
Any update on this? How do I get any assistance to my questions?
 

Similar threads

Top