TradingView Pine 脚本:绘制收盘价的百分位数
TradingView Pine Script: Plotting Percentile's of Price Close
我正在尝试为 TradvingView 编写一个指标脚本,其中收盘价(或任何一组值)的第 80 个百分位值和第 20 个百分位值绘制在图表上(代码如下)。
基于 'Lookback Period' 输入(比方说 x),它应该从当前柱回头看 x 柱并计算和绘制收盘价(或开盘价或任何指定的用户输入)。它应该为每个小节执行此操作。
虽然它确实在图表上画了线,但它绘制的百分位值似乎不准确。
希望得到关于我出错的地方的反馈,或者如果有一种方法可以使用函数手动计算百分位值,因为内置函数似乎计算不正确。
谢谢! :)
//@version=3
study(title="Percentiles", shorttitle="Percentiles", overlay=true)
// ----- DESCRIPTION
//
// Given a set of values, this indicator plots 2 lines: the upper percentile and the lower percentile
// It was made to be overlaid on the 'Bitmex Funding' indicator but could work with any set of values
//
//
//----- PRINTED/RENDERED VALUES
//
// Upper Percentile Plot Threshold | Lower Percentile Plot Threshold
// Upper Percentile Plot (Green Line)
// Lower Percentile Plot (Red Line)
//
//
// ----- OPTIONS
//
// Lookback Period: The number of values to look at plotting the percentiles thresholds.
// Upper Percentile Plot: The percentile plot i.e. 80th percentile plot of a set of values. By default, the value is 80 is used.
// Lower Percentile Plot: The percentile plot i.e. 20th percentile plot of a set of values. By default, the value is 20 is used.
length = input(100, minval=1, title="Lookback Period")
upperPercentilePlot = input (80, title="Upper Percentile Plot")
lowerPercentilePlot = input(20, title="Lower Percentile Plot")
src = input(close, title="Source")
median_high = percentile_nearest_rank(src, length, upperPercentilePlot)
median_low = percentile_nearest_rank(src, length, lowerPercentilePlot)
plot(median_high, color=blue, title="Upper Percentile Plot", linewidth=2)
plot(median_low, color=blue, title="Lower Percentile Plot", linewidth=2)
您使用该函数的方式似乎没有任何问题,而且似乎工作正常。将您的 src
行替换为条形图索引的模 100 会产生正确的结果:
src = n%100
我正在尝试为 TradvingView 编写一个指标脚本,其中收盘价(或任何一组值)的第 80 个百分位值和第 20 个百分位值绘制在图表上(代码如下)。
基于 'Lookback Period' 输入(比方说 x),它应该从当前柱回头看 x 柱并计算和绘制收盘价(或开盘价或任何指定的用户输入)。它应该为每个小节执行此操作。
虽然它确实在图表上画了线,但它绘制的百分位值似乎不准确。
希望得到关于我出错的地方的反馈,或者如果有一种方法可以使用函数手动计算百分位值,因为内置函数似乎计算不正确。
谢谢! :)
//@version=3
study(title="Percentiles", shorttitle="Percentiles", overlay=true)
// ----- DESCRIPTION
//
// Given a set of values, this indicator plots 2 lines: the upper percentile and the lower percentile
// It was made to be overlaid on the 'Bitmex Funding' indicator but could work with any set of values
//
//
//----- PRINTED/RENDERED VALUES
//
// Upper Percentile Plot Threshold | Lower Percentile Plot Threshold
// Upper Percentile Plot (Green Line)
// Lower Percentile Plot (Red Line)
//
//
// ----- OPTIONS
//
// Lookback Period: The number of values to look at plotting the percentiles thresholds.
// Upper Percentile Plot: The percentile plot i.e. 80th percentile plot of a set of values. By default, the value is 80 is used.
// Lower Percentile Plot: The percentile plot i.e. 20th percentile plot of a set of values. By default, the value is 20 is used.
length = input(100, minval=1, title="Lookback Period")
upperPercentilePlot = input (80, title="Upper Percentile Plot")
lowerPercentilePlot = input(20, title="Lower Percentile Plot")
src = input(close, title="Source")
median_high = percentile_nearest_rank(src, length, upperPercentilePlot)
median_low = percentile_nearest_rank(src, length, lowerPercentilePlot)
plot(median_high, color=blue, title="Upper Percentile Plot", linewidth=2)
plot(median_low, color=blue, title="Lower Percentile Plot", linewidth=2)
您使用该函数的方式似乎没有任何问题,而且似乎工作正常。将您的 src
行替换为条形图索引的模 100 会产生正确的结果:
src = n%100