blackcat1402

How to use pandas_ta library to build R-Breaker indicator

SZSE:000597   NORTHEAST PHARMACE
Today is the first day of 2022. I hereby wish all my friends a smooth transaction in the new year, and your account will be N times profitable.

The reason why I write this article is not to simply introduce the R-Breaker strategy itself. I think many of my friends may have used this strategy for intraday short-term trading operations. And I hope to use this case to introduce how to use the pandas_ta library I just released for indicator and strategy design.
Many friends who are familiar with Python may find: Is the pandas_ta library not an open source library for Python? How can it be directly used in Tradingview? In fact, I spent some time and energy to convert the Python version of the pandas_ta library file into Tradingview's Pine v5 script, and used the latest library functions released in v5 to encapsulate most of the functions.

The pandas_ta library is a public library file containing functions that can be reused in Pine indicators, strategies or other libraries. They are useful for defining commonly used functions, so their source code does not have to be included in every script that requires them. The pandas_ta library is a public and open source Pine script library, so it is referenced in another script. In fact, according to Tradingview's release policy, all libraries must be released as open source before they can be publicly cited. In other words, public scripts can only use public libraries, and they must be open source. Private or personal scripts saved in the Pine editor can use public or private libraries. A library can use other libraries, or even its own previous version (Tradingview requires that the version number of the library must be noted when importing).

If you want to use the pandas_ta library, it is done through the import statement in the following format:

import <username>/<libraryName>/<libraryVersion>

Among them, the path <username>/<libraryName>/<libraryVersion> will uniquely identify the library. <libraryVersion> must be specified explicitly. In order to ensure the reliability of scripts that use the library, there is no way to automatically use the latest version of the library. Each time the author of the library updates, its version number will increase. If you plan to use the latest version of the library, you need to update the <libraryVersion> value in the import statement. The as <alias> part is optional. When used, it defines the namespace that will reference library functions. For example, if you import a library using the allTime alias as we did in the example below, you would call the library's function allTime.<function_mame>(). When no alias is defined, the name of the library becomes its namespace. To use the panadas_ta library, our script will need an import statement:

import blackcat1402/pandas_ta/2 as pta


The above is an introduction to the usage of the Tradingview library. Next, let me talk about the realization of the intraday short-term strategy R-Breaker.

The R-Breaker strategy is a short-term intraday trading strategy that combines trend and reversal trading methods. High, Close and Low PreClose are respectively the highest price of the current K-line, the closing price of the current K-line, the lowest price of the current K-line and the closing price of yesterday. Through these prices, a pivot point ( Pivot Point ) can be set, and many people in China also refer to it as the "pocket pivot ." With the "pocket pivot", we can calculate the support and resistance levels for buying and selling. They are:
-Breakthrough buying price = Observing selling price + 0.25 * (Observing selling price-Observing buying price)
-Observe the selling price = High + 0.35 * (Close – Low)
-Reversal selling price = 1.07 / 2 * (High + Low) – 0.07 * Low
-Reversal buying price = 1.07 / 2 * (High + Low) – 0.07 * High
-Observe the buying price = Low – 0.35 * (High – Close)
-Breakthrough selling price = Observing the buying price-0.25 * (Observing the selling price-Observing the buying price)

R-Breaker trading strategy details:
-1) When the intraday highest price exceeds the observed selling price, and the intraday price falls back and further breaks below the support line constituted by the reversal selling price, a reversal strategy is adopted, that is, at this point (backhand, open position) ) Short;
-2) When the intraday lowest price is lower than the observed purchase price, and the intraday price rebounds and further exceeds the resistance line constituted by the reverse purchase price, a reversal strategy is adopted, that is, at this point (backhand, open position) ) Long;
-3) In the case of a short position, if the intraday price exceeds the breakthrough buying price, a trend strategy is adopted, that is, open a long position at that point;
-4) In the case of a short position, if the intraday price breaks below the selling price, a trend strategy is adopted, that is, open a short position at that point.

R-Breaker indicator usage

-Generally used in short periods such as minute periods (I generally use 30 minutes and 1 hour periods, taking into account the response speed and stability), or the T+0 varieties with strong shares.
-It is best to perform double verification based on other indicators such as volume , price, market, and sector.
-The green label B is for early warning and buying.
-The red S label is short warning and sell.


Use pandas_ta library file to build R-Breaker

At the beginning of script writing, you need to use import to import the pandas_ta library, as follows:
//@version=5
indicator(" L2 Intraday R-Breaker Indicator", overlay = true)
import blackcat1402/pandas_ta/2 as pta

After naming the pandas_ta library as pta, you need to use "pta." as the prefix when referencing functions in it, for example:
preclose = callsec(syminfo.tickerid, "D", close, false)
nn = ta.barssince(dayofmonth!=pta. xrf (dayofmonth,1))+1
hh = pta. xrf (pta.xhh(high,nn),nn)
ll = pta. xrf (pta.xll(low,nn),nn)

Do not use pta. xrf , pta.xll, pta.xhh to reference the functions in the pandas_ta library.

In summary, this is the whole content of the tutorial. The tradingview library is very convenient to use, which can greatly improve coding efficiency and focus on the development of core strategies.




Donate TRC20 USDT to below address, 5USDT per monthly sub, 50USDT per yearly sub: TNz84MjJTWUUUyQFpPNjaAU7J2SwhJJ7j9
Note: USDT_TRC20 deposits sent from decentralized exchanges are not yet supported.
免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。