KERPD Noise Filter

SensitiveSuit · study · 75 行 · 点赞 250 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=5
indicator('KERPD Noise Filter - Kaufman Efficiency Ratio and Price Density', shorttitle='KERPD Noise Filter (SensitiveSuit)', overlay=false)
 
//This indicator combines Kaufman Efficiency Ratio (KER) and Price Density theories to create a unique market noise filter that is 'right on time' compared to using KER or Price Density alone. All data is normalized and merged into a single output. 
//Additionally, this indicator provides the ability to consider background noise and background noise buoyancy to allow dynamic observation of noise level and asset specific calibration of the indicator (if desired).
//The basic theory surrounding usage is that higher values = lower noise, while lower values = higher noise in market.
//NON-DIRECTIONAL Kaufman Efficiency Ratio used. Threshold period of 30 to 40 applies to Kaufman Efficiency Ratio systems if standard length of 20 is applied; maintained despite incorporation of Price Density normalized data.
 
 
//TRADING USES:
//---Trend strategies, mean reversion/reversal/contrarian strategies, and identification/avoidance of ranging market conditions.
//---Trend strategy where KERPD is above a certain value; generally a trend is forming/continuing as noise levels fall in the market.
//---Mean reversion/reversal/contrarian strategies when KERPD exits a trending condition and falls below a certain value (additional signal confluence confirming for a strong reversal in price required); generally a reversal is forming as noise levels increase in the market.
//---A filter to screen out ranging/choppy conditions where breakouts are frequently fake-outs and or price fails to move significantly; noise level is high, in addition to the background buoyancy level.
//---In an adaptive trading systems to assist in determining whether to apply a trend following algorithm or a mean reversion algorithm.
 
//THEORY:
//The market is a jungle. When apex predators are present it often goes quiet (institutions moving price), when absent the jungle is loud.
//There is always background noise that scales with the anticipation of the silence, which has features of buoyancy that act to calibrate the beginning of the silence and return to background noise conditions.
//Trend traders hunt in low noise conditions. Reversion traders hunt in the onset of low noise into static conditions. Ranges can be avoided during high noise and buoyant background noise conditions. 
//Distance between the noise line and background noise can help inform decision making.
 
//CALIBRATION:
//Set the Noise Threshold % color change line so that the color cut off is where your trend/reversion should begin.
//Set the Background Noise Buoyancy Calibration Decimal % to match the beginning/end of the color change Noise Threshold % line. Match the Background Noise Baseline Decimal %' to the number set for buoyancy.
//Additionally, create your own custom settings; 33/34 and 50 length also provides interesting results.
//A color change tape option can be enabled by un-commenting the lines at the bottom of this script.
 
 
//INPUTS
//---KAUFMAN EFFICIENCY RATIO---
KERPDperiod = input(20, 'Period', group='KERPD Noise Filter')
KERPDthreshold = input(35, title='Noise Threshold %', group='KERPD Noise Filter')
KERPDdybaseline = input(0.35, 'Background Noise Baseline Decimal %', group='KERPD Noise Filter')
KERPDdycal = input(0.35, 'Background Noise Bouyancy Calibration Decimal %', group='KERPD Noise Filter')
//KERdirectional = (false)
//LOGIC
//---MODULE KAUFMAN EFFICIENCY RATIO---
KER(srckauf, pkauf, dirkauf) =>
    akauf = dirkauf ? srckauf - srckauf[pkauf] : math.abs(srckauf - srckauf[pkauf])
    bkauf = 0.0
    for ikauf = 0 to pkauf - 1 by 1
        bkauf += math.abs(srckauf[ikauf] - srckauf[ikauf + 1])
        bkauf
    er = akauf / bkauf
    er
resultkauf = KER(close, KERPDperiod, false) //DATA STREAM MUST BE NORMALIZED TO BASE 100 FOR FUNCTIONALITY WITH EXCLUSION ZONE HORIZONTAL LINE/COLOR CHANGE
normresultkauf = ((resultkauf-0)/(100-0)*100)*100 //NORMALIZATION FORMULA ---------------------------------------------------------zi = (xi – min(x)) / (max(x) – min(x)) * 100
//---Module Price Density (INVERTED)--- //NOTE: Price density must be inverted to match logic with Kaufman Price Efficiency Ratio
//LOGIC
numerPD = 0.0
for iPD = 0 to KERPDperiod - 1 by 1
    numerPD += high[iPD] - low[iPD]
    numerPD
denoPD = ta.highest(high, KERPDperiod) - ta.lowest(low,KERPDperiod)
resultpricedensity = numerPD / denoPD
invertedPD = 1/resultpricedensity
normpricedensity = ((invertedPD-0)/(100-0)*100)*100 //NORMALIZATION FORMULA ---------------------------------------------------------zi = ((xi – min(x)) / (max(x) – min(x)) * 100) * 100
//---------Kaufman Efficiency Ratio AND Inverted Price Density Merge---------
KERPDmerge = (normresultkauf + normpricedensity)/2
//Dynamic Horizontal Line Control
horzline = (normresultkauf*KERPDdybaseline) //creates white dynamic color change for threshold filter
horzlinea = (100-normresultkauf)*KERPDdycal //creates red noise bouyancy for calibration
//PLOT
//Merged Result
plot(KERPDmerge, color=KERPDthreshold <= KERPDmerge ? color.new(color.aqua,0) : color.new(color.aqua,100), title="KERPD Noise Filter Quiet", linewidth = 2)
plot(KERPDmerge, color=KERPDthreshold >= KERPDmerge ? color.new(color.blue,0) : color.new(color.blue,100), title="KERPD Noise Filter Loud", linewidth = 1)
//Dynamic Horizontal Line
plot(horzline, color=color.new(color.white,50), title='KERPD Background Noise Baseline %', style=plot.style_area, linewidth=1)
plot(horzlinea, color=color.new(color.teal,90), title='KERPD Background Noise Bouyancy %', style=plot.style_area, linewidth=1)
//PLOT Merged Result as TAPE
//KERPDtop = plot(KERPDmerge ? 0 : na, title='KERPD TOP Line') //-95 //CONTROLS PLACEMENT ON CHART --- width is 4 wide
//KERPDbtm = plot(KERPDmerge  ? -5 : na, title='KERPD BOTTOM Line') //-99 //CONTROLS PLACEMENT ON CHART
//fill(KERPDtop, KERPDbtm, title='KERPD Colors', color=KERPDthreshold <= KERPDmerge ? color.new(color.aqua,0) : color.new(color.aqua,100))
//fill(KERPDtop, KERPDbtm, title='KERPD Colors', color=KERPDthreshold >= KERPDmerge ? color.new(color.blue,0) : color.new(color.blue,100))

← 返回列表