twobiscuitsngravy

Trading Range Finder

twobiscuitsngravy 업데이트됨   
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.
릴리즈 노트:
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.
초대 전용 스크립트

이 스크립트에 대한 접근은 작성자가 승인한 사용자로 제한되며, 일반적으로 지불이 필요합니다. 즐겨찾기에 추가할 수 있지만 권한을 요청하고 작성자에게 권한을 받은 후에만 사용할 수 있습니다. 자세한 내용은 twobiscuitsngravy에게 문의하거나 아래의 작성자의 지시사항을 따르십시오.

트레이딩뷰는 당신이 스크립트 작성자를 100% 신뢰하고 스크립트의 작동 방식을 이해할 때까지 스크립트 비용을 지불하고 사용할 것을 권장하지 않습니다. 대부분의 경우 트레이딩뷰의 커뮤니티 스크립트 에서 무료로 좋은 오픈 소스 대안을 찾을 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

작성자 지시 사항

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.

차트에 이 스크립트를 사용하시겠습니까?

경고: 액세스를 요청하기 전에 읽으십시오 .