OPEN-SOURCE SCRIPT

Swing Counter [theEccentricTrader]

تم تحديثه
█  OVERVIEW


This indicator counts the number of confirmed swing high and swing low scenarios on any given candlestick chart and displays the statistics in a table, which can be repositioned and resized at the user's discretion.


█  CONCEPTS


Green and Red Candles

• A green candle is one that closes with a high price equal to or above the price it opened.
• A red candle is one that closes with a low price that is lower than the price it opened.

Swing Highs and Swing Lows

• A swing high is a green candle or series of consecutive green candles followed by a single red candle to complete the swing and form the peak.
• A swing low is a red candle or series of consecutive red candles followed by a single green candle to complete the swing and form the trough.

Peak and Trough Prices (Basic)

• The peak price of a complete swing high is the high price of either the red candle that completes the swing high or the high price of the preceding green candle, depending on which is higher.
• The trough price of a complete swing low is the low price of either the green candle that completes the swing low or the low price of the preceding red candle, depending on which is lower.

Peak and Trough Prices (Advanced)

• The advanced peak price of a complete swing high is the high price of either the red candle that completes the swing high or the high price of the highest preceding green candle high price, depending on which is higher.
• The advanced trough price of a complete swing low is the low price of either the green candle that completes the swing low or the low price of the lowest preceding red candle low price, depending on which is lower.

Green and Red Peaks and Troughs

• A green peak is one that derives its price from the green candle/s that constitute the swing high.
• A red peak is one that derives its price from the red candle that completes the swing high.
• A green trough is one that derives its price from the green candle that completes the swing low.
• A red trough is one that derives its price from the red candle/s that constitute the swing low.

Historic Peaks and Troughs

The current, or most recent, peak and trough occurrences are referred to as occurrence zero. Previous peak and trough occurrences are referred to as historic and ordered numerically from right to left, with the most recent historic peak and trough occurrences being occurrence one.

Upper Trends

• A return line uptrend is formed when the current peak price is higher than the preceding peak price.
• A downtrend is formed when the current peak price is lower than the preceding peak price.
• A double-top is formed when the current peak price is equal to the preceding peak price.

Lower Trends

• An uptrend is formed when the current trough price is higher than the preceding trough price.
• A return line downtrend is formed when the current trough price is lower than the preceding trough price.
• A double-bottom is formed when the current trough price is equal to the preceding trough price.


█  FEATURES


Inputs

• Start Date
• End Date
• Position
• Text Size
• Show Sample Period
• Show Plots
• Show Lines

Table

The table is colour coded, consists of three columns and nine rows. Blue cells denote neutral scenarios, green cells denote return line uptrend and uptrend scenarios, and red cells denote downtrend and return line downtrend scenarios.

The swing scenarios are listed in the first column with their corresponding total counts to the right, in the second column. The last row in column one, row nine, displays the sample period which can be adjusted or hidden via indicator settings.

Rows three and four in the third column of the table display the total higher peaks and higher troughs as percentages of total peaks and troughs, respectively. Rows five and six in the third column display the total lower peaks and lower troughs as percentages of total peaks and troughs, respectively. And rows seven and eight display the total double-top peaks and double-bottom troughs as percentages of total peaks and troughs, respectively.

Plots

I have added plots as a visual aid to the swing scenarios listed in the table. Green up-arrows with ‘HP’ denote higher peaks, while green up-arrows with ‘HT’ denote higher troughs. Red down-arrows with ‘LP’ denote higher peaks, while red down-arrows with ‘LT’ denote lower troughs. Similarly, blue diamonds with ‘DT’ denote double-top peaks and blue diamonds with ‘DB’ denote double-bottom troughs. These plots can be hidden via indicator settings.

Lines

I have also added green and red trendlines as a further visual aid to the swing scenarios listed in the table. Green lines denote return line uptrends (higher peaks) and uptrends (higher troughs), while red lines denote downtrends (lower peaks) and return line downtrends (lower troughs). These lines can be hidden via indicator settings.


█  HOW TO USE


This indicator is intended for research purposes and strategy development. I hope it will be useful in helping to gain a better understanding of the underlying dynamics at play on any given market and timeframe. It can, for example, give you an idea of any inherent biases such as a greater proportion of higher peaks to lower peaks. Or a greater proportion of higher troughs to lower troughs. Such information can be very useful when conducting top down analysis across multiple timeframes, or considering entry and exit methods.

What I find most fascinating about this logic, is that the number of swing highs and swing lows will always find equilibrium on each new complete wave cycle. If for example the chart begins with a swing high and ends with a swing low there will be an equal number of swing highs to swing lows. If the chart starts with a swing high and ends with a swing high there will be a difference of one between the two total values until another swing low is formed to complete the wave cycle sequence that began at start of the chart. Almost as if it was a fundamental truth of price action, although quite common sensical in many respects. As they say, what goes up must come down.

The objective logic for swing highs and swing lows I hope will form somewhat of a foundational building block for traders, researchers and developers alike. Not only does it facilitate the objective study of swing highs and swing lows it also facilitates that of ranges, trends, double trends, multi-part trends and patterns. The logic can also be used for objective anchor points. Concepts I will introduce and develop further in future publications.


█  LIMITATIONS


Some higher timeframe candles on tickers with larger lookbacks such as the DXY , do not actually contain all the open, high, low and close (OHLC) data at the beginning of the chart. Instead, they use the close price for open, high and low prices. So, while we can determine whether the close price is higher or lower than the preceding close price, there is no way of knowing what actually happened intra-bar for these candles. And by default candles that close at the same price as the open price, will be counted as green. You can avoid this problem by utilising the sample period filter.

The green and red candle calculations are based solely on differences between open and close prices, as such I have made no attempt to account for green candles that gap lower and close below the close price of the preceding candle, or red candles that gap higher and close above the close price of the preceding candle. I can only recommend using 24-hour markets, if and where possible, as there are far fewer gaps and, generally, more data to work with. Alternatively, you can replace the scenarios with your own logic to account for the gap anomalies, if you are feeling up to the challenge.

The sample size will be limited to your Trading View subscription plan. Premium users get 20,000 candles worth of data, pro+ and pro users get 10,000, and basic users get 5,000. If upgrading is currently not an option, you can always keep a rolling tally of the statistics in an excel spreadsheet or something of the like.


█  NOTES


I feel it important to address the mention of advanced peak and trough price logic. While I have introduced the concept, I have not included the logic in my script for a number of reasons. The most pertinent of which being the amount of extra work I would have to do to include it in a public release versus the actual difference it would make to the statistics. Based on my experience, there are actually only a small number of cases where the advanced peak and trough prices are different from the basic peak and trough prices. And with adequate multi-timeframe analysis any high or low prices that are not captured using basic peak and trough price logic on any given time frame, will no doubt be captured on a higher timeframe. See the example below on the 1H FOREXCOM:USDJPY chart (Figure 1), where the basic peak price logic denoted by the indicator plot does not capture what would be the advanced peak price, but on the 2H FOREXCOM:USDJPY chart (Figure 2), the basic peak logic does capture the advanced peak price from the 1H timeframe.


لقطة
Figure 1.

لقطة
Figure 2.


█  RAMBLINGS


“Never was there an age that placed economic interests higher than does our own. Never was the need of a scientific foundation for economic affairs felt more generally or more acutely. And never was the ability of practical men to utilize the achievements of science, in all fields of human activity, greater than in our day. If practical men, therefore, rely wholly on their own experience, and disregard our science in its present state of development, it cannot be due to a lack of serious interest or ability on their part. Nor can their disregard be the result of a haughty rejection of the deeper insight a true science would give into the circumstances and relationships determining the outcome of their activity. The cause of such remarkable indifference must not be sought elsewhere than in the present state of our science itself, in the sterility of all past endeavours to find its empirical foundations.” (Menger, 1871, p.45).


█  BIBLIOGRAPHY


Menger, C. (1871) Principles of Economics. Reprint, Auburn, Alabama: Ludwig Von Mises Institute: 2007.
ملاحظات الأخبار
Added group titles to inputs.
ملاحظات الأخبار
Incorporated library functions and general TLC.
ملاحظات الأخبار
Corrected an inconsistency in the line plots I noticed after TLC update.
educationalstatisticsTrend Analysis

نص برمجي مفتوح المصدر

قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الرمز في المنشور يخضع لقواعد‎‎قوانين الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟

إخلاء المسؤولية