TradingView
alexgrover
29 мая 2020 г., 18:27

Time Range Statistics 

Advanced Micro Devices, Inc.NASDAQ

Описание

A good amount of users requested a text box showing various price statistics, the following script returns various of these stats in a user-selected range, and include classical ones such as a central tendency measurement (mean), dispersion (normalized range) and percent change, but also include less common statistics such as average traded volume and number of gaps. The script also calculates the correlation between the closing price and another user-selected instrument.

The script is currently the longest one I ever made and took some efforts, as I wasn't satisfied with the statistics to be originally included. Big thx to Gael for the enormous feedback and the idea of the normalized range, to user @cookiecrush for the feedback (without ya I would have posted something bad you know umu ?), and Lulidolce for the support, friendship is magic!

Selected Range

The setting Start determine the bar at which the range starts, while End determine at which bar the range end. To help you select these values, the current bar number (bar index) is displayed at the right of the indicator title in blue.

The setting evaluate to last bar will use a range starting at Start and ending at the last bar, as such you can use a full range by using Start = 0 and select evaluate to last bar



The range is highlighted by an area on the chart. By default Start = 9000 and End = 10000, you might not have this amount of data in your chart, as such use the displayed bar index to select Start and End, then set the settings as default.

Displayed Statistics

The statistics panel is displayed on the right side of the last bar, the panel has 3 sections, a title section who shows the symbol ticker, timeframe, and overall trends represented by a chart emoji, the overall trends are determined by comparing the number of higher highs with the number of lower low.

Below are displayed the date ranges with time format: year/month/day/hour:minute.

The second section shows the general statistics. The first one is the mean, also represented by the orange line in the chart, the blue line displayed represent the highest price value in the range, while the red one represents the lowest price value.

The second stat is the normalized range, and determine how spread is the price in the user-selected range, why not the standard deviation? Because the standard deviation might return results varying widely depending on the scale of the closing price, you could get measures such as 0.0156 or 16 or even 56 depending on the instrument, as such using a normalized range can be more appropriate as it lays in a range of (0,1). Lower values indicate a low degree of price variation. Note that I still want to find another measure in the future.

The percentage change (or relative change) indicates at which percentage the price has increased or decreased, and is calculated by subtracting the closing at bar Start with the price at bar End, divided by the price at bar End, the result is then multiplied by 100.

The average traded volume calculate the mean of the volume in the selected range, I used the same format used by the original volume indicator for clarity.

Finally, the last stats of the section is the number of gaps, this stat is by default hidden. An up gap is detected when the open price is superior to the previous high, while a down gap is detected when the open price is inferior to the previous low, this allow to only retain significant gaps.

The last section of the indicator panel shows the correlation between the closing price and another instrument, by default GOOG, this correlation is also calculated within the user-selected range. Positive values indicate a positive relationship, that is the two instruments tend to move in the same direction. Negative values indicate a negative relationship, both instruments tend to move in a direction opposite to each other. Values closer to 1 or -1 indicate a stronger relationship, while values closer to 0 indicate no relationship.

In Summary

The script shows various stats, each calculated within a user-selected range, in general one would be more interested in how these stats might evolve with time, but checking them in a custom range can be quite interesting.

Thx for reading. umu

Информация о релизе

Updated title, can be less confusing

Информация о релизе

Updated the title another time, wasn't satisfied with the previous one umu
Комментарии
PineCoders
PineCoders
This publication will be featured in our "Best Scripts of The Month" selection. Thank you for your valuable contribution to the TradingView community, and congrats!
kurtsmock
This is definitely.... VERY cool.
I used some of the code in a position sizing script. Your work has been invaluable to my growth. Thanks for making the world a better place!
azinc
Thnaks for your work, I checked with a cfd like DE30EUR but for example for intraday:

function mean(x)=> doesn´t work for me because I would like to know the sma of all the data from start to end

Also I would like to calculate median, I tried but in my best effort there are always many medians in this case I would like to know the median from highest high and highest low

I published a version simplified: Time Range Statistics_@alexgrover_simplified

If you see the image the mean (is mean of start and end) and the median is repainting,...

I would try to undestand why it doesn´t seem to work for me,...any help will be appreciated

Thanks anyway
LunaOwl
Thank you Alex for your contribution to the community >w<)!
alexgrover
@LunaOwl, umu you are more than welcome
Anderson-FX
Thanks for this
ICEKI
Hi Alex; that is so impressive; thank you so much for your work =D
alexgrover
@ICEKI, Thanks for your support :)
Halleyroach
Good job mate
Ещё