RSI and MACD CrossOver Signal Indicator

xxentre

Member
VIP
This is the first code I have tried to do in ThinkScript.
I am trying to create a Strategy that will perform the following label a Call order when the RSI Crosses above 30 and within 4 bars of the MACD Histogram crossing above 0. Then label a Sell_Call when the RSI Crosses above 70 or MACD Crossing below 0.

Also label a Put order when the RSI Crosses below 70 and within 4 bars of the MACD Histogram crossing below 0 . Then signal a Sell_Put when the RSI Crosses below 30 or MACD Crossing above 0.

Basically trying to combine the RSICrossover and the MACDHistogramCrossover so they cross within 0-4 Bars of each other and place a label on the chart for both Buy_Long and Close_Long, and Buy_Short and Close_Short. Normally the RSI crosses then the MACD follows for buy signals.

CODE:
#Strategy
#Alert a Call order when the RSI Crosses above 30 and within 4 bars of the MACDHistogram crosses above 0
# and Alert a Sell_Call when the RSI Crosses above 70 or MACD Crosses crosses below 0
#Alert a Put order when the RSI Crosses below 70 and within 4 bars of the MACDHistogram crosses below 0
# and Alert a Sell_Put when the RSI Crosses below 30 or MACD Crosses crosses above 0

#RSI Inputs
input rsiLength = 14;
#input crossingType = {default above, below};
#input threshold = 30;
input RSIAverageType = AverageType.WILDERS;
input RSIPrice = close;
input RSIOverBought = 70;
input RSIOverSold = 30;

#MACD Inputs
input MACDFastLength = 12;
input MACDSlowLength = 26;
input MACDLength = 9;
input MACDAverageType = AverageType.EXPONENTIAL;

def rsi = reference RSI(price = RSIPrice, length = rsiLength, averageType = RSIAverageType).rsi;
def macdcross = reference MACD(MACDFastLength, MACDSlowLength, MACDLength, MACDAverageType).Diff;

#Buy or Call
AddOrder(OrderType.BUY_AUTO, rsi crosses above RSIOverSold and macdcross crosses above 0, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Buy_Call");
AddOrder(OrderType.SELL_TO_CLOSE, rsi > RSIOverBought or macdcross crosses above 0, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Close_Call");

#Short or Put
AddOrder(OrderType.BUY_AUTO, rsi crosses below RSIOverBought and macdcross crosses below 0, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "Buy_Put");
AddOrder(OrderType.SELL_TO_CLOSE, rsi < RSIOverSold or macdcross crosses below 0, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Close_Put");

#Alerts
#Alert(OrderType.BUY_AUTO, " ", Alert.Bar, Sound.Chimes);
#Alert(OrderType.SELL_TO_CLOSE, " ", Alert.Bar, Sound.Bell);
#END
 
Last edited:
This is the first code I have tried to do in ThinkScript.
I am trying to create a Strategy that will perform the following label a Call order when the RSI Crosses above 30 and within 4 bars of the MACD Histogram crossing above 0. Then label a Sell_Call when the RSI Crosses above 70 or MACD Crossing below 0.

Also label a Put order when the RSI Crosses below 70 and within 4 bars of the MACD Histogram crossing below 0 . Then signal a Sell_Put when the RSI Crosses below 30 or MACD Crossing above 0.

Basically trying to combine the RSICrossover and the MACDHistogramCrossover so they cross within 0-4 Bars of each other and place a label on the chart for both Buy_Long and Close_Long, and Buy_Short and Close_Short. Normally the RSI crosses then the MACD follows for buy signals.

CODE:
#Strategy
#Alert a Call order when the RSI Crosses above 30 and within 4 bars of the MACDHistogram crosses above 0
# and Alert a Sell_Call when the RSI Crosses above 70 or MACD Crosses crosses below 0
#Alert a Put order when the RSI Crosses below 70 and within 4 bars of the MACDHistogram crosses below 0
# and Alert a Sell_Put when the RSI Crosses below 30 or MACD Crosses crosses above 0

#RSI Inputs
input rsiLength = 14;
#input crossingType = {default above, below};
#input threshold = 30;
input RSIAverageType = AverageType.WILDERS;
input RSIPrice = close;
input RSIOverBought = 70;
input RSIOverSold = 30;

#MACD Inputs
input MACDFastLength = 12;
input MACDSlowLength = 26;
input MACDLength = 9;
input MACDAverageType = AverageType.EXPONENTIAL;

def rsi = reference RSI(price = RSIPrice, length = rsiLength, averageType = RSIAverageType).rsi;
def macdcross = reference MACD(MACDFastLength, MACDSlowLength, MACDLength, MACDAverageType).Diff;

#Buy or Call
AddOrder(OrderType.BUY_AUTO, rsi crosses above RSIOverSold and macdcross crosses above 0, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Buy_Call");
AddOrder(OrderType.SELL_TO_CLOSE, rsi > RSIOverBought or macdcross crosses above 0, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Close_Call");

#Short or Put
AddOrder(OrderType.BUY_AUTO, rsi crosses below RSIOverBought and macdcross crosses below 0, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "Buy_Put");
AddOrder(OrderType.SELL_TO_CLOSE, rsi < RSIOverSold or macdcross crosses below 0, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Close_Put");

#Alerts
#Alert(OrderType.BUY_AUTO, " ", Alert.Bar, Sound.Chimes);
#Alert(OrderType.SELL_TO_CLOSE, " ", Alert.Bar, Sound.Bell);
#END
Do you have instructions on how to add this scanner for a watchlist?
 

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