Ultimate MACD For ThinkOrSwim

petertn

New member
Hi guys!

Can anyone convert this MACD+RSI TradingView Indicator into a TOS indicator? Here is the link to the author's indicator: https://www.tradingview.com/script/aM7pePxC-Ultimate-MACD/. It is an open-source code and I take no credit for this author's indicator and any usage of author's code is strictly for personal use.

I want a red dot to appear every time RSI is greater than 50 as shown below. The red dot will disappear when RSI is less than 50. The blue/orange lines + histogram is just your standard MACD settings.

Thank you all for taking your time to read this post!
1695226042651.png
 
Hi guys!

Can anyone convert this MACD+RSI TradingView Indicator into a TOS indicator? Here is the link to the author's indicator: https://www.tradingview.com/script/aM7pePxC-Ultimate-MACD/. It is an open-source code and I take no credit for this author's indicator and any usage of author's code is strictly for personal use.

I want a red dot to appear every time RSI is greater than 50 as shown below. The red dot will disappear when RSI is less than 50. The blue/orange lines + histogram is just your standard MACD settings.

Thank you all for taking your time to read this post!
View attachment 19773
check below

CSS:
# https://www.tradingview.com/v/aM7pePxC/
#//@taufan_ganas
#indicator(title='Ultimate MACD')
# converted by Sam4Cok@Samer800 - 09/2023 - request form ww.usethinkscript.com member
declare lower;

input source = close;
input RSIstrength = 50;# (defval=50, title='RSI Strength Level', group=grp_1)
input fastLength = 8;# minval=1, title='MACD Fast Length', group=grp_2)
input slowLength = 16;# minval=1, title='MACD Slow Length', group=grp_2)
input signalLength = 11;# minval=1, title='MACD Signal Length', group=grp_2)
input fastLength1 = 12;#, minval=1, title='MACD Fast Length', group=grp_3)
input slowLength1 = 26;# minval=1, title='MACD Slow Length', group=grp_3)
input signalLength1 = 9;# minval=1, title='MACD Signal Length', group=grp_3)
input periodK = 14;# title='K', minval=1)
input periodD = 3;# title='D', minval=1)
input smoothK = 3;# title='Smooth', minval=1)

def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;


def fastMA = ExpAverage(source, fastLength);
def slowMA = ExpAverage(source, slowLength);
def macd = fastMA - slowMA;
def signal = Average(macd, signalLength);
def hist = macd - signal;

#//RSI Color
def rsivalue = rsi(Price = close,Length = 14);
def colorsi = rsivalue >= RSIstrength;

#//Plot RSI

plot rsiPlot = if colorsi then 0 else na;
rsiPlot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
rsiPlot.SetDefaultColor(Color.YELLOW);
#//Plot MACD

plot macdHist = hist;#, title='Histogram'
macdHist.SetLineWeight(4);
macdHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
macdHist.AssignValueColor(if hist >= 0 then if hist[1] < hist then Color.GREEN else Color.DARK_GREEN else
                                            if hist[1] < hist then Color.DARK_RED else Color.RED);

plot sigLine = signal;#, color=color.new(color.red, 0), linewidth=1)
plot macLine = macd;#, color=color.new(color.blue, 0), linewidth=1)
sigLine.SetDefaultColor(GetColor(8));
macLine.SetDefaultColor(GetColor(1));

#  'SLOW MACD SETTINGS:'
def fastMA1 = ExpAverage(source, fastLength1);
def slowMA1 = ExpAverage(source, slowLength1);
def macd1 = fastMA1 - slowMA1;
def signal1 = Average(macd1, signalLength1);

AddCloud(if macd1 >= signal1 then pos else na, neg, Color.BLUE);

def intersection1 = macd >= signal;
def intersection2 = macd1 >= signal1;

AddCloud(if !intersection1 and !intersection2 then pos else na, neg, Color.DARK_RED);
AddCloud(if intersection2 then pos else na, neg, Color.BLUE);
AddCloud(if intersection1 then pos else na, neg, Color.YELLOW);

# //Stochastic

def k = StochasticFull(KPeriod = periodK, DPeriod = periodD, slowing_period = smoothK).FullK;
def d = StochasticFull(KPeriod = periodK, DPeriod = periodD, slowing_period = smoothK).FullD;

def stobull = Crosses(k, d, CrossingDirection.ABOVE) and k <= 20;# ? #3179f5 : na
def stobear = Crosses(d, k, CrossingDirection.ABOVE) and k >= 80;# ? #ff3b7d : na

plot CrossUp = if stobull then 0 else na;#, color=stobull, style=plot.style_cross, linewidth=4)
plot CrossDn = if stobear then 0 else na;#, color=stobear, style=plot.style_cross, linewidth=4)
CrossUp.SetDefaultColor(Color.CYAN);
CrossDn.SetDefaultColor(Color.MAGENTA);
CrossUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
CrossDn.SetPaintingStrategy(PaintingStrategy.SQUARES);

#-- END of CODE
 
This is a slick indicator. That RSI triangle which turns on (yellow, RSI > 50 bullish) and triangle off (RSI < 50 bearish) paired with the MACD lines and histogram is powerful. This indicator combination, timing-wise, correlates very well with price movement. Not much lag either its pretty quick. I change the fast MACD to 8,17,6 to match the 12,26,9 ratio. I had a lot of success scalping /NQZ23 while focusing on the action of this indicator.

Appreciate the effort - thanks so much.
 
Just an idea…What about:
-Dot across the whole indicator center line.
-four colors: green over 50 and increasing, dark green over 50 and decreasing, then red for under 50 and decreasing and dark red for under 50 and increasing.
 
@jonesjb Replace the RSI plot with this:

Code:
#//Plot RSI
plot rsiPlot = if colorsi then 0 else na;
rsiPlot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
#rsiPlot.SetDefaultColor(Color.YELLOW);
rsiPlot.AssignValueColor(
if rsiValue >= 50 and rsiValue > rsiValue[1] then Color.GREEN
else if rsiValue >= 50 and rsiValue < rsiValue[1] then Color.DARK_GREEN
else if rsiValue < 50 and rsiValue < rsiValue[1] then Color.RED
else if rsiValue < 50 and rsiValue > rsiValue[1] then Color.DARK_RED
else Color.GRAY);

Hope this helps...

Good Luck and Good Trading :cool:
 
Last edited:
@jonesjb Replace the RSI plot with this:

Code:
#//Plot RSI
plot rsiPlot = if colorsi then 0 else na;
rsiPlot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
#rsiPlot.SetDefaultColor(Color.YELLOW);
rsiPlot.AssignValueColor(
if rsiValue >= 50 and rsiValue > rsiValue[1] then Color.GREEN
else if rsiValue >= 50 and rsiValue < rsiValue[1] then Color.DARK_GREEN)
else if rsiValue < 50 and rsiValue < rsiValue[1] then Color.RED)
else if rsiValue < 50 and rsiValue > rsiValue[1] then Color.DARK_RED
else Color.GRAY);

Hope this helps...

Good Luck and Good Trading :cool:
Hi @netarchitech. Thank you for this. For some reason after the cut/paste and removal of the original code, the TOS doesn't like it. I'm just learning scripting in TOS so I'm sure sure what the issue it.
 
Hi @cmierzwa: Sorry for the errors...Should have done this right in TOS, instead of quickly in a text editor...In any event, the following code should work properly...just make sure to replace both the RSI Color and Plot RSI sections in the existing Ultimate MACD code...

Code:
#//RSI Color
def rsivalue = rsi(Price = close,Length = 14);
def colorsi = rsivalue <> RSIstrength;

#//Plot RSI
plot rsiPlot = if colorsi then 0 else na;
rsiPlot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
rsiPlot.SetLineWeight(3);
rsiPlot.AssignValueColor(
if rsiValue > 50 and rsiValue > rsiValue[1] then Color.GREEN
else if rsiValue > 50 and rsiValue < rsiValue[1] then Color.DARK_GREEN
else if rsiValue < 50 and rsiValue < rsiValue[1] then Color.RED
else if rsiValue < 50 and rsiValue > rsiValue[1] then Color.DARK_RED
else Color.GRAY);

Hope this helps...

Good Luck and Good Trading :cool:
 
Hi @cmierzwa: Sorry for the errors...Should have done this right in TOS, instead of quickly in a text editor...In any event, the following code should work properly...just make sure to replace both the RSI Color and Plot RSI sections in the existing Ultimate MACD code...

Code:
#//RSI Color
def rsivalue = rsi(Price = close,Length = 14);
def colorsi = rsivalue <> RSIstrength;

#//Plot RSI
plot rsiPlot = if colorsi then 0 else na;
rsiPlot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
rsiPlot.SetLineWeight(3);
rsiPlot.AssignValueColor(
if rsiValue > 50 and rsiValue > rsiValue[1] then Color.GREEN
else if rsiValue > 50 and rsiValue < rsiValue[1] then Color.DARK_GREEN
else if rsiValue < 50 and rsiValue < rsiValue[1] then Color.RED
else if rsiValue < 50 and rsiValue > rsiValue[1] then Color.DARK_RED
else Color.GRAY);

Hope this helps...

Good Luck and Good Trading :cool:
Fantastic! Thank you again :)
 
@Swamibapa: Comment out the following "AddCloud" lines:

Code:
#  'SLOW MACD SETTINGS:'
def fastMA1 = ExpAverage(source, fastLength1);
def slowMA1 = ExpAverage(source, slowLength1);
def macd1 = fastMA1 - slowMA1;
def signal1 = Average(macd1, signalLength1);

#AddCloud(if macd1 >= signal1 then pos else na, neg, Color.BLUE);

def intersection1 = macd >= signal;
def intersection2 = macd1 >= signal1;

#AddCloud(if !intersection1 and !intersection2 then pos else na, neg, Color.DARK_RED);
#AddCloud(if intersection2 then pos else na, neg, Color.BLUE);
#AddCloud(if intersection1 then pos else na, neg, Color.YELLOW);

Hope that helps...

Good Luck and Good Trading :cool:
 
check below

CSS:
# https://www.tradingview.com/v/aM7pePxC/
#//@taufan_ganas
#indicator(title='Ultimate MACD')
# converted by Sam4Cok@Samer800 - 09/2023 - request form ww.usethinkscript.com member
declare lower;

input source = close;
input RSIstrength = 50;# (defval=50, title='RSI Strength Level', group=grp_1)
input fastLength = 8;# minval=1, title='MACD Fast Length', group=grp_2)
input slowLength = 16;# minval=1, title='MACD Slow Length', group=grp_2)
input signalLength = 11;# minval=1, title='MACD Signal Length', group=grp_2)
input fastLength1 = 12;#, minval=1, title='MACD Fast Length', group=grp_3)
input slowLength1 = 26;# minval=1, title='MACD Slow Length', group=grp_3)
input signalLength1 = 9;# minval=1, title='MACD Signal Length', group=grp_3)
input periodK = 14;# title='K', minval=1)
input periodD = 3;# title='D', minval=1)
input smoothK = 3;# title='Smooth', minval=1)

def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;


def fastMA = ExpAverage(source, fastLength);
def slowMA = ExpAverage(source, slowLength);
def macd = fastMA - slowMA;
def signal = Average(macd, signalLength);
def hist = macd - signal;

#//RSI Color
def rsivalue = rsi(Price = close,Length = 14);
def colorsi = rsivalue >= RSIstrength;

#//Plot RSI

plot rsiPlot = if colorsi then 0 else na;
rsiPlot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
rsiPlot.SetDefaultColor(Color.YELLOW);
#//Plot MACD

plot macdHist = hist;#, title='Histogram'
macdHist.SetLineWeight(4);
macdHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
macdHist.AssignValueColor(if hist >= 0 then if hist[1] < hist then Color.GREEN else Color.DARK_GREEN else
                                            if hist[1] < hist then Color.DARK_RED else Color.RED);

plot sigLine = signal;#, color=color.new(color.red, 0), linewidth=1)
plot macLine = macd;#, color=color.new(color.blue, 0), linewidth=1)
sigLine.SetDefaultColor(GetColor(8));
macLine.SetDefaultColor(GetColor(1));

#  'SLOW MACD SETTINGS:'
def fastMA1 = ExpAverage(source, fastLength1);
def slowMA1 = ExpAverage(source, slowLength1);
def macd1 = fastMA1 - slowMA1;
def signal1 = Average(macd1, signalLength1);

AddCloud(if macd1 >= signal1 then pos else na, neg, Color.BLUE);

def intersection1 = macd >= signal;
def intersection2 = macd1 >= signal1;

AddCloud(if !intersection1 and !intersection2 then pos else na, neg, Color.DARK_RED);
AddCloud(if intersection2 then pos else na, neg, Color.BLUE);
AddCloud(if intersection1 then pos else na, neg, Color.YELLOW);

# //Stochastic

def k = StochasticFull(KPeriod = periodK, DPeriod = periodD, slowing_period = smoothK).FullK;
def d = StochasticFull(KPeriod = periodK, DPeriod = periodD, slowing_period = smoothK).FullD;

def stobull = Crosses(k, d, CrossingDirection.ABOVE) and k <= 20;# ? #3179f5 : na
def stobear = Crosses(d, k, CrossingDirection.ABOVE) and k >= 80;# ? #ff3b7d : na

plot CrossUp = if stobull then 0 else na;#, color=stobull, style=plot.style_cross, linewidth=4)
plot CrossDn = if stobear then 0 else na;#, color=stobear, style=plot.style_cross, linewidth=4)
CrossUp.SetDefaultColor(Color.CYAN);
CrossDn.SetDefaultColor(Color.MAGENTA);
CrossUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
CrossDn.SetPaintingStrategy(PaintingStrategy.SQUARES);

#-- END of CODE
Appreciate if you can add Color Bar option, many thanks
 
Appreciate if you can add Color Bar option, many thanks
add this at the end of the code:

CSS:
input colorBars = yes;

def col = if !intersection1 and !intersection2 then -2 else
          if intersection2 then 1 else if intersection1 then -1 else 0;

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if col ==  1 then Color.CYAN else
                 if col == -1 then Color.YELLOW else
                 if col == -2 then Color.RED else Color.GRAY);
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
407 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