Stoch, RSI, MACD bullish

rajaodu1

Member
VIP
HI Script Guru's,

Can you please help to create a script with the logic as follows. Add

(1) Slow stochastic (%K) with 14 and 3 parameter.
(2) RSI
(3) MACD (12,26,9)

If Slow stochastic is above 50% AND RSI is above 50% and MACD is above signal then candle color turns to GREEN
If slow stochastic is below 50% AND RSI is below 50% and MACD is below signal then candle color turns to RED
If all 3 conditions do not meet, then the candle color turns to Yellow.

Thanks in advance for your help
 
Solution
Ruby:
plot RSI = reference RSI().RSI;
RSI.Hide();
plot SlowK = reference StochasticFull(80,20,14,3,high,low,close,3,AverageType.SIMPLE).FullK;
SlowK.Hide();
plot MACD = reference MACD(12,26,9,AverageType.EXPONENTIAL).Value;
MACD.Hide();

AssignPriceColor(if SlowK > 50 && RSI > 50 && MACD > 0 then Color.Green else if SlowK< 50 && RSI < 50 && MACD < 0 then Color.Red else Color.Yellow);
YOSnRcG.jpeg
Ruby:
plot RSI = reference RSI().RSI;
RSI.Hide();
plot SlowK = reference StochasticFull(80,20,14,3,high,low,close,3,AverageType.SIMPLE).FullK;
SlowK.Hide();
plot MACD = reference MACD(12,26,9,AverageType.EXPONENTIAL).Value;
MACD.Hide();

AssignPriceColor(if SlowK > 50 && RSI > 50 && MACD > 0 then Color.Green else if SlowK< 50 && RSI < 50 && MACD < 0 then Color.Red else Color.Yellow);
YOSnRcG.jpeg
 
Last edited:
Solution
Give this a try.
Code:
# === Candle Color + Arrows for Stoch/RSI/MACD Alignment ===

# === INPUTS ===
input colorCandles = yes;
input rsiLength = 14;
input stochKLength = 14;
input stochDLength = 3;
input stochSlowing = 3;
input macdFastLength = 12;
input macdSlowLength = 26;
input macdSignalLength = 9;
input arrowOffsetATRmult = 1.0;
input atrLength = 14;

# === INDICATORS ===

# RSI
def rsi = RSI(rsiLength);

# MACD
def macdValue = MACD(macdFastLength, macdSlowLength, macdSignalLength).Value;
def macdSignal = MACD(macdFastLength, macdSlowLength, macdSignalLength).Avg;

# Slow Stochastic %K
def fullK = StochasticFull(stochKLength, stochDLength, stochSlowing).FullK;

# ATR for offsetting arrows
def atr = Average(TrueRange(high, close, low), atrLength);

# === CONDITIONS ===
def isBullish = fullK > 50 and rsi > 50 and macdValue > macdSignal;
def isBearish = fullK < 50 and rsi < 50 and macdValue < macdSignal;

# === CANDLE COLORING ===
AssignPriceColor(
if !colorCandles then Color.CURRENT
else if isBullish then Color.GREEN
else if isBearish then Color.RED
else Color.YELLOW
);

# === ARROWS ===

plot bullishArrow = if isBullish then low - atr * arrowOffsetATRmult else Double.NaN;
bullishArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
bullishArrow.SetDefaultColor(Color.GREEN);
bullishArrow.SetLineWeight(3);

plot bearishArrow = if isBearish then high + atr * arrowOffsetATRmult else Double.NaN;
bearishArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
bearishArrow.SetDefaultColor(Color.RED);
bearishArrow.SetLineWeight(3);


1750466257705.png
 
Last edited by a moderator:

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
351 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