twobiscuitsngravy

Trading Range Finder

twobiscuitsngravy Cập nhật   
There are 5 horizontal lines printed by this indicator, and they extend from the last bar to a user-defined look-back period (the number of bars back from the last bar). The dark blue lines are the swing high and swing low within the look-back period. The magenta lines are the range high and range low used to define a trading range for the look-back period. The light blue line in the middle is the halfway point within the trading range, or the equilibrium.

The majority of the script logic focuses on the placement of the magenta lines (range high and range low). To do this, a histogram analysis is used. The price difference between the swing high and swing low is broken up into discrete bins which are monitored by an array. The high and low of each bar within the look-back period is used to populate the bins. There is also a toggle to use the midpoint of each bar to populate the bins as well. This means that for every bar two bins (three with the toggle) within the array will increase by a value of 1. The two bins with the highest count are used to print the magenta lines. Around each magenta line are two dotted lines and a shaded area to show the size of the bins used in the analysis.

Regarding bin size:
The bin size is a fraction of the asset price. If the price difference between the swing high and swing low is $1000, and the bin size is 1, then there are 1000 bins. I initially made the bin size a user input, but for a given look-back period the trading range would have wildly different range highs/lows when the bin size was incremented by small amounts. It was also difficult to manage a user input when the asset price is near, or less than 1. I then used a loop to optimize the bin size so it is no longer a user input. The optimization parameter is the maximization of the distance between the range high and range low. I capped the bin size within the script somewhat arbitrarily (but with a lot of testing) at ((swing high - swing low)/50) because sometimes very large bin sizes (one third or one quarter of the difference between swing high and swing low) would maximize the distance between the range high and range low, but with the line placed in the middle of the bin, its level wouldn't always make sense. Besides the maximum bin size, the only other hardcoded part of the script was to test 50 bin sizes, up to and including the maximum bin size. The loop finds the bin size that gives the largest separation between prices, and then uses that bin size to set the up the array with the bin counts.

Toggles for the plots are available to show how the range high, range low, and equilibrium move as new bars are added to the chart. The effects of these plots can most readily be seen in replay mode. There is also to a toggle to show the Fibonacci levels between the range high and range low. I made the midpoint a toggle because sometimes it is detrimental, meaning it contracts the trading range to the point of not being useful on a given chart. If there are periods of very low volatility and the bin size is large enough, the midpoint might end up in the same bin as the high or the low (or both!), and a single bar could unevenly weight a particular bin. The midpoint toggle, along with different lookback periods, will be needed to find a suitable trading range for a given chart.
Phát hành các Ghi chú:
There are 5 horizontal lines printed by this indicator, and they extend from the last bar to a user-defined look-back period (the number of bars back from the last bar). The dark blue lines are the swing high and swing low within the look-back period. The magenta lines are the range high and range low used to define a trading range for the look-back period. The light blue line in the middle is the halfway point within the trading range, or the equilibrium.

The majority of the script logic focuses on the placement of the magenta lines (range high and range low). To do this, a histogram analysis is used. The price difference between the swing high and swing low is broken up into discrete bins which are monitored by an array. The high and low of each bar within the look-back period is used to populate the bins. There are also toggles to use the midpoint, and the ¼ and ¾ points of each bar to populate the bins as well. This means that for every bar two bins (three to five with the toggles) within the array will increase by a value of 1. The two bins with the highest count are used to print the magenta lines. Around each magenta line are two dotted lines and a shaded area to show the size of the bins used in the analysis.

Regarding bin size:
The bin size is a fraction of the asset price. If the price difference between the swing high and swing low is $1000, and the bin size is 1, then there are 1000 bins. I initially made the bin size a user input, but for a given look-back period the trading range would have wildly different range highs/lows when the bin size was incremented by small amounts. It was also difficult to manage a user input when the asset price is near, or less than 1. I then used a loop to optimize the bin size so it is no longer a user input. The optimization parameter is the maximization of the distance between the range high and range low. I capped the bin size within the script somewhat arbitrarily (but with a lot of testing) at ((swing high - swing low)/50) because sometimes very large bin sizes (one third or one quarter of the difference between swing high and swing low) would maximize the distance between the range high and range low, but with the line placed in the middle of the bin, its level wouldn't always make sense. Besides the maximum bin size, the only other hardcoded part of the script was to test 50 bin sizes, up to and including the maximum bin size. The loop finds the bin size that gives the largest separation between prices, and then uses that bin size to set the up the array with the bin counts.

Toggles for the plots are available to show how the range high, range low, and equilibrium move as new bars are added to the chart. The effects of these plots can most readily be seen in replay mode. There is also to a toggle to show the Fibonacci levels between the range high and range low. I made toggles for use of the midpoint, ¼ point, and ¾ point of each bar in the analysis because sometimes they are detrimental, meaning they contract the trading range to the point of not being useful on a given chart. If there are periods of very low volatility and the bin size is large enough, the midpoint and quarter-points might end up in the same bin as the high or the low (or both!), and a single bar could unevenly weight a particular bin. The midpoint and quarter-point toggles, along with different lookback periods, will be needed to find a suitable trading range for a given chart.
Tập lệnh chỉ hiển thị cho người được mời

Quyền truy cập vào tập lệnh này bị hạn chế đối với người dùng được tác giả ủy quyền và thường yêu cầu thanh toán. Bạn có thể thêm nó vào mục yêu thích của mình, nhưng bạn sẽ chỉ có thể sử dụng nó sau khi yêu cầu sự cho phép từ tác giả. Liên hệ twobiscuitsngravy để thêm thông tin, hoặc làm theo hướng dẫn của tác giả bên dưới.

TradingView không đề xuất trả tiền cho một tập lệnh và sử dụng cho đến khi bạn hoàn toàn tin tưởng tác giả và hiểu cách thức hoạt động của tập lệnh. Trong nhiều trường hợp, bạn có thể tìm thấy một giải pháp thay thế nguồn mở miễn phí trong Thư viện Công cộng của chúng tôi.

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.

Hướng dẫn của tác giả

I've done a lot of testing but it's still a work in progress. I'm publishing it mainly to share with friends, but if you're interested in using it, let me know.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?

Cảnh báo: vui lòng đọc trước khi yêu cầu quyền truy cập.