RSI and MA with Trailing Stop Loss and Take Profit (by Coinrule)

Dec 22, 2022

Static chart image
Signals
Oscillators
Moving Averages
Trailing-Stop

The RSI and MA with Trailing Stop Loss and Take Profit tool automates trend-following entries by combining Relative Strength Index momentum with Moving Average crossovers and dynamic trailing exits.

Usage

The Usage section describes how the script can be used to identify trend momentum and manage trade exits. This strategy is designed for traders looking to capture medium-term bullish moves while protecting gains through a trailing mechanism.

Entry Logic

The strategy enters a long position when three specific conditions align:

  • RSI Threshold: The Relative Strength Index (RSI) must be above 50, indicating bullish momentum.
  • Moving Average Alignment: The 9-period Simple Moving Average (SMA 9) must be trading above the 50-period Simple Moving Average (SMA 50).
  • Momentum Spike: The RSI must increase by a user-defined value (defaulting to 5 points) compared to the previous bar, confirming a sudden surge in buying pressure.

Exit Management

The script utilizes a dynamic trailing stop-loss to manage risk:

  • Trailing Stop: As the price moves in favor of the trade, the stop-loss level automatically adjusts upward based on a percentage of the current price.
  • Capital Preservation: If the price retraces by the specified trailing percentage (default 2%), the trade is closed to lock in profits or minimize losses.

Details

The script integrates two primary technical indicators to filter market noise. The RSI measures the speed and magnitude of price changes to evaluate momentum, while the SMAs serve as trend filters to ensure trades are only taken in the direction of the prevailing trend.

The "RSI Increase" parameter is a unique filter used to detect acceleration in price movement. By requiring the RSI to jump by a specific margin, the script aims to avoid entering "flat" trends and instead targets high-velocity breakouts. The execution logic is optimized for backtesting with integrated commission settings and a date-range filter starting from 2022 to account for various market cycles.

Settings

Indicator Settings

  • RSI Length: Sets the number of periods used to calculate the Relative Strength Index.
  • RSI Increase: Determines the required point increase in RSI value over the previous bar to trigger an entry.
  • Show Date Range: Toggles the visibility of the backtesting period filter.

Risk Management Settings

  • Trail Long Loss (%): The percentage distance from the highest price reached while in a long position at which the trailing stop will be triggered.
  • Trail Short Loss (%): The percentage distance used for trailing exits in short scenarios (where applicable).

FAQ

How does the trailing stop work?

The trailing stop calculates a stop-loss price based on a percentage below the current price. If the price rises, the stop-loss follows it upward; however, the stop-loss never moves downward, ensuring gains are protected during a reversal.

What are the default Moving Averages used?

The script plots and utilizes the SMA 9, SMA 50, and SMA 100. The primary entry filter relies on the SMA 9 being above the SMA 50.

How can I access this tool?

You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free access on the following platforms
tradingviewSymbolTradingView
ninjatraderNinjaTrader
metatrader4MetaTrader 4/5
thinkorswimThinkorswim

Unlock Unlimited Access to the LuxAlgo Library

Upgrade your plan to get all indicators, strategies, charts, and full access to Quant, our AI agent.

Trading & investing are risky and many will lose money in connection with trading and investing activities. All content on this site is not intended to, and should not be, construed as financial advice. Decisions to buy, sell, hold or trade in securities, commodities and other investments involve risk and are best made based on the advice of qualified financial professionals. Past performance does not guarantee future results.

Hypothetical or Simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, including, but not limited to, lack of liquidity. Simulated trading programs in general are designed with the benefit of hindsight, and are based on historical information. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

Testimonials appearing on this website may not be representative of other clients or customers and is not a guarantee of future performance or success.

As a provider of technical analysis tools and strategies, we do not have access to the personal trading accounts or brokerage statements of our customers. As a result, we have no reason to believe our customers perform better or worse than traders as a whole based on any content, tool, or platform feature we provide.

Charts used on this site are by TradingView in which the majority of our technical indicators are built on. TradingView® is a registered trademark of TradingView, Inc. www.TradingView.com TradingView® has no affiliation with the owner, developer, or provider of the Services described herein.

Market data is provided by CBOE, CME Group, BarChart, Massive, CoinAPI. Select U.S. equities data is provided through Massive. CBOE BZX real-time U.S. equities data is licensed from CBOE and provided through BarChart. Real-time futures data is licensed from CME Group and provided through BarChart. Select cryptocurrency data, including major coins, is provided through CoinAPI. All data is provided “as is” and should be verified independently for trading purposes.

This does not represent our full Disclaimer. Please read our full disclaimer.

© 2026 LuxAlgo Global, LLC.