Signals based on RSI, BB, and Moving Average

Babisco

New member
Greeting to everyone is my please to joined this amazing community I'm very grateful
please I needed your help I have been working on this script but note able to make it work on ThinkOrSwim
Ruby:
# Trend Following with Mean Reversion Strategy
# Inputs
input lengthMA = 50;
input lengthBB = 20;
input lengthRSI = 14;
input overbought = 70;
input oversold = 30;
# Define indicators
def MA = Average(close, lengthMA);
def UpperBB = BollingerBandTop(close, lengthBB);
def LowerBB = BollingerBandBottom(close, lengthBB);
def RSI = RSI(close, lengthRSI);
# Entry rules
def longCondition = close > MA and RSI < oversold and close crosses above LowerBB;
def shortCondition = close < MA and RSI > overbought and close crosses below UpperBB;
# Exit rules
def longExit = close crosses below UpperBB or RSI > overbought;
def shortExit = close crosses above LowerBB or RSI < oversold;
# Plot signals
plot longEntry = if longCondition then Low else Double.NaN;
plot shortEntry = if shortCondition then High else Double.NaN;
plot longExitSignal = if longExit then Low else Double.NaN;
plot shortExitSignal = if shortExit then High else Double.NaN;
longEntry.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longEntry.SetDefaultColor(Color.GREEN);
shortEntry.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortEntry.SetDefaultColor(Color.RED);
longExitSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longExitSignal.SetDefaultColor(Color.GREEN);
shortExitSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortExitSignal.SetDefaultColor(Color.RED);
# Alerts
Alert(longCondition, "Long Entry", "Long Entry Signal", Alert.BAR, Sound.RING);
2
Alert(shortCondition, "Short Entry", "Short Entry Signal", Alert.BAR, Sound.RING);
Alert(longExit, "Long Exit", "Long Exit Signal", Alert.BAR, Sound.RING);
Alert(shortExit, "Short Exit", "Short Exit Signal", Alert.BAR, Sound.RING);
 
Last edited by a moderator:
Solution
Greeting to everyone is my please to joined this amazing community I'm very grateful
please I needed your help I have been working on this script but note able to make it work on ThinkOrSwim
Ruby:
# Trend Following with Mean Reversion Strategy
# Inputs
input lengthMA = 50;
input lengthBB = 20;
input lengthRSI = 14;
input overbought = 70;
input oversold = 30;
# Define indicators
def MA = Average(close, lengthMA);
def UpperBB = BollingerBandTop(close, lengthBB);
def LowerBB = BollingerBandBottom(close, lengthBB);
def RSI = RSI(close, lengthRSI);
# Entry rules
def longCondition = close > MA and RSI < oversold and close crosses above LowerBB;
def shortCondition = close < MA and RSI > overbought and close crosses below UpperBB;
# Exit...
Greeting to everyone is my please to joined this amazing community I'm very grateful
please I needed your help I have been working on this script but note able to make it work on ThinkOrSwim
Ruby:
# Trend Following with Mean Reversion Strategy
# Inputs
input lengthMA = 50;
input lengthBB = 20;
input lengthRSI = 14;
input overbought = 70;
input oversold = 30;
# Define indicators
def MA = Average(close, lengthMA);
def UpperBB = BollingerBandTop(close, lengthBB);
def LowerBB = BollingerBandBottom(close, lengthBB);
def RSI = RSI(close, lengthRSI);
# Entry rules
def longCondition = close > MA and RSI < oversold and close crosses above LowerBB;
def shortCondition = close < MA and RSI > overbought and close crosses below UpperBB;
# Exit rules
def longExit = close crosses below UpperBB or RSI > overbought;
def shortExit = close crosses above LowerBB or RSI < oversold;
# Plot signals
plot longEntry = if longCondition then Low else Double.NaN;
plot shortEntry = if shortCondition then High else Double.NaN;
plot longExitSignal = if longExit then Low else Double.NaN;
plot shortExitSignal = if shortExit then High else Double.NaN;
longEntry.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longEntry.SetDefaultColor(Color.GREEN);
shortEntry.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortEntry.SetDefaultColor(Color.RED);
longExitSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longExitSignal.SetDefaultColor(Color.GREEN);
shortExitSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortExitSignal.SetDefaultColor(Color.RED);
# Alerts
Alert(longCondition, "Long Entry", "Long Entry Signal", Alert.BAR, Sound.RING);
2
Alert(shortCondition, "Short Entry", "Short Entry Signal", Alert.BAR, Sound.RING);
Alert(longExit, "Long Exit", "Long Exit Signal", Alert.BAR, Sound.RING);
Alert(shortExit, "Short Exit", "Short Exit Signal", Alert.BAR, Sound.RING);

if you look up the functions, you would realize the spelling errors and wrong input parameters
https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/A-B/BollingerBands
notes in comments

Code:
#signals_rsi_bb_ma

#https://usethinkscript.com/threads/signals-based-on-rsi-bb-and-moving-average.19517/
#Signals based on RSI, BB, and Moving Average
#Babisco  9/9

#1
#Greeting to everyone is my please to joined this amazing community I'm very grateful
#please I needed your help I have been working on this script but note able to make it work on ThinkOrSwim

# Trend Following with Mean Reversion Strategy
# Inputs
input lengthMA = 50;
input lengthBB = 20;
input lengthRSI = 14;
input overbought = 70;
input oversold = 30;

# Define indicators
def MA = Average(close, lengthMA);

#  wrong study name. didn't use correct plot name
def UpperBB = BollingerBands(close, lengthBB).upperband;
def LowerBB = BollingerBands(close, lengthBB).LowerBand;

# BollingerBands
#plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
#plot LowerBand = MidLine + num_Dev_Dn * sDev;
#plot UpperBand = MidLine + num_Dev_Up * sDev;



# inputs in wrong order
def RSI = RSI(length = lengthRSI, price = close);

# rsi inputs
#input length = 14;
#input over_Bought = 70;
#input over_Sold = 30;
#input price = close;
#input averageType = AverageType.WILDERS;
#input showBreakoutSignals = no;





# Entry rules
def longCondition = close > MA and RSI < oversold and close crosses above LowerBB;
def shortCondition = close < MA and RSI > overbought and close crosses below UpperBB;
# Exit rules
def longExit = close crosses below UpperBB or RSI > overbought;
def shortExit = close crosses above LowerBB or RSI < oversold;
# Plot signals
plot longEntry = if longCondition then low else Double.NaN;
plot shortEntry = if shortCondition then high else Double.NaN;
plot longExitSignal = if longExit then low else Double.NaN;
plot shortExitSignal = if shortExit then high else Double.NaN;
longEntry.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longEntry.SetDefaultColor(Color.GREEN);
shortEntry.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortEntry.SetDefaultColor(Color.RED);
longExitSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
longExitSignal.SetDefaultColor(Color.GREEN);
shortExitSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortExitSignal.SetDefaultColor(Color.RED);


# had extra text value
# Alerts
Alert(longCondition, "Long Entry Signal", Alert.BAR, Sound.Ring);
Alert(shortCondition, "Short Entry Signal", Alert.BAR, Sound.Ring);
Alert(longExit,  "Long Exit Signal", Alert.BAR, Sound.Ring);
Alert(shortExit,  "Short Exit Signal", Alert.BAR, Sound.Ring);
 
Solution

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