本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Shivam_Mandrai
//@version=5
indicator("IU Price Density(Market Noise)", overlay = false)
//note ->>> less value = less noise , high value = high noise
//______________________________User Input____________________________________________________________\\
length = input.int(20, "Price Density Length = ")
smoothing = input.int(5, "Smoothing Length = ", minval = 1, tooltip = "This will soom the Price Density by averaging it")
//______________________________Array to Store Ranges(High - low)______________________________________\\
var range_array = array.new<float>()
for i = 0 to length - 1
array.push(range_array, high[i] - low[i])
//_____________________________Price Density Calculation_______________________________________________\\
highest_high = ta.highest(high, length)
lowest_low = ta.lowest(low, length)
price_density = array.sum(range_array) / (highest_high - lowest_low)
smoothed_density = ta.sma(price_density, smoothing)
array.clear(range_array) // << Resetting the array >> //
//____________________________Dynamic Color Based on Price Density______________________________________\\
density_color = smoothed_density >= 6 ? color.red : smoothed_density >= 3 ? color.orange : color.green
plot(smoothed_density, color = density_color, linewidth = 2, title = "Smoothed Price Density")
//---BG color----//
bgcolor(smoothed_density >= 6 ? color.new(color.red, 90) : na , title = "High Density Background")
bgcolor(smoothed_density <= 3 ? color.new(color.green, 90) : na, title = "Low Density Background" )
//---Hlines color----//
hline(6, "High Density Threshold", color = color.red, linestyle = hline.style_dashed)
hline(3, "Low Density Threshold", color = color.green, linestyle = hline.style_dashed)