Resampling
Resampling
0 at
https://mozilla.org/MPL/2.0/
// © DonovanWall
//@version=4
study("Resampling Reverse Engineering Bands [DW]", shorttitle="RREB [DW]",
overlay=true)
//In this study, the reverse engineering functions are used to calculate the price
values of user defined high and low oscillator thresholds, and the price values for
the oscillator center.
//This allows you to visualize what prices will trigger thresholds as a sort of
confidence interval, which is information that isn't inherently available when
simply analyzing the oscillator directly.
//This script is equipped with three reverse engineering functions to choose from
for calculating the band values:
// -> Reverse Relative Strength Index (RRSI)
// -> Reverse Stochastic Oscillator (RStoch)
// -> Reverse Commodity Channel Index (RCCI)
//You can easily select the function you want to utilize from the "Band Calculation
Type" dropdown tab.
//These functions are specially designed to calculate at any sample rate (up to 1
bar per sample) utilizing the process of downsampling that I introduced in my
Resampling Filter Pack.
//The sample rate can be determined with any of these three methods:
// -> BPS - Resamples based on the number of bars.
// -> Interval - Resamples based on time in multiples of current charting
timeframe.
// -> PA - Resamples based on changes in price action by a specified size. The PA
algorithm in this script is derived from my Range Filter algorithm.
// The range for PA method can be sized in points, pips, ticks, % of price, ATR,
average change, and absolute quantity.
//Utilizing downsampled rates allows you to visualize the reverse engineered values
of an oscillator calculated at larger sample scales.
//This can be rather beneficial for trend analysis since lower sample rates
completely remove certain levels of noise.
//By default, the sample rate is set to 1 BPS, which is the same as bar-to-bar
calculation. Feel free to experiment with the sample rate parameters and configure
them how you like.
//Custom bar colors are included as well. The color scheme is based on disparity
between sources and the reverse engineered center level.
//In addition, background highlights are included to indicate when price is outside
the bands, thus indicating "overbought" and "oversold" conditions according to the
thresholds you set.
//I also included four external output variables for easy integration of signals
with other scripts:
// -> Trend Signals (Current Resolution Prices) - Outputs 1 for bullish and -1 for
bearish based on disparity between current resolution source and the central level
output.
// -> Trend Signals (Resampled Prices) - Outputs 1 for bullish and -1 for bearish
based on disparity between resampled source and the central level output.
// -> Outside Band Signal (Current Resolution Prices) - Outputs 1 for overbought
and -1 for oversold based on current resolution source being outside the bands.
Returns 0 otherwise.
// -> Outside Band Signal (Resampled Prices) - Outputs 1 for overbought and -1 for
oversold based on resampled source being outside the bands. Returns 0 otherwise.
//To use these signals with another script, simply select the corresponding
external output you want to use from your script's source input dropdown tab.
//I hope you all find this script useful and enjoyable!
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Functions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Inputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Source Price
src = input(defval=close, title="Input Source Price")
//Resampling Method
s_method = input(defval="BPS", options=["BPS", "Interval", "PA"], title="Resampling
Method")
//Sample Offset
s_off = input(defval=0, minval=0, title="Sample Cycle Offset ═══════════════════")
//RRSI Inputs
rsi_per = input(defval=14, minval=2, title="RSI Period")
rsi_ht = input(defval=70.0, minval=50, maxval=100, title="RSI High Threshold
Value")
rsi_lt = input(defval=30.0, minval=0, maxval=50, title="RSI Low Threshold Value
═══════════════════")
//RStoch Inputs
stoch_per = input(defval=14, minval=2, title="Stochastic Period")
stoch_sper = input(defval=1, minval=1, title="Stochastic Smoothing Period")
stoch_ht = input(defval=80.0, minval=50, maxval=100, title="Stochastic High
Threshold Value")
stoch_lt = input(defval=20.0, minval=0, maxval=50, title="Stochastic Low
Threshold Value ═══════════════════")
//RCCI Inputs
cci_per = input(defval=20, minval=2, title="CCI Period")
cci_ht = input(defval=100.0, minval=0, title="CCI High Threshold Value")
cci_lt = input(defval=-100.0, maxval=0, title="CCI Low Threshold Value
═══════════════════")
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Definitions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Band Selection
hband = band_type=="RRSI" ? rrsi_h : band_type=="RStoch" ? rstoch_h : rcci_h
lband = band_type=="RRSI" ? rrsi_l : band_type=="RStoch" ? rstoch_l : rcci_l
mband = band_type=="RRSI" ? rrsi_m : band_type=="RStoch" ? rstoch_m : rcci_m
//Colors
bar_color = (src > mband) and (src >= ds_src) ? ((src > src[1]) ? #00ff66 :
#008b00) :
(src < mband) and (src <= ds_src) ? ((src < src[1]) ? #ff0066 :
#8b0000) : #cccccc
mcolor = ds_src > mband ? #00ff66 : ds_src < mband ? #ff0066 : #cccccc
bg_color = src > hband ? #00ffcc : src < lband ? #ff00cc : #000000
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Outputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Resampled Source
plot(ds_src, color=#ffffff, style=plot.style_circles, title="Resampled Source")
//Band Plots
mplot = plot(mband, color=mcolor, linewidth=2, transp=0, title="Central Threshold
Band")
hplot = plot(hband, color=#00ff66, linewidth=2, transp=0, title="High Threshold
Band")
lplot = plot(lband, color=#ff0066, linewidth=2, transp=0, title="Low Threshold
Band")
//Band Fills
fill(hplot, mplot, color=#00ff66, title="High Band Fill")
fill(lplot, mplot, color=#ff0066, title="Low Band Fill")
//Bar Color
barcolor(bar_color)
//Background Colors
bgcolor(#000000, transp=0)
bgcolor(bg_color)
//External Outputs
plot(trend_out1, transp=100, editable=false, display=display.none, title="External
Output - Trend Signal (Current Resolution Prices)")
plot(trend_out2, transp=100, editable=false, display=display.none, title="External
Output - Trend Signal (Resampled Prices)")
plot(obos_out1, transp=100, editable=false, display=display.none, title="External
Output - Outside Band Signal (Current Resolution Prices)")
plot(obos_out2, transp=100, editable=false, display=display.none, title="External
Output - Outside Band Signal (Resampled Prices)")