TradingView
RicardoSantos
8 paź 2021 10:13

MathStatisticsKernelDensityEstimation 

Bitcoin / U.S. dollarBitstamp

Opis

Library "MathStatisticsKernelDensityEstimation"
(KDE) Method for Kernel Density Estimation

kde(observations, kernel, bandwidth, nsteps)
Parameters:
  • observations: float array, sample data.
  • kernel: string, the kernel to use, default='gaussian', options='uniform', 'triangle', 'epanechnikov', 'quartic', 'triweight', 'gaussian', 'cosine', 'logistic', 'sigmoid'.
  • bandwidth: float, bandwidth to use in kernel, default=0.5, range=(0, +inf), less will smooth the data.
  • nsteps: int, number of steps in range of distribution, default=20, this value is connected to how many line objects you can display per script.

Returns: tuple with signature: (float array, float array)

draw_horizontal(distribution_x, distribution_y, distribution_lines, graph_lines, graph_labels) Draw a horizontal distribution at current location on chart.
Parameters:
  • distribution_x: float array, distribution points x value.
  • distribution_y: float array, distribution points y value.
  • distribution_lines: line array, array to append the distribution curve lines.
  • graph_lines: line array, array to append the graph lines.
  • graph_labels: label array, array to append the graph labels.

Returns: void, updates arrays: distribution_lines, graph_lines, graph_labels.

draw_vertical(distribution_x, distribution_y, distribution_lines, graph_lines, graph_labels) Draw a vertical distribution at current location on chart.
Parameters:
  • distribution_x: float array, distribution points x value.
  • distribution_y: float array, distribution points y value.
  • distribution_lines: line array, array to append the distribution curve lines.
  • graph_lines: line array, array to append the graph lines.
  • graph_labels: label array, array to append the graph labels.

Returns: void, updates arrays: distribution_lines, graph_lines, graph_labels.

style_distribution(lines, horizontal, to_histogram, line_color, line_style, linewidth) Style the distribution lines.
Parameters:
  • lines: line array, distribution lines to style.
  • horizontal: bool, default=true, if the display is horizontal(true) or vertical(false).
  • to_histogram: bool, default=false, if graph style should be switched to histogram.
  • line_color: color, default=na, if defined will change the color of the lines.
  • line_style: string, defaul=na, if defined will change the line style, options=('na', line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_right, line.style_arrow_left, line.style_arrow_both)
  • linewidth: int, default=na, if defined will change the line width.

Returns: void.

style_graph(lines, lines, horizontal, line_color, line_style, linewidth) Style the graph lines and labels
Parameters:
  • lines: line array, graph lines to style.
  • lines: labels array, graph labels to style.
  • horizontal: bool, default=true, if the display is horizontal(true) or vertical(false).
  • line_color: color, default=na, if defined will change the color of the lines.
  • line_style: string, defaul=na, if defined will change the line style, options=('na', line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_right, line.style_arrow_left, line.style_arrow_both)
  • linewidth: int, default=na, if defined will change the line width.

Returns: void.
Komentarze
RicardoSantos
there is a known bug with drawing horizontal histogram, i have no solution for this atm..
hosseinfrtrades
Hello, that's awesome. can you explain how can I use it? thank you
Ziloan
Dear RS,

Do you by any chanche now a way to implement Sheather-Jones algorithm for finding the proper bandwidth?
RicardoSantos
@Ziloan, not at the moment, seams rather complex for current pine version,
here is a python implementation if you want to explore further:
github.com/tommyod/KDEpy/blob/master/KDEpy/bw_selection.py
Ziloan
@RicardoSantos, Thank you!
peacefulLizard50262
My goodness you do amazing work! Would you be able to make a library for just drawing a graph with a dot that represents two variables? If you could do that could you also make it so you can set the angle of the plot so that I can have 1,1 pointing north? Either that or would you be able to explain how to do that? Thank you very much in advance!
RicardoSantos
@peacefulLizard50262, that is not hard to do, but TV is not built for drawing that kinda graphs, so scales/labels must be hardcoded, to disassociate from the built in scales, as you can see above scales/labels need to be redrawn/adjusted to underlying.
peacefulLizard50262
@RicardoSantos, Thank you for your quick reply! I was just looking at tradingview.com/script/Faku8iLD-Example-Graph-style-4th-Dimension-RSI/ . Do you think that the code in here will be enough to point me in the right direction?
RicardoSantos
@peacefulLizard50262, well yes, its a good example of the limitations in place, and yes its doing what you want on the rsi scale
peacefulLizard50262
@RicardoSantos, Thank you very much! This should be a fun challenge.
Więcej