A trading system based on the RSI indicator
Last updated
Last updated
The relative strength index (RSI) — is a technical indicator used in the analysis of financial markets. It is intended to chart the current and historical strength or weakness of a stock or market based on the closing prices of a recent trading period. The indicator should not be confused with relative strength.
How exactly is RSI calculated in the program? It is easy to make sure that it is calculated exactly as described in wiki.
Finding positive (U) and negative (D) price changes.
Calculating the relative strength RS.
Based on the RS, the Relative Strength Index RSI is calculated.
The market is changing very quickly now. When the Author created the indicator, the market changes were slower and the author of the indicator used a two-week period.
To be closer to the author's calculations, it is enough to simply set a longer period on a one-minute chart, but, for the convenience of the calculation, you can use ready-made daily candles in the program by using the Compress block.
For a more detailed study of the RSI indicator calculation, you can download the demo algorithm RSIcalc.tscript
Download the file. In the program, open Lab | Scripts. Click the Load from file button.
Open the script for editing.
Thus, you can create algorithms for calculating indicators in the program.
The attached algorithm presents the calculation of the indicator and for comparison, the calculation of the indicator built into the program (RSIintegrated Block) is displayed on the chart. You can save your own calculation into a Self-made script.
To do this, click on the New indicator button in the Scripts window.
As an example, ready-made blocks from the RSIcalc.tscript script were copied to the created indicator.
The ready-made indicator can be downloaded from the link: RSI_calc_1.tscript
Please note!
The value of the created indicator is always output through the Return value block.
You can output only one value from one indicator.
There can be as many inputs as you want. They are performed using the Source Blocks.
The input to the indicator can be a number, like mine, and the indicator in the script can be used for any number.
You can also use a data source as an input. In this case, a specific bar value must be used in the indicator.
After closing the window with the indicator, the program will automatically create a self-made indicator.
The Custom folder will appear in the Script Editor Toolbar, and if there are no errors in the indicator, it will be available in this folder.
The Custom indicator can be used in any scripts you create.
In previous articles, examples were given of how you can switch from one calculation to another using an ordinary constant.
In this example, you can apply the same method. You can calculate several different averages for the indicator.
In some scripts it is necessary to use one calculation, for example EMA, and in some another. In the formula, a small number will eliminate division by 0. ind_RSI_calc.tscript
The wiki describes several signals for the indicator. Be sure to check them out if you are not already familiar with them.
For all signals, the following is true: if the indicator is high, then you should not buy, if the indicator is low, then you should not sell.
In the RSI_.tscript example, the following strategy is implemented: if the indicator is high, then we sell, if the indicator is low, we buy.
With short profit and stop loss, the price of which is calculated by trail stop in relative values.
Perhaps the momentum indicator should be added to the strategy, for entry points signals.
The second strategy RSI_trend.tscript: sell and close long if the indicator is high, and buy and close short if the indicator is low.
Parameter optimization was not carried out.
Please note! Demo materials and example scripts are intended only for learning TSLab.
Demonstration algorithm for calculating RSI
Self-made RSI indicator
Indicator with a built-in switching of averaging EMA, SMA or AMA
Strategy example
Strategy example
(Download the file. In the TSLab program, open "Lab" -> "Script Manager" → Click the "Load from file" button).