peterb1234

Williams %R Cross Strategy with 200 MA Filter


1. The script is a trading strategy based on the Williams %R indicator and a 200-period moving average (MA) filter.

2. The user can input the length of the Williams %R indicator (`wrLength`), the threshold for %R crossing (`crossPips`), the take profit level in pips (`takeProfitPips`), and the stop loss level in pips (`stopLossPips`).

3. The script calculates the Williams %R using the `ta.highest` and `ta.lowest` functions to find the highest high and lowest low over the specified length (`wrLength`).

4. It also calculates a 200-period simple moving average (`ma200`) using the `ta.sma` function.

5. The entry conditions are defined as follows:
- For a long entry, it checks if the Williams %R crosses above the -50 line by a threshold of `crossPips` and if the close price is above the 200-period MA.
- For a short entry, it checks if the Williams %R crosses below the -50 line by a threshold of `crossPips` and if the close price is below the 200-period MA.

6. The exit conditions are defined as follows:
- For a long position, it checks if the close price reaches the take profit level (defined as the average entry price plus `takeProfitPips` in pips) or the stop loss level (defined as the average entry price minus `stopLossPips` in pips).
- For a short position, it checks if the close price reaches the take profit level (defined as the average entry price minus `takeProfitPips` in pips) or the stop loss level (defined as the average entry price plus `stopLossPips` in pips).

7. The script uses the `strategy.entry` function to place long and short orders when the respective entry conditions are met.

8. It uses the `strategy.close` function to close the long and short positions when the respective exit conditions are met.

The script allows you to customize the parameters such as the length of Williams %R, the crossing threshold, take profit and stop loss levels, and the moving average period to suit your trading preferences.
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 đồ?