RSI-2 Stock Trading Strategy: Pinescript Version


[ Home ] [ Strategy Overview ] [ Technical Breakdown ] [ How to Use (and the code) ] [ Examples ]

Strategy Overview

This project contains a simple, yet robust, Pine Script trading strategy designed for use on TradingView. The strategy combines two popular technical indicators—a long-term Exponential Moving Average (EMA) for trend identification and a short-term Relative Strength Index (RSI) for entry signals and to manage buy and sell positions.

This strategy is built on a core idea: trade the trend while exploiting short-term oversold conditions. It uses the following logic:

Technical Breakdown

The code is well-structured and uses several key Pine Script features to manage its state and logic effectively.

1. State Management with var

The most critical technical element is the use of var int positionState = 0. Unlike a regular variable, a var variable retains its value from one bar (or candle) to the next. This is essential for the strategy's logic, as it allows the code to remember whether a position is currently open (positionState = 1) or closed (positionState = 0). This prevents the strategy from continuously buying on every bar that meets the entry conditions.

2. Customizable Inputs

The strategy is highly customizable via the input.int() function:

3. Logical Conditions

The entry and exit logic are broken down into clear, readable Boolean variables:

4. Strategy Commands

The core trading actions are performed using built-in Pine Script strategy functions:

5. Visual Plotting

The script also plots the 200-period EMA directly on the chart using the plot() function, allowing for visual confirmation of the trend filter.

How to Use (and the code)

  1. Copy the entire Pine Script code block from the file attached below.
  2. Open TradingView and navigate to the Pine Editor.
  3. Paste the code into the editor.
  4. Click "Save" and then "Add to Chart" to apply the strategy to your preferred ticker.

View the Pine Script Code Here


Disclaimer: This is a trading strategy for educational and illustrative purposes only. Trading involves risk, and past performance is not indicative of future results. Always backtest and paper trade any strategy before using it with real capital.

Examples


73 de YB1SDL

This page was handcrafted in plain HTML. No Java, No Flash.

Last Updated: February 17, 2026