RSI-2-Stock-Trading-Strategy-Pinescript

RSI-2 Stock Trading Strategy Pinescript Version

This is a PineScript version of the previously uploaded strategy on Python here


This repository 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—to manage buy and sell positions.

Strategy Overview

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

  1. Copy the entire Pine Script code block from this file.
  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.

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

Meta Platforms (Facebook)

Bank BCA



Back to Index