ZLu

[ZL] ADX+RSI (Long Entries and Exits only)

ZLu Cập nhật   
A popular strategy which combines Average Directional Index and RSI. In this version, we coded for only LONG entries and exits.
Created by Shanghai Reed Asset Management Co., Ltd.
Bình luận:
This strategy is recommended to be used on stocks with daily charts.

Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?
//Copyright by Reed Asset Management registered in Shanghai, China
//该策略为上海蘆田资产管理有限公司制
//@version=2
strategy("[蘆田策略]ADX+RSI", overlay=true)

//ADX
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
	up = change(high)
	down = -change(low)
	truerange = rma(tr, len)
	plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
	minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)
	[plus, minus]

adx(dilen, adxlen) => 
	[plus, minus] = dirmov(dilen)
	sum = plus + minus
	adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)

sig = adx(dilen, adxlen)

plot(sig, color=red, title="ADX")

//ADX+RSI Strategy Long Entry
longEntry1 = sma(close, 20) > sma(close, 20)[1] //check if the ADX is rising
longEntry2 = (adx(14, 14) - adx(14, 14)[1]) > 0.2
longEntry3 = rsi(close, 14) < 85
longEntry4 = (adx(14, 14) - adx(14, 14)[1]) > 0
longEntry5 = (adx(14, 14) - adx(14, 14)[1] ) < 0.2
longEntry6 = rsi(close, 14) < 50

longCondition1 = longEntry1 and longEntry2 and longEntry3
longCondition2 = longEntry1 and longEntry4 and longEntry5 and longEntry6
if(longCondition1 or longCondition2)
    strategy.entry("long", strategy.long)

//ADX+RSI Strategy Long Exit
longExit1 = rsi(close, 9) > 75
longExit2 = (adx(14, 14) - adx(14, 14)[1]) > 0
longExit3 = (adx(14, 14) - adx(14, 14)[1] ) < 0.2
longExit4 = (adx(14, 14) - adx(14, 14)[1]) > 0.2
longExit5 = sma(close, 20) < sma(close,20)[1]

longExitCondition1 = longExit1 and longExit2 and longExit3
longExitCondition2 = longExit1 and longExit4
longStop1 = strategy.position_avg_price + 4 * tr
longExitCondition3 = longExit5
longStop2 = sma(close, 20)

strategy.close_all(when = longExitCondition1)
if (longExitCondition2)
    strategy.exit("exit", "long", stop = longStop1)
if (longExitCondition3)
    strategy.exit("exit", "long", stop = longStop2)
    

//Strategy